Add font loading service

This commit is contained in:
SleepWalker 2017-01-25 07:52:19 +02:00
parent 770a6c3ae9
commit bab6293d9e
2 changed files with 24 additions and 17 deletions

View File

@ -6,8 +6,6 @@ import ReactDOM from 'react-dom';
import { Provider as ReduxProvider } from 'react-redux';
import { Router, browserHistory } from 'react-router';
import webFont from 'webfontloader';
import { factory as userFactory } from 'components/user/factory';
import { IntlProvider } from 'components/i18n';
import routesFactory from 'routes';
@ -15,6 +13,7 @@ import storeFactory from 'storeFactory';
import bsodFactory from 'components/ui/bsod/factory';
import loader from 'services/loader';
import logger from 'services/logger';
import font from 'services/font';
logger.init({
sentryCdn: window.SENTRY_CDN
@ -22,27 +21,13 @@ logger.init({
import dispatchBsod from 'components/ui/bsod/dispatchBsod'; // TODO: remove after tests
import dispatchBsod from 'components/ui/bsod/dispatchBsod'; // TODO: remove after tests
const store = storeFactory();
bsodFactory(store, stopLoading);
const fontLoadingPromise = new Promise((resolve) =>
webFont.load({
classes: false,
active: resolve,
inactive: resolve, // TODO: may be we should track such cases
timeout: 2000,
custom: {
families: ['Roboto', 'Roboto Condensed']
}
})
);
Promise.all([
userFactory(store),
fontLoadingPromise
font.load(['Roboto', 'Roboto Condensed'])
])
.then(() => {
ReactDOM.render(

22
src/services/font.js Normal file
View File

@ -0,0 +1,22 @@
import webFont from 'webfontloader';
export default {
/**
* @param {array} families
*
* @return {Promise}
*/
load(families = []) {
return new Promise((resolve) =>
webFont.load({
classes: false,
active: resolve,
inactive: resolve, // TODO: may be we should track such cases
timeout: 2000,
custom: {
families
}
})
);
}
};