diff --git a/core/src/global/config.ts b/core/src/global/config.ts deleted file mode 100644 index 1eaad39b7b..0000000000 --- a/core/src/global/config.ts +++ /dev/null @@ -1,34 +0,0 @@ - -export class Config { - - private m: Map; - - constructor(configObj: {[key: string]: any}|undefined) { - this.m = new Map(configObj ? Object.entries(configObj) : undefined); - } - - get(key: string, fallback?: any): any { - const value = this.m.get(key); - return (value !== undefined) ? value : fallback; - } - - getBoolean(key: string, fallback = false): boolean { - const val = this.m.get(key); - if (val === undefined) { - return fallback; - } - if (typeof val === 'string') { - return val === 'true'; - } - return !!val; - } - - getNumber(key: string, fallback?: number): number { - const val = parseFloat(this.m.get(key)); - return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val; - } - - set(key: string, value: any) { - this.m.set(key, value); - } -} diff --git a/core/src/global/ionic-global.ts b/core/src/global/ionic-global.ts index ca99cdc5f5..c2f62ed244 100644 --- a/core/src/global/ionic-global.ts +++ b/core/src/global/ionic-global.ts @@ -1,6 +1,6 @@ import 'ionicons'; -import { Config } from './config'; -import { configFromURL, isIOS } from '../utils/platform'; +import { Config, configFromURL } from '../utils/config'; +import { isIOS } from '../utils/platform'; const Ionic = (window as any).Ionic = (window as any).Ionic || {}; declare const Context: any; diff --git a/core/src/global/queue-controller.ts b/core/src/global/queue-controller.ts deleted file mode 100644 index 70bd6fcb62..0000000000 --- a/core/src/global/queue-controller.ts +++ /dev/null @@ -1,13 +0,0 @@ - -export interface QueueController { - read: DomControllerCallback; - write: DomControllerCallback; -} - -export interface RafCallback { - (timeStamp: number): void; -} - -export interface DomControllerCallback { - (cb: RafCallback): void; -} diff --git a/core/src/index.d.ts b/core/src/index.d.ts index 7a7093e469..305336ccb8 100644 --- a/core/src/index.d.ts +++ b/core/src/index.d.ts @@ -104,8 +104,7 @@ export { Toolbar } from './components/toolbar/toolbar'; // export all of the component declarations that are dynamically created export * from './components'; -export { Config } from './global/config'; -export { QueueController, RafCallback } from './global/queue-controller'; +export { Config } from './utils/config'; export { FrameworkDelegate } from './utils/framework-delegate'; export { OverlayEventDetail } from './utils/overlays'; export * from './utils/platform'; @@ -116,6 +115,20 @@ export type ComponentRef = Function | HTMLElement | string; export type ComponentProps = {[key: string]: any}; export type CssClassMap = { [className: string]: boolean }; +export interface QueueController { + read: DomControllerCallback; + write: DomControllerCallback; +} + +export interface RafCallback { + (timeStamp: number): void; +} + +export interface DomControllerCallback { + (cb: RafCallback): void; +} + + declare global { namespace JSXElements { diff --git a/core/src/utils/config.ts b/core/src/utils/config.ts new file mode 100644 index 0000000000..3f87b2ca4d --- /dev/null +++ b/core/src/utils/config.ts @@ -0,0 +1,61 @@ + +export function setupConfig(config: {[key: string]: any}, win: any) { + const Ionic = win.Ionic; + if (Ionic && Ionic.config && Ionic.config.constructor.name !== 'Object') { + console.error('ionic config was already initialized'); + return; + } + win.Ionic = win.Ionic || {}; + win.Ionic.Config = { + ...win.Ionic.Config, + ...config + }; + return win.Ionic.Config; +} + +export function configFromURL(win: Window) { + const config: any = {}; + win.location.search.slice(1) + .split('&') + .filter(entryText => entryText.startsWith('ionic:')) + .map(entryText => entryText.split('=')) + .forEach(entry => { + config[entry[0].slice(6)] = decodeURIComponent(entry[1]); + }); + + return config; +} + +export class Config { + + private m: Map; + + constructor(configObj: {[key: string]: any}) { + this.m = new Map(Object.entries(configObj)); + } + + get(key: string, fallback?: any): any { + const value = this.m.get(key); + return (value !== undefined) ? value : fallback; + } + + getBoolean(key: string, fallback = false): boolean { + const val = this.m.get(key); + if (val === undefined) { + return fallback; + } + if (typeof val === 'string') { + return val === 'true'; + } + return !!val; + } + + getNumber(key: string, fallback?: number): number { + const val = parseFloat(this.m.get(key)); + return isNaN(val) ? (fallback !== undefined ? fallback : NaN) : val; + } + + set(key: string, value: any) { + this.m.set(key, value); + } +} diff --git a/core/src/utils/platform.ts b/core/src/utils/platform.ts index 17ed4dd367..c68e1a2d1a 100644 --- a/core/src/utils/platform.ts +++ b/core/src/utils/platform.ts @@ -63,16 +63,3 @@ export function needInputShims(win: Window) { export function testUserAgent(win: Window, expr: RegExp) { return expr.test(win.navigator.userAgent); } - -export function configFromURL(win: Window) { - const config: any = {}; - win.location.search.slice(1) - .split('&') - .filter(entryText => entryText.startsWith('ionic:')) - .map(entryText => entryText.split('=')) - .forEach(entry => { - config[entry[0].slice(6)] = decodeURIComponent(entry[1]); - }); - - return config; -}