Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
SSR Data
If we're running in a server-side rendering scenario,
the ServerHtml component will provide the window.__data object
for us to acquire the initial React state.
SSR is initiated from server.js.
*/
if (window.__data) {
viewBag = window.__data.viewBag;
}
// init i18n
const routeParams = resolveCurrentRoute(window.location.pathname, viewBag);
i18nInit(routeParams.currentLang, true /* isClient */, viewBag ? viewBag.dictionary : null);
const history = createHistory();
if (window.__data) {
// we have data from the server, use it
initialize(window.__data, routeParams, history);
} else {
// init with empty object
const state = initialState();
const store = initialize(state, routeParams, history);
store.dispatch(fetchInitialRoute(window.location.pathname, window.location.search));
}
async function setup() {
const serverState: IDomainState = await fetch('/api/state').then(res => res.json());
// build state to match the redux store
const initialState = {
auth: {
...serverState.auth,
error: null,
},
};
const history = createHistory();
const store = configureStore(history, initialState);
const mount = document.querySelector('.mount');
const rerender = Component => render(Component, mount);
class App extends React.PureComponent<{ store }> {
render() {
return (
);
}
}
// render our app
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, combineReducers, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import createHistory from 'history/createBrowserHistory';
import { Route } from 'react-router';
import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux';
import reducers from './reducers';
import SlackPatron from './components/SlackPatron';
import SlackActions from './actions/SlackActions';
const history = createHistory({
basename: document.getElementById('basename').getAttribute('href')
});
const middleware = routerMiddleware(history);
const store = createStore(
combineReducers({ ...reducers, router: routerReducer }),
applyMiddleware(middleware, thunkMiddleware)
);
// initialize data
store.dispatch(SlackActions.getUsers());
store.dispatch(SlackActions.getTeamInfo());
store.dispatch(SlackActions.getChannels());
store.dispatch(SlackActions.getIms());
render(
_setupDefaultHtml5History(spec) {
let base = spec.base;
// Try to take base from ``
if (!base) {
const baseEl = document.querySelector('base');
base = baseEl && baseEl.getAttribute('href');
}
base = (base || '').replace(/\/+$/, '');
this.history = createHistory({ basename: base });
}
import createBrowserHistory from 'history/createBrowserHistory';
// Abstracts away the differences in various environments and provides
// a minimal API that lets you manage the history stack
// https://github.com/ReactTraining/history
const history = process.env.BROWSER && createBrowserHistory();
export default history;
import App from 'containers/App';
// Import Language Provider
import LanguageProvider from 'containers/LanguageProvider';
import configureStore from './configureStore';
// Import i18n messages
import { translationMessages } from './i18n';
// Import CSS reset and Global Styles
import './global-styles';
// Create redux store with history
const initialState = {};
const history = createHistory();
const store = configureStore(initialState, history);
const MOUNT_NODE = document.getElementById('app');
const render = (messages) => {
ReactDOM.render(
,
MOUNT_NODE
);
};
document,
location,
history: _history
};
const DOMContainer = document.getElementById('fcc');
defaultState.app.csrfToken = csrfToken;
const serviceOptions = {
context: { _csrf: csrfToken },
xhrPath: '/services',
xhrTimeout: 15000
};
const history = createHistory();
sendPageAnalytics(history, ga);
createApp({
history,
serviceOptions,
defaultState,
epics,
epicOptions,
enhancers: isDev && devToolsExtension && [ devToolsExtension() ]
})
.doOnNext(() => {
if (module.hot && typeof module.hot.accept === 'function') {
module.hot.accept(() => {
// note(berks): not sure this ever runs anymore after adding
// RHR?
log('saving state and refreshing.');
// @flow
import createHistory from 'history/createBrowserHistory';
import qs from 'qs';
const history = createHistory();
history.location = {
...history.location,
query: qs.parse(history.location.search.substr(1)),
state: { modal: false, scroll: false },
};
/* istanbul ignore next */
history.listen(() => {
history.location = {
...history.location,
query: qs.parse(history.location.search.substr(1)),
state: history.location.state || {},
};
});
======================================================================
*/
const openSansObserver = new FontFaceObserver('Roboto', {});
openSansObserver.load().then(
() => {
document.body.classList.add('fontLoaded');
},
() => {
document.body.classList.remove('fontLoaded');
}
);
// Create redux store with history
// Get state from local storage.
const initialState = loadState();
const history = createHistory();
const store = configureStore(initialState, history);
createStoreSubscription(store);
const MOUNT_NODE = document.getElementById('app');
if (localStorage.getItem('token')) {
initAxios();
}
const render = (messages) => {
ReactDOM.render(