-
Notifications
You must be signed in to change notification settings - Fork 5
API Reference
Primary component of GroundControl. It sits beneath the router & above your application. Controls data fetching, store structure, and how your application renders.
render((
<Router
routes={routes}
history={browserHistory}
render={(props) => (
<GroundControl
{...props}
store={store}
/>
)}/>
), document.getElementById('app'));
Object. Create an initial Redux store and pass it in as prop.
Object. For universal applications, pass in initialData from loadStateOnServer
/ loadStateOnClient
.
Object. If you want additional top level reducers (ex: redux-simple-router), pass in object with reducers so that we can properly call store.replaceReducers
. If you don't have extra reducers, skip this entirely and just send in the store.
{ groundcontrol: (s = {}) => s, otherReducer: (s = {}) => s }
Function. If using a lib like Immutable.js, and want an app level serializer to handle data before it is send to components, add a serializer.
const serializer = (data, route) => {
if (route.immutable) return data.toJS();
return data;
};
We extend React-Router <Route>
components with a few additional props.
Function. Reducers defined on your routes will automatically be used to create your global application state, in line with route hierarchy. When someone navigates to a new route, the old routes state is cleared, and the old reducer is replaced with the new reducer in the store.
const reducer = (state = {}, action) => state;
Function. If asyncEnter is a set on a route, the route component doesn't resolve until a callback is called. See Universal Route API for details.
Function. Clean up, etc before leaving route.
Component. For synchronous client side transitions, set a loader (like a spinner) until the route component is rendered.
Function. For universal apps that use custom data (immutable), deserialize data from __INITIAL_DATA__
to the reducers.
const deserializer = (data) => data;
Function. For apps that use custom data (immutable), serialize data from reducers before it gets to components.
const serializer = (data) => data;
Add whatever custom props you'd like, ex: route.immutable
, so that you can manipulate data in application serializer / deserializer.
This includes location, params, route, etc. Please see React-Router documentation.
Object. Data from your route reducer is automatically passed to your component as data.
Object. Data from top level component is passed to all route components as a convenience. This is a common place to persist data.
Function. Helper to get any level of parentData if deeply nested.
Bool. For async transitions, whether the route is still loading.
Null/Object. If asyncEnter called the err() callback.
Function. Call done when route is completely done fetching data.
Object. Route params to help fetch data.
Function. Returns null. Dispatch actions to your store.
Function. Returns object. getState of your store, if needed.
Function. Returns null. Tell your client to stop blocking and handle loading with preview template.
Function. Returns null. Tell your server to stop blocking and render page. Useful if you want to render the top half of page server side, bottom half of page client side.
Function. Returns null. Call to signify an error to pass loadingErr on client render; and handle error on server (with a 500, etc).
Function. Returns null. Call to redirect on client, and to redirect on server (with a 302, etc).
Function. Returns bool for whether the current route is still active. Useful for avoiding race conditions on quick route changes.
Function. Returns bool for whether we can assume the data we have is accurate on initial page load.
Function. Returns object with hydrated data. Useful if we want to cache client side.
Function. Returns bool for client render.
Function. Returns bool for server render.
Function for universal rendering (server side). Takes in props from React-Router match
, store, and reducers (optional). Calls callback with error (/null) for server side error handling; redirect (/null); initialData to send into GroundControl
and scriptString so that we can hydrate the client.
Function for universal rendering (client side). Takes in routes, and an optional deserializer, and calls callback with initialData
to pass into GroundControl
.
Pass in current store, and level you'd like to receive (without traversing self / child hierarchy manually).