Skip to content

Instantly share code, notes, and snippets.

@tomkis
Created June 2, 2016 15:36
Show Gist options
  • Save tomkis/6db84c8f799ceef09a02d6ad3c11bc5b to your computer and use it in GitHub Desktop.
Save tomkis/6db84c8f799ceef09a02d6ad3c11bc5b to your computer and use it in GitHub Desktop.
redux-elm with react-router
///
/// <---- rootView.js
///
import { view } from 'redux-elm';
import buildRouting from './buildRouting';
export default view(({ history }) => buildRouting(history));
///
/// <---- buildRouting.js
///
import React from 'react';
import { connect } from 'react-redux';
import { forwardTo } from 'redux-elm';
import { Router, Route, IndexRoute } from 'react-router';
import Template from '../../template/template';
import LibraryListView from '../library-list/libraryListView';
const connectView = (View, modelKey, ...nesting) =>
connect(appState => ({ model: appState.root[modelKey] }))(
props => <View {...props} dispatch={forwardTo(props.dispatch, ...nesting)} />);
const ConnectedLibraryListView = connectView(LibraryListView, 'libraryList', 'LibraryList');
export default history => (
<Router history={history}>
<Route path="/" component={Template}>
<IndexRoute component={ConnectedLibraryListView} />
</Route>
</Router>
);
import { Updater } from 'redux-elm';
import libraryListUpdater,
{ initialModel as libraryListInitialModel } from '../library-list/libraryListUpdater';
const initialModel = {
libraryList: libraryListInitialModel
};
///
/// <---- rootUpdater.js
///
import { Updater } from 'redux-elm';
import libraryListUpdater,
{ initialModel as libraryListInitialModel } from '../library-list/libraryListUpdater';
const initialModel = {
libraryList: libraryListInitialModel
};
export default new Updater(initialModel)
.case('LibraryList', (model, action) => ({
...model,
libraryList: libraryListUpdater(model.libraryList, action)
}))
.toReducer();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment