perf(platform): remove from critical path

This commit is contained in:
Manu Mtz.-Almeida
2018-04-18 23:06:56 +02:00
parent 861ce49363
commit 86a6cde4a1
23 changed files with 347 additions and 1001 deletions

View File

@ -1,10 +1,8 @@
import 'ionicons';
import { createConfigController } from './config-controller';
import { PLATFORM_CONFIGS, detectPlatforms, readQueryParam } from './platform-configs';
import { Config } from './config';
import { configFromURL, isIOS } from '../utils/platform';
const Ionic = (window as any).Ionic = (window as any).Ionic || {};
declare const Context: any;
// queue used to coordinate DOM reads and
@ -13,25 +11,18 @@ Object.defineProperty(Ionic, 'queue', {
get: () => Context.queue
});
if (!Context.platforms) {
Context.platforms = detectPlatforms(window.location.href, window.navigator.userAgent, PLATFORM_CONFIGS, 'core');
}
if (!Context.readQueryParam) {
Context.readQueryParam = readQueryParam;
}
// create the Ionic.config from raw config object (if it exists)
// and convert Ionic.config into a ConfigApi that has a get() fn
Ionic.config = Context.config = createConfigController(
Ionic.config,
Context.platforms
);
const config = Ionic.config = Context.config = new Config({
...configFromURL(window),
...Ionic.config,
});
// first see if the mode was set as an attribute on <html>
// which could have been set by the user, or by prerendering
// otherwise get the mode via config settings, and fallback to md
Ionic.mode = Context.mode = document.documentElement.getAttribute('mode') || Context.config.get('mode', 'md');
// ensure we've got the mode attribute set on <html>
document.documentElement.setAttribute('mode', Ionic.mode);
const documentElement = document.documentElement;
const mode = config.get('mode', documentElement.getAttribute('mode') || (isIOS(window) ? 'ios' : 'md'));
Ionic.mode = Context.mode = mode;
config.set('mode', mode);
documentElement.setAttribute('mode', Ionic.mode);