-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contain SSR setup, clean-up and add notes to our Redux store creation
- Loading branch information
1 parent
e709c5c
commit 62205c8
Showing
8 changed files
with
100 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,11 @@ | ||
import React from 'react' | ||
import { DndProvider } from 'react-dnd' | ||
import { HTML5Backend } from 'react-dnd-html5-backend' | ||
import ReactDOM from 'react-dom' | ||
import { Provider } from 'react-redux' | ||
import { rootDomId } from 'client/util' | ||
import App from './router' | ||
import './client/websockets' | ||
import { LayoutFlagsProvider } from 'contexts/LayoutFlagsContext' | ||
import { clientRouter, history } from './router' | ||
import createStore from './store' | ||
|
||
const store = createStore(history) | ||
import './css/global/index.scss' | ||
|
||
ReactDOM.render( | ||
<LayoutFlagsProvider> | ||
<DndProvider backend={HTML5Backend}> | ||
<Provider store={store}> | ||
{clientRouter()} | ||
</Provider> | ||
</DndProvider> | ||
</LayoutFlagsProvider>, | ||
<App />, | ||
document.getElementById(rootDomId) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,31 @@ | ||
import React from 'react' | ||
import { StaticRouter, Switch, Route } from 'react-router' | ||
import { ConnectedRouter } from 'connected-react-router' | ||
import { createBrowserHistory, createMemoryHistory } from 'history' | ||
import HyloAppRouter from 'routes/HyloAppRouter' | ||
import { Switch, Route } from 'react-router' | ||
import { DndProvider } from 'react-dnd' | ||
import { HTML5Backend } from 'react-dnd-html5-backend' | ||
import { Provider } from 'react-redux' | ||
import { LayoutFlagsProvider } from 'contexts/LayoutFlagsContext' | ||
import createStore, { history } from '../store' | ||
import RootRouter from 'routes/RootRouter' | ||
import '../css/global/index.scss' | ||
import HyloAppRouter from 'routes/HyloAppRouter' | ||
|
||
export const history = typeof window !== 'undefined' | ||
? createBrowserHistory() | ||
: createMemoryHistory() | ||
const store = createStore() | ||
|
||
// Note: `/hyloApp/*` routes will not invoke auth as auth cookie is already passed from webview | ||
export function clientRouter () { | ||
export default function App () { | ||
require('client/rollbar') // set up handling of uncaught errors | ||
|
||
return ( | ||
<ConnectedRouter history={history}> | ||
<Switch> | ||
<Route path='/hyloApp' component={HyloAppRouter} /> | ||
<RootRouter /> | ||
</Switch> | ||
</ConnectedRouter> | ||
) | ||
} | ||
|
||
// Note: Server-side Rendering | ||
// ref: https://github.com/Hylozoic/hylo-evo/issues/1069 | ||
export function serverRouter (req, context) { | ||
return ( | ||
<StaticRouter location={req.url} context={context}> | ||
<Switch> | ||
<Route path='/hyloApp' component={HyloAppRouter} /> | ||
<RootRouter /> | ||
</Switch> | ||
</StaticRouter> | ||
<LayoutFlagsProvider> | ||
<DndProvider backend={HTML5Backend}> | ||
<Provider store={store}> | ||
<ConnectedRouter history={history}> | ||
<Switch> | ||
<Route path='/hyloApp' component={HyloAppRouter} /> | ||
<RootRouter /> | ||
</Switch> | ||
</ConnectedRouter> | ||
</Provider> | ||
</DndProvider> | ||
</LayoutFlagsProvider> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,22 @@ | ||
import { createStore } from 'redux' | ||
import createMiddleware from './middleware' | ||
import rootReducer, { combinedReducers } from './reducers' | ||
import { createBrowserHistory } from 'history' | ||
import createRootReducer, { createCombinedReducers } from './reducers' | ||
|
||
// `window` check here is for SSR case (see `appMiddleware`) | ||
// where a static memory history is passed | ||
export const history = typeof window !== 'undefined' && createBrowserHistory() | ||
|
||
export function getEmptyState (providedHistory = history) { | ||
const combinedReducers = createCombinedReducers(providedHistory) | ||
|
||
export function getEmptyState () { | ||
return combinedReducers({}, { type: '' }) | ||
} | ||
|
||
export default function (history, req) { | ||
return createStore(rootReducer, getEmptyState(), createMiddleware(history, req)) | ||
export default function configureStore (providedHistory = history, req) { | ||
return createStore( | ||
createRootReducer(providedHistory), | ||
getEmptyState(providedHistory), | ||
createMiddleware(providedHistory, req) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters