Skip to content

Instantly share code, notes, and snippets.

@kpuputti
Created September 29, 2015 11:49
Show Gist options
  • Save kpuputti/59af201a42fbc5f79dea to your computer and use it in GitHub Desktop.
Save kpuputti/59af201a42fbc5f79dea to your computer and use it in GitHub Desktop.
JS next steps

JavaScript projects

Packages and build process

Start simple, keep simple.

  • CommonJS modules
  • Browserify
  • npm run scripts
  • Makefile
  • simple build script

State

Remove all state from modules.

  • DI
  • Schedulers for timers etc.
  • Use an explicit messaging in view hierarchy

Components

Create independent component views.

  • React
  • structure assets (js, css/scss, images) by component

Promises

Include a proper Promise library and use it everywhere in async functions.

  • Q, native Promises + prollyfill, etc.
  • Always resolve with a single value
  • Always reject with an instance of Error
  • Always either end the chain (like Q's done()) or return a promise
  • Be careful with nesting in promise chains, keep the chain shallow

Errors

Use custom Error types.

  • Extend Error object properly
  • Do custom error checking in Promise chains
  • Bubble errors in the defined messaging hierarchy

Documentation

Use JsDoc (?).

  • Generate documentation

  • Help tern.js etc. in autocompletion

  • Google Closure compiler + type annotations?

    • Override e.g. DEBUG mode from command line to remove logging?
    • Use with JsDoc for type checking

Miscellaneous

  • Lint everything (JSHint, ESLint, JSCS)
  • Use null instead of undefined as an explicit missing value, undefined for something that is not yet defined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment