mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
@@ -16,10 +16,14 @@ import {TapClick} from '../components/tap-click/tap-click';
|
||||
import * as dom from '../util/dom';
|
||||
|
||||
|
||||
export function ionicBindings(rootCmp, configSettings) {
|
||||
export function ionicBindings(rootCmp, config) {
|
||||
let app = new IonicApp();
|
||||
let platform = new IonicPlatform();
|
||||
let config = new IonicConfig(configSettings);
|
||||
|
||||
if (!(config instanceof IonicConfig)) {
|
||||
config = new IonicConfig(config);
|
||||
}
|
||||
|
||||
let events = new Events();
|
||||
let tapClick = new TapClick(app, config, window, document);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {IonicPlatform} from '../platform/platform';
|
||||
import {isObject, isDefined, isFunction, extend} from '../util/util';
|
||||
import {isObject, isDefined, isFunction, isArray, extend} from '../util/util';
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -16,10 +16,10 @@ export class IonicConfig {
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* @param {Object} settings The settings for your app
|
||||
* @param {Object} config The config for your app
|
||||
*/
|
||||
constructor(settings={}) {
|
||||
this._s = settings;
|
||||
constructor(config) {
|
||||
this._s = config && isObject(config) && !isArray(config) ? config : {};
|
||||
this._c = {}; // cached values
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,39 @@
|
||||
import {IonicConfig, IonicPlatform} from 'ionic/ionic';
|
||||
import {IonicConfig, IonicPlatform, ionicBindings} from 'ionic/ionic';
|
||||
|
||||
export function run() {
|
||||
|
||||
it('should create a new IonicConfig instace when no confg passed in ionicBindings', () => {
|
||||
let rootCmp = function(){};
|
||||
let bindings = ionicBindings(rootCmp);
|
||||
|
||||
let config = bindings.find(binding => binding.toValue instanceof IonicConfig).toValue;
|
||||
|
||||
expect(config.get('mode')).toEqual('ios');
|
||||
});
|
||||
|
||||
it('should used passed in IonicConfig instance in ionicBindings', () => {
|
||||
let rootCmp = function(){};
|
||||
let userConfig = new IonicConfig({
|
||||
mode: 'configInstance'
|
||||
})
|
||||
let bindings = ionicBindings(rootCmp, userConfig);
|
||||
|
||||
let config = bindings.find(binding => binding.toValue instanceof IonicConfig).toValue;
|
||||
|
||||
expect(config.get('mode')).toEqual('configInstance');
|
||||
});
|
||||
|
||||
it('should create new IonicConfig instance from config object in ionicBindings', () => {
|
||||
let rootCmp = function(){};
|
||||
let bindings = ionicBindings(rootCmp, {
|
||||
mode: 'configObj'
|
||||
});
|
||||
|
||||
let config = bindings.find(binding => binding.toValue instanceof IonicConfig).toValue;
|
||||
|
||||
expect(config.get('mode')).toEqual('configObj');
|
||||
});
|
||||
|
||||
it('should override mode settings', () => {
|
||||
let config = new IonicConfig({
|
||||
mode: 'md'
|
||||
@@ -317,4 +349,36 @@ export function run() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should create default config w/ bad settings value', () => {
|
||||
let config = new IonicConfig(null);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(undefined);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig();
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig([1,2,3]);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig('im bad, you know it');
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(8675309);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(true);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(false);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(1);
|
||||
expect(config.settings()).toEqual({});
|
||||
|
||||
config = new IonicConfig(function(){});
|
||||
expect(config.settings()).toEqual({});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user