Skip to content

Commit

Permalink
Intl polyfill for unsupported clients [closes kriasoft#639]
Browse files Browse the repository at this point in the history
  • Loading branch information
langpavel committed May 26, 2016
1 parent 21c77a8 commit eabbf0d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
9 changes: 1 addition & 8 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function render(container, state, config, component) {
});
}

function run() {
export default function main() {
let currentLocation = null;
const container = document.getElementById('app');
const initialState = JSON.parse(
Expand Down Expand Up @@ -143,10 +143,3 @@ function run() {
removeHistoryListener();
});
}

// Run the application when both DOM is ready and page content is loaded
if (['complete', 'loaded', 'interactive'].includes(document.readyState) && document.body) {
run();
} else {
document.addEventListener('DOMContentLoaded', run, false);
}
26 changes: 26 additions & 0 deletions src/clientLoader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

import main from './client';

function run() {
// Run the application when both DOM is ready and page content is loaded
if (['complete', 'loaded', 'interactive'].includes(document.readyState) && document.body) {
main();
} else {
document.addEventListener('DOMContentLoaded', main, false);
}
}

if (!global.Intl) {
require.ensure([
'intl',
'intl/locale-data/jsonp/en.js',
'intl/locale-data/jsonp/cs.js',
], require => {
require('intl');
require('intl/locale-data/jsonp/en.js');
require('intl/locale-data/jsonp/cs.js');
run();
}, 'intl');
} else {
run();
}
2 changes: 1 addition & 1 deletion tools/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const config = {
// -----------------------------------------------------------------------------

const clientConfig = extend(true, {}, config, {
entry: './client.js',
entry: './clientLoader.js',

output: {
filename: DEBUG ? '[name].js?[chunkhash]' : '[name].[chunkhash].js',
Expand Down

0 comments on commit eabbf0d

Please sign in to comment.