Skip to content

Latest commit

 

History

History
189 lines (144 loc) · 9.92 KB

Javascript_details.md

File metadata and controls

189 lines (144 loc) · 9.92 KB

JS/HTML5 Style and libraries

This app is set up as a React/Redux/Rx application. That's 3 different libraries with coincidentally similar names. Sorry.

Javascript is Ecmascript 2015, a.k.a. ES6, the latest version of Javascript.

ES6

Module support in ES6 looks different than the older standards.

Android special tips

Android does not like expensive re-renders on timers; instead they must be done in worker threads or in response to user input.

Optimizing

HTML5 Multimedia

  • To have a stable API to access audio and video we use webrtc-adapter.
  • Audio synthesis
  • SVG - see the SVG HOWTO.
  • For the gallery: kiosk mode is natively supported by chrome, but you should disable sensitive controls by doing a gallery build, npm run gallerybuild
  • Icons are provided through fontawesome

React

The rendering system for all UI components is React.

If I need to get to DOM nodes...

e.g. for accessing video. How do I persist DOM nodes? Perhaps using keys and then relying on a ref How do i communicate across branches of Components? Methods?

But I think I can avoid this by separating DOM streams and React components as two separates types of App both of which talk to the Redux store.

If i want easy graphing

  • for people using react.js, Victory

Alternatives

  • Preact is smaller than React. Does it work for us? Is it faster?

Redux

We use Redux to organise the app state.

Introductions to Redux

Persistence

We are currently using redux-persist. It imports a LOT of code in dependencies though... We could instead use redux-storage

The storage engine is localForage but we could use cookies or localStorage. redux-storage supports many backends.

Alternatives to Redux

Could also use Rx with a redux pattern A, B, or C. It's recommended to not even bother with redux in that case. However I will start that way because otherwise it's too complicated

Building

We mostly use webpack, which is built on npm. webpack is a module bundler. This means webpack takes modules spread across multiple files with dependencies and a smaller number of files which include the functionality.. It's the dominant build system right now for web apps, at least for community-supported react-based ones.

Webpack works by magic, as far as I can tell, and it has fearsomely complicated and poorly explained configuration. Nonetheless, everyone uses it and so we ignore it and just GO here.

webpack.config.js has the actual configuration, which does various things. package.json lists the various libraries ("dependencies") that are assembled together by npm. It isn't specific to webpack, as all npm packages use it, but we use webpack here.

npm install --save-dev --upgrade \
  babel-cli \
  babel-core \
  babel-loader \
  babel-plugin-system-import-transformer \
  babel-plugin-transform-dead-code-elimination\
  babel-plugin-transform-function-bind \
  babel-plugin-transform-object-rest-spread \
  babel-preset-es2015 \
  babel-preset-react \
  babel-preset-stage-0 \
  localforage \
  node-static \
  react \
  react-dom \
  react-redux \
  redux \
  redux-logger \
  redux-persist \
  redux-thunk \
  reselect \
  rxjs \
  serviceworker-webpack-plugin \
  source-map-loader \
  tone \
  webpack \
  webpack-dev-server \
  webrtc-adapter \
  worker-loader

caching using serviceworkers

See progressive webapps with webpack and the serviceworker-webpack-plugin documentation.

Rx.js

We use Rx.js 5.0, because even though it is less common that Rx.js 4.0, the documentation is way better.