Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
state.app = {
...state.app,
...parsedData.sitecore,
};
}
// init i18n
const routeParams = resolveCurrentRoute(path, parsedViewBag);
i18nInit(routeParams.currentLang, false /* isClient */, parsedViewBag.dictionary);
state.app = {
...state.app,
...routeParams,
};
const store = initStore(state);
const history = createMemoryHistory({
initialEntries: [path],
});
const context = {};
const component = (
);
const html = ReactDOM.renderToString(
);
if (context.url) {
result.redirect = context.url;
import { applyMiddleware, combineReducers, compose, createStore } from 'redux'
import { routerMiddleware, routerReducer } from 'react-router-redux'
import createHistory from 'history/createMemoryHistory'
import { ApolloClient } from 'apollo-client'
import reducers from './reducers'
import devTools from 'remote-redux-devtools'
import { networkInterface } from './networkInterface'
const client = new ApolloClient({
networkInterface
})
// TODO this file needs a clean up! we create the store and client and in tests we create different ones - this should be streamlined similarly to what we do in web client
const history = createHistory()
const returnStore = (client, history = createHistory()) => {
return createStore(
combineReducers({
...reducers,
router: routerReducer,
apollo: client.reducer()
}),
{}, // initial state
compose(
applyMiddleware(routerMiddleware(history), client.middleware()),
devTools()
)
)
}
function createReduxStore() {
// Setup state
const initialState = {};
const history = createMemoryHistory();
return createStore(
require('../modules/root').reducer,
initialState,
getStoreMiddleware(history)
);
}
describe('', () => {
const history = createMemoryHistory();
const node = document.createElement('div');
it('renders a function', () => {
const TEXT = 'Mrs. Kato';
const node = document.createElement('div');
render(
<div>{TEXT}</div>} />
,
node
);
expect(node.innerHTML).toContain(TEXT);
});
it('renders a child element', () => {
export default function createHistory(
initialEntries: string | string[] = '/',
matchParams: MatchShape = {},
): ContextRouter {
const entries = _.castArray(initialEntries);
const history = createMemoryHistory({ initialEntries: entries });
const { params = {}, isExact = true } = matchParams;
const match = {
params,
isExact,
path: entries[0],
url: entries[0],
};
return {
history,
match,
location: history.location,
};
}
app.get('/*', function(req, res) {
const history = createHistory()
const location = history.location
match({ routes, location }, (err, redirectLocation, renderProps) => {
if(err) {
console.error(err);
return res.status(500).end('Internal server error');
}
if(!renderProps) {
return res.status(404).end('Not found');
}
const store = configureStore();
const InitialView = (
export const createExpressRouter = (installer: Function) => ({
routes,
request,
historyOptions = {}
}: ServerRouterArgs) => {
const history = createMemoryHistory(historyOptions);
const location = locationForRequest(request);
return installer({ routes, history, location });
};
handleChangePage(prev, next) {
if (prev.page != next.page) {
this.history = createMemoryHistory({
initialEntries: [ next.page.initialPath || '/' ],
getUserConfirmation: (message, callback) => {
callback(window.confirm(message))
}
})
}
}
export default function render(req, res) {
const history = createMemoryHistory();
const store = configureStore({}, history);
if (!req.url || req.url.includes('assets')) return null;
const matchedRoutes = matchRoutes(routes, req.url);
store.dispatch({ type: types.CREATE_REQUEST });
return fetchDataForRoute(matchedRoutes)
.then((data) => {
store.dispatch({ type: types.REQUEST_SUCCESS, data });
const initialState = store.getState();
const context = {};
const componentHTML = renderToString(
{renderRoutes(routes)}
,
);
export function renderApp(moduleGetter, appName, initialEntries, storeOptions, ssrInitStoreKey, renderToStream) {
if (storeOptions === void 0) { storeOptions = {}; }
if (ssrInitStoreKey === void 0) { ssrInitStoreKey = "reactCoatInitStore"; }
if (renderToStream === void 0) { renderToStream = false; }
MetaData.appModuleName = appName;
var history = createMemoryHistory({ initialEntries: initialEntries });
var store = buildStore(history, storeOptions.reducers, storeOptions.middlewares, storeOptions.enhancers, storeOptions.initData, storeOptions.routerParser);
var appModule = moduleGetter[appName]();
var render = renderToStream ? renderToNodeStream : renderToString;
return appModule
.model(store)
.catch(function (err) {
return store.dispatch(errorAction(err));
})
.then(function () {
var data = store.getState();
return {
ssrInitStoreKey: ssrInitStoreKey,
data: data,
html: render(React.createElement(Provider, { store: store },
React.createElement(ConnectedRouter, { history: history },
React.createElement(appModule.views.Main, null)))),