scratch-www/src/lib/render.jsx

53 lines
1.7 KiB
React
Raw Normal View History

2018-01-30 09:54:45 -05:00
var redux = require('redux');
var thunk = require('redux-thunk').default;
// JSX syntax transforms to React.createElement
2018-01-30 09:54:45 -05:00
var React = require('react'); // eslint-disable-line
var ReactDOM = require('react-dom');
var StoreProvider = require('react-redux').Provider;
2018-01-30 09:54:45 -05:00
var IntlProvider = require('./intl.jsx').IntlProvider;
var permissionsActions = require('../redux/permissions.js');
var sessionActions = require('../redux/session.js');
var reducer = require('../redux/reducer.js');
require('../main.scss');
2018-01-30 09:54:45 -05:00
var render = function (jsx, element, reducers) {
// Get locale and messages from global namespace (see "init.js")
2018-01-30 09:54:45 -05:00
var locale = window._locale || 'en';
var messages = {};
if (typeof window._messages !== 'undefined') {
if (typeof window._messages[locale] === 'undefined') {
// Fall back on the split
locale = locale.split('-')[0];
}
if (typeof window._messages[locale] === 'undefined') {
// Language appears to not be supported fall back to 'en'
locale = 'en';
}
messages = window._messages[locale];
}
2018-01-30 09:54:45 -05:00
var allReducers = reducer(reducers);
var store = redux.createStore(
allReducers,
redux.applyMiddleware(thunk)
);
// Render view component
ReactDOM.render(
2016-03-18 11:51:22 -04:00
<StoreProvider store={store}>
2018-01-30 09:54:45 -05:00
<IntlProvider locale={locale} messages={messages}>
2016-03-18 11:51:22 -04:00
{jsx}
</IntlProvider>
</StoreProvider>,
element
);
// Get initial session & permissions
store.dispatch(permissionsActions.getPermissions());
store.dispatch(sessionActions.refreshSession());
};
2015-10-16 15:10:17 -04:00
module.exports = render;