mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
wip
This commit is contained in:
@ -146,7 +146,11 @@ export function ionicBootstrap(ComponentType, config) {
|
||||
let platform = Platform.create(app);
|
||||
|
||||
config = config || new IonicConfig();
|
||||
config.platform(platform);
|
||||
|
||||
// copy default platform settings into the user config platform settings
|
||||
// user config platform settings should override default platform settings
|
||||
config.setPlatform(platform);
|
||||
|
||||
|
||||
GlobalIonicConfig = config;
|
||||
|
||||
|
@ -152,8 +152,13 @@ export function main(ionicBootstrap) {
|
||||
|
||||
let myConfig = new IonicConfig();
|
||||
|
||||
//myConfig.setting('someKey', 'userConfig');
|
||||
// myConfig.setting('ios', 'someKey', 'iosConfig');
|
||||
// myConfig.setting('ipad', 'someKey', 'ipadConfig');
|
||||
|
||||
ionicBootstrap(MyApp, myConfig).then(root => {
|
||||
|
||||
console.log('someKey', myConfig.setting('someKey'));
|
||||
console.log(myConfig.setting('mode'));
|
||||
|
||||
console.log('mobile', root.platform.is('mobile'))
|
||||
|
@ -1,14 +1,10 @@
|
||||
import {isObject, isDefined} from '../util/util';
|
||||
import {isString, isObject, isDefined, extend} from '../util/util';
|
||||
|
||||
|
||||
export class IonicConfig {
|
||||
|
||||
constructor(settings={}) {
|
||||
this.setting(settings);
|
||||
}
|
||||
|
||||
platform(platform) {
|
||||
this._platform = platform;
|
||||
constructor(settings) {
|
||||
this.setting(settings || {});
|
||||
}
|
||||
|
||||
setting() {
|
||||
@ -33,37 +29,43 @@ export class IonicConfig {
|
||||
// setting({...}) = set settings object
|
||||
// arg0 = setting object
|
||||
this._settings = arg0;
|
||||
break;
|
||||
return this;
|
||||
}
|
||||
|
||||
// time for the big show, get the value
|
||||
// setting('key') = get value
|
||||
// arg0 = key
|
||||
if (isDefined(s[arg0])) {
|
||||
// value found in users settings object
|
||||
return s[arg0];
|
||||
}
|
||||
// arg0 must be a string to get a property
|
||||
if (isString(arg0)) {
|
||||
// time for the big show, get the value
|
||||
// setting('key') = get value
|
||||
// arg0 = key
|
||||
|
||||
// check the users platform settings object
|
||||
// loop though each of the active platforms
|
||||
let activePlatformKeys = this._platform.platforms();
|
||||
let platformSettings = s.platforms;
|
||||
if (platformSettings) {
|
||||
let platformValue = undefined;
|
||||
for (let i = 0; i < activePlatformKeys.length; i++) {
|
||||
if ( platformSettings[ activePlatformKeys[i] ] ) {
|
||||
platformValue = platformSettings[ activePlatformKeys[i] ][arg0];
|
||||
if (!isDefined(s[arg0])) {
|
||||
// if the value was already set this will all be skipped
|
||||
// if there was no user config then it'll check each of
|
||||
// the user config's platforms, which already contains
|
||||
// settings from default platform configs
|
||||
s[arg0] = null;
|
||||
|
||||
// check the platform settings object for this value
|
||||
// loop though each of the active platforms
|
||||
let activePlatformKeys = this._platforms;
|
||||
let platformSettings = s.platforms;
|
||||
let platformObj = null;
|
||||
if (platformSettings) {
|
||||
let platformValue = undefined;
|
||||
for (let i = 0; i < activePlatformKeys.length; i++) {
|
||||
platformObj = platformSettings[ activePlatformKeys[i] ];
|
||||
if (platformObj && isDefined(platformObj[arg0])) {
|
||||
platformValue = platformObj[arg0];
|
||||
}
|
||||
}
|
||||
if (isDefined(platformValue)) {
|
||||
s[arg0] = platformValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isDefined(platformValue)) {
|
||||
return platformValue;
|
||||
}
|
||||
}
|
||||
|
||||
// check the value from the default platform settings
|
||||
platformSettings = this._platform.settings();
|
||||
if (isDefined(platformSettings[arg0])) {
|
||||
return platformSettings[arg0];
|
||||
// return value.
|
||||
return s[arg0];
|
||||
}
|
||||
|
||||
// idk
|
||||
@ -73,21 +75,20 @@ export class IonicConfig {
|
||||
case 2:
|
||||
// setting('ios', {...}) = set platform config object
|
||||
// setting('key', 'value') = set key/value pair
|
||||
|
||||
if (isObject(arg1)) {
|
||||
// setting('ios', {...}) = set platform config object
|
||||
// arg0 = platform
|
||||
// arg1 = platform config object
|
||||
s.platforms = s.platforms || {};
|
||||
s.platforms[arg0] = arg1;
|
||||
break;
|
||||
}
|
||||
|
||||
// setting('key', 'value') = set key/value pair
|
||||
// arg0 = key
|
||||
// arg1 = value
|
||||
s[arg0] = arg1;
|
||||
break;
|
||||
} else {
|
||||
// setting('key', 'value') = set key/value pair
|
||||
// arg0 = key
|
||||
// arg1 = value
|
||||
s[arg0] = arg1;
|
||||
}
|
||||
return this;
|
||||
|
||||
|
||||
case 3:
|
||||
@ -98,9 +99,21 @@ export class IonicConfig {
|
||||
s.platforms = s.platforms || {};
|
||||
s.platforms[arg0] = s.platforms[arg0] || {};
|
||||
s.platforms[arg0][arg1] = args[2];
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setPlatform(platform) {
|
||||
// get the array of active platforms, which also knows the hierarchy,
|
||||
// with the last one the most important
|
||||
this._platforms = platform.platforms();
|
||||
|
||||
// copy default platform settings into the user config platform settings
|
||||
// user config platform settings should override default platform settings
|
||||
this._settings.platforms = this._settings.platforms || {};
|
||||
this._settings.platforms = extend(platform.settings(), this._settings.platforms);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,13 +12,6 @@ export class Platform {
|
||||
return (this._platforms.indexOf(platformName) > -1);
|
||||
}
|
||||
|
||||
platforms(val) {
|
||||
if (arguments.length) {
|
||||
this._platforms = val;
|
||||
}
|
||||
return this._platforms;
|
||||
}
|
||||
|
||||
settings(val) {
|
||||
if (arguments.length) {
|
||||
this._settings = val;
|
||||
@ -39,6 +32,12 @@ export class Platform {
|
||||
this._platforms.push(platformName);
|
||||
}
|
||||
|
||||
platforms() {
|
||||
// get the array of active platforms, which also knows the hierarchy,
|
||||
// with the last one the most important
|
||||
return this._platforms;
|
||||
}
|
||||
|
||||
|
||||
/* Static Methods */
|
||||
static create(app) {
|
||||
@ -81,17 +80,23 @@ export class Platform {
|
||||
|
||||
let platform = new Platform();
|
||||
if (rootNode) {
|
||||
let platformNode = rootNode.child();
|
||||
let platformNode = rootNode;
|
||||
while (platformNode) {
|
||||
insertSuperset(platformNode);
|
||||
platformNode = platformNode.child();
|
||||
}
|
||||
|
||||
platformNode = rootNode.child();
|
||||
platformNode = rootNode;
|
||||
let settings = {};
|
||||
while (platformNode) {
|
||||
// set the array of active platforms with
|
||||
// the last one in the array the most important
|
||||
platform.add(platformNode.name());
|
||||
util.extend(settings, platformNode.settings());
|
||||
|
||||
// copy default platform settings into this platform settings obj
|
||||
settings[platformNode.name()] = util.extend({}, platformNode.settings());
|
||||
|
||||
// go to the next child
|
||||
platformNode = platformNode.child();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user