scratch-www/src/lib/render.jsx

45 lines
1.2 KiB
React
Raw Normal View History

2016-03-18 11:51:22 -04:00
var redux = require('redux');
var thunk = require('redux-thunk').default;
var ReactDOM = require('react-dom');
2016-03-18 11:51:22 -04:00
var StoreProvider = require('react-redux').Provider;
var IntlProvider = require('./intl.jsx').IntlProvider;
2016-03-18 11:51:22 -04:00
var actions = require('../redux/actions.js');
var reducer = require('../redux/reducer.js');
require('../main.scss');
2016-03-18 11:51:22 -04:00
var store = redux.createStore(
reducer,
redux.applyMiddleware(thunk)
);
var render = function (jsx, element) {
// Get locale and messages from global namespace (see "init.js")
var locale = window._locale || 'en';
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';
}
var messages = window._messages[locale];
// Render view component
ReactDOM.render(
2016-03-18 11:51:22 -04:00
<StoreProvider store={store}>
<IntlProvider locale={locale} messages={messages}>
{jsx}
</IntlProvider>
</StoreProvider>,
element
);
2016-03-18 11:51:22 -04:00
// Get initial session
store.dispatch(actions.refreshSession());
};
2015-10-16 15:10:17 -04:00
module.exports = render;