.. | ||
index.js | ||
README.md |
Boot process
appBoot
This is where routes, reducers, and other functions registered by core and thirdparty code are aggregated. It's responsible for bootstrapping the main client application before any React code is executed.
Hooking into appBoot
In order to include routes and reducers in the bootstrapping process, you need to register
them before appBoot
is called, when the window.onload
event is fired.
We can use the
DOMContentLoaded
event as an opportunity to do this, as it's fired after the initial HTML document is
loaded and parsed, and before the window.onload
event.
document.addEventListener('DOMContentLoaded', () => {
// Register things.
});
Registering routes
The RouteRegister can be used to register routes which will
be applied to Page.js when appBoot
is called.
controller.js
import routeRegister from 'lib/RouteRegister';
document.addEventListener('DOMContentLoaded', () => {
routeRegister.add('/some/route', (ctx, next) => {
// Do stuff.
});
});
Registering reducers
The ReducerRegister can be used to register reducers with
the main application Redux store. This store is passed into every route callback on the
ctx.store
property.
controller.js
import reducerRegister from 'lib/ReducerRegister';
import routeRegister from 'lib/RouteRegister';
import ProductReducer from '../state/product/ProductReducer';
document.addEventListener('DOMContentLoaded', () => {
reducerRegister.add('product', ProductReducer);
routeRegister.add('/products', (ctx, next) => {
ctx.store.getState().product // -> { products: [] }
});
});