git ssb

1+

dinoworm ๐Ÿ› / catstack



Commit cdd217083b6f75828df3910f914dc5d9bf46437f

update code to work with new `react-router` + `redux-simple-router`

Michael Williams committed on 1/18/2016, 8:14:39 AM
Parent: 6c495c8b7fdf2fb19251200cd2cd547883d7d533

Files changed

app/render-browser.jschanged
app/render.jschanged
app/store.jschanged
package.jsonchanged
app/render-browser.jsView
@@ -1,9 +1,8 @@
11 import React from 'react'
22 import { render } from 'react-dom'
33 import { Provider } from 'react-redux'
4-import { Router } from 'react-router'
5-import { createHistory } from 'history'
4+import { browserHistory as history, Router } from 'react-router'
65 import { syncReduxAndRouter } from 'redux-simple-router'
76
87 import createRoutes from 'app/routes'
98 import createStore from 'app/store'
@@ -12,13 +11,10 @@
1211 if (process.env.NODE_ENV === 'development') {
1312 var DevTools = require('app/util/dev-tools').default
1413 }
1514
16-const store = createStore(window.__data)
17-const history = createHistory()
15+const store = createStore(window.__data, history)
1816
19-syncReduxAndRouter(history, store)
20-
2117 const main = (
2218 <Router createElement={fetchElement(store)} history={history}>
2319 { createRoutes(store) }
2420 </Router>
app/render.jsView
@@ -4,10 +4,9 @@
44 import Url from 'url'
55 import React from 'react'
66 import { renderToString } from 'react-dom/server'
77 import { Provider } from 'react-redux'
8-import { createHistory } from 'history'
9-import { Router, RoutingContext, match } from 'react-router'
8+import { Router, RouterContext, match, createMemoryHistory as createHistory } from 'react-router'
109 import sendHtml from 'send-data/html'
1110 import sendError from 'send-data/error'
1211 import redirect from 'predirect'
1312
@@ -20,9 +19,10 @@
2019
2120 return http.createServer(render)
2221
2322 function render (req, res) {
24- const store = createStore()
23+ const history = createHistory()
24+ const store = createStore(undefined, history)
2525
2626 match({
2727 routes: createRoutes(store),
2828 location: req.url
@@ -43,9 +43,9 @@
4343 renderProps.location,
4444 renderProps.params
4545 ).then(function () {
4646 const component = <Provider store={store}>
47- <RoutingContext { ...renderProps } />
47+ <RouterContext { ...renderProps } />
4848 </Provider>
4949
5050 var innerHtml
5151 try {
app/store.jsView
@@ -1,7 +1,7 @@
11 import { createStore, compose, applyMiddleware } from 'redux'
22 import thunk from 'redux-thunk'
3-import { createHistory } from 'history'
3+import { syncHistory } from 'redux-simple-router'
44
55 import reducer from 'app/reducer'
66
77 if (process.env.NODE_ENV === 'development') {
@@ -13,17 +13,11 @@
1313 let middleware = []
1414
1515 middleware.push(thunk)
1616
17-storeEnhancers.push(
18- applyMiddleware(...middleware)
19-)
20-
2117 if (process.env.NODE_ENV === 'development') {
2218 if (process.browser) {
23- storeEnhancers.push(
24- applyMiddleware(logger())
25- )
19+ middleware.push(logger())
2620 }
2721
2822 storeEnhancers.push(DevTools.instrument())
2923
@@ -36,15 +30,26 @@
3630 ))
3731 }
3832 }
3933
40-const createEnhancedStore = compose(
41- ...storeEnhancers
42-)(createStore)
34+export default function finalCreateStore(initialState, history) {
35+ const historyMiddleware = syncHistory(history)
4336
44-export default function finalCreateStore(initialState) {
37+ const finalMiddleware = middleware.concat([
38+ historyMiddleware
39+ ])
40+
41+ const createEnhancedStore = compose(
42+ applyMiddleware(...finalMiddleware),
43+ ...storeEnhancers
44+ )(createStore)
45+
4546 const store = createEnhancedStore(reducer, initialState)
4647
48+ if (process.env.NODE_ENV === 'development') {
49+ historyMiddleware.listenForReplays(store)
50+ }
51+
4752 if (module.hot) {
4853 module.hot.accept('app/reducer', () => {
4954 store.replaceReducer(require('app/reducer'))
5055 })
package.jsonView
@@ -116,9 +116,8 @@
116116 "feathers-hooks": "^0.6.0",
117117 "feathers-knex": "^2.0.0",
118118 "feathers-rest": "^1.1.0",
119119 "feathers-tcomb": "^1.0.0",
120- "history": "^1.13.1",
121120 "isomorphic-fetch": "^2.2.1",
122121 "knex": "^0.9.0",
123122 "lnfs-cli": "^1.0.1",
124123 "lodash": "^4.0.0",

Built with git-ssb-web