Modern web tools are enabling developers to build web apps in no-wifi and low-fi environments. This talk is about performance and how frontend engineers can create a better user experience while using less resources.
Talk presented on Oct 20, 2017 at PloneConf2017.
Topics:
Airplane mode for web apps:
Mobile and native apps get lots of praise for offline mode. But why aren’t we seeing more web-apps using this. Two reasons: persistent data and code storage. We can now provide offline apps with Web Workers and IndexedDB that also improve the smoothness and robustness of our web apps in high bandwidth environments.
Redux:
Persisting state, store middleware, store subscriptions, normalizing data, normalizr, pure reducers, redux dev tools
Components:
Data heavy pages, component blocks, component skeletons, component lifecycle, shouldComponentUpdate, virtual dom, chrome render tools, method binding
Actions:
ActionTypes, action chaining, promises, store.getState()
General:
env files, route wrappers, offline first, web workers, indexeddb, eslint, airbnb style guide
15. Normalized State
Why
• Faster queries
• Less data redundancy
• More flexible entity access
• Easier to test & debug
How
1. Flatten reducers
2. Separate reducer entities (ideally to their own reducer)
3. Use objects with ids for keys instead of a list
62. Offline First – IndexedDB Promised
Like localStorage, but able to store larger volumes of data and has an asynchronous API.
let dbPromise = idb.open(’app-db', 1, function(upgradeDb) {
switch(upgradeDb.oldVersion) {
case 0:
let lineStore = upgradeDb.createObjectStore('lines');
}
});
class DB {
constructor() {}
storeLine(line) {
dbPromise.then((db) => {
let tx = db.transaction('lines', 'readwrite');
let lineStore = tx.objectStore('lines');
lineStore.put(line, line.Id);
return tx.complete;
});
}
}
idbController.js
64. ESLint
$ npm run lint
/ProjectsX/client/src/js/reducers/index.js
125:9 error Identifier 'some_random_var' is not in camel case
camelcase
125:9 warning 'some_random_var' is assigned a value but never used
no-unused-vars
134:7 error for..in loops iterate over the entire prototype chain, which is virtually never
what you want. Use Object.{keys,values,entries}, and iterate over the resulting array
no-restricted-syntax
✖ 3 problems (2 errors, 1 warning)