| title | redux-first-router - Just dispatch actions - Interview with James Gillmore | |
|---|---|---|
| date | 2017-xx-xx | |
| headerImage | /assets/img/XXX.jpg | |
| keywords |
|
TODO: I'll fill this up and link to your Twitter (@faceyspacey)
| export default webpackStats => (req, res) => { | |
| const appString = ReactDOM.renderToString(<App />) | |
| const chunkNames = flushChunkNames() | |
| const assets = webpackStats.assetsByChunkName | |
| const filesForChunk = chunk => assets[chunk] | |
| const files = flatten(chunkNames.map(filesForChunk)) | |
| const scripts = files.filter(f => f.endsWith('.js')) | |
| const stylesheets = files.filter(f => f.endsWith('.css')) |
| routesMap: { | |
| HOME: '/', | |
| POST: '/feed/post/:id', | |
| USER: '/users/:slug', | |
| } | |
| which I'm sure you're familiar with. But then what you can do is this: | |
| store.dispatch({ type: 'HOME' }) |
| /** @flow */ | |
| import type { Dispatch, Store } from 'redux'; | |
| declare module 'react-redux' { | |
| /* | |
| S = State | |
| A = Action | |
| AS = AppState |
| import { flushChunkNames } from 'react-universal-component/server' | |
| import flushChunks from 'webpack-flush-chunks' | |
| export default ({ clientStats, outputPath }) => (req, res) => { | |
| const app = ReactDOM.renderToString(<App />) | |
| const chunkNames = flushChunkNames() | |
| const { js, styles, cssHash } = flushChunks(clientStats, { chunkNames }) | |
| res.send( | |
| `<!doctype html> |
| import Tooltip from 'app/components/Tooltip'; | |
| import Switch from 'app/components/Switch'; | |
| <Tooltip | |
| title={isProjectView ? 'Project View' : 'Current Module View'} | |
| position="left" | |
| > | |
| <Switch right={isProjectView} onClick={toggleProjectView} /> | |
| </Tooltip> | |
| </SwitchContainer> |
| // src/components/App.js | |
| window.ASYNC_COMPONENTS = {} | |
| const App = () => ... | |
| export default App | |
| // src/routesMap.js |
| const routesMap = { | |
| ACTION_TYPE1: { | |
| path: '/foo/:param1/:param2', | |
| thunk: async (dispatch, getState) { | |
| const someParams = getState().location.payload | |
| const responses = await Promise.all([ | |
| import('./components/Foo'), | |
| fetchData(someParams) | |
| ]) |
| const memory = {} | |
| const isLoading = (state = false, action = {}, mem = memory) => { | |
| switch (action.type) { | |
| case 'LIST': | |
| return !mem[action.payload.category] | |
| case 'VIDEO': | |
| return !mem[action.payload.slug] | |
| case 'VIDEOS_FETCHED': | |
| return !(mem[action.payload.category] = true) |