Code Monkey home page Code Monkey logo

iohk-training's People

Contributors

alanverbner avatar

Watchers

 avatar

iohk-training's Issues

Only generate data once if there is none

Currently you re-generate the invoices data on every server restart, which is fine for this example app but it would be more elegant to only generate the data if it does not exist yet ๐Ÿ˜‰

Optimize for readability

In general the code looks good but in some cases it would be nice to cleanup the formatting and avoid splitting up code flow into too many functions unnecessarily.

One example are imports:

import {
  Invoices
} from '../api/invoices'

can and should be a simple one-liner:

import { Invoices } from '../api/invoices';

Here you split the code up into many small functions which is nice for big apis and when there is real complexity going on. But this component is so simple that this is less readable in the end!

function areAllLoaded( data ) {
  return data.total === data.loaded
}

function isIndicatorVisible( window, target ) {

  const threshold = window.scrollTop() + window.height() - target.height();
  return target.offset().top < threshold;
}

function tryLoadMoreData( instance ) {
  var target = instance.$( "#load-more" );
  if ( !target.length ) return;

  if ( isIndicatorVisible( $( window ), target ) && !areAllLoaded( instance.data ) ) {
    instance.data.onNeedMoreItems()
  }
}

Template.InfiniteScroll.onRendered( function onBodyCreated() {
  $( window ).scroll( () => {
    tryLoadMoreData( this )
  } )
} )

Template.InfiniteScroll.helpers( {

  allLoaded() {
    return areAllLoaded( this )
  },

  moreToLoad() {
    return !areAllLoaded( this )
  }
} )

you could pack this code into ~20-30 lines of code instead, as simple as possible ๐Ÿ˜‰

No default route on "/"

Currently there is just the iron router error page showing up that there is no route defined for the URL path "/". Would be nice to add a redirect for that ๐Ÿ˜‰

total-invoices count must represent current query

Currently you return the total count of all invoices but the client actually needs to know how many invoices there are for the current set of filter and sorting options! This means you have to use the same query for the total count too.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.