engine now Engine, platform now Platform

This commit is contained in:
Adam Bradley
2015-05-04 10:16:53 -05:00
parent 77838300b7
commit 7c41ac739a
8 changed files with 29 additions and 217 deletions

View File

@ -1,6 +1,6 @@
import {Component, View, bootstrap} from 'angular2/angular2' import {Component, View, bootstrap} from 'angular2/angular2'
import {Tabs, Tab} from 'ionic/ionic' import {Tabs, Tab} from 'ionic/ionic'
import {engine} from 'ionic/engine/engine' import {Engine} from 'ionic/engine/engine'
import * as util from 'ionic/util' import * as util from 'ionic/util'
@ -13,18 +13,18 @@ class IonicApp {
constructor() { constructor() {
console.log('IonicApp Start'); console.log('IonicApp Start');
console.log(engine.getName(), engine.is('cordova')); console.log(Engine.getName(), Engine.is('cordova'));
engine.ready().then(() => { Engine.ready().then(() => {
console.log('engine ready') console.log('Engine ready')
}); });
engine.fullScreen(true).then((isShown) => { Engine.fullScreen(true).then((isShown) => {
console.log('fullScreen', isShown) console.log('Engine fullScreen', isShown)
}); });
engine.showStatusBar(true).then((isShown) => { Engine.showStatusBar(true).then((isShown) => {
console.log('showStatusBar', isShown) console.log('Engine showStatusBar', isShown)
}); });
} }

View File

@ -15,7 +15,7 @@ import {BackButton} from 'ionic/components/toolbar/back-button';
import {IonicComponent} from 'ionic/config/component'; import {IonicComponent} from 'ionic/config/component';
import {NavController} from 'ionic/components/nav/nav-item'; import {NavController} from 'ionic/components/nav/nav-item';
import {raf} from 'ionic/util/dom'; import {raf} from 'ionic/util/dom';
import {platform} from 'ionic/platform/platform'; import {Platform} from 'ionic/platform/platform';
// FYI for later: // FYI for later:
@ -47,7 +47,7 @@ export class Toolbar {
// TODO use config to add these classes // TODO use config to add these classes
this.viewContainer.domElement.classList.add('toolbar'); this.viewContainer.domElement.classList.add('toolbar');
this.viewContainer.domElement.classList.add(`toolbar-${platform.getMode()}`); this.viewContainer.domElement.classList.add(`toolbar-${Platform.getMode()}`);
// TODO Make a better way than this // TODO Make a better way than this
if (/header/i.test(this.viewContainer.domElement.tagName)) { if (/header/i.test(this.viewContainer.domElement.tagName)) {

View File

@ -1,188 +0,0 @@
import {platform} from 'ionic/platform/platform'
import * as util from 'ionic/util'
/*
let MyConfig = new ComponentConfig(MyComponent)
MyConfig.classes('classes')
MyConfig.delegate('gesture')
.when({side: 'left'}, LeftAsideGesture)
.when({side: 'right'}, RightAsideGesture)
.when({side: 'top'}, TopAsideGesture)
.when({side: 'bottom'}, BottomAsideGesture)
*/
export function ComponentConfig(componentCssName) {
let platformName = platform.get().name;
return class Config {
static classes() {
Config.classProperties || (Config.classProperties = [])
Config.classProperties.push.apply(Config.classProperties, arguments)
return Config
}
static delegate(delegateName) {
let self = {
when(condition, DelegateConstructor) {
Config.addCase(delegateName, condition, DelegateConstructor)
return self
}
}
return self
}
static platform(name, Class) {
Config.platformFns = Config.platformFns || []
if (name === platformName) {
Config.platformFns.unshift(Class)
}
return Config
}
static addCase(delegateName, condition, DelegateConstructor) {
Config.registry || (Config.registry = {})
var array = (Config.registry[delegateName] || (Config.registry[delegateName] = []))
let callback = condition
if (util.isObject(callback)) {
// Support eg `{side: 'left'}` as a condition
callback = (instance) => {
for (let key in condition) {
if (condition.hasOwnProperty(key) && instance[key] !== condition[key]) {
return false
}
}
return true
}
}
array.unshift({ callback, DelegateConstructor })
}
create(instance) {
instance.domElement.classList.add(componentCssName)
instance.domElement.classList.add(`${componentCssName}-${platformName}`)
for (let i = 0; i < (Config.classProperties || []).length; i++) {
let propertyValue = instance[Config.classProperties[i]]
instance.domElement.classList.add(`${componentCssName}-${propertyValue}`)
}
for (let i = 0; i < (Config.platformFns || []).length; i++) {
new Config.platformFns[i](instance)
}
return {
getDelegate(delegateName) {
let registry = Config.registry && Config.registry[delegateName] || []
for (let i = 0; i < registry.length; i++) {
let condition = registry[i]
if (condition.callback(instance)) {
return new condition.DelegateConstructor(instance)
}
}
}
}
}
}
}
// TODO stop hardcoding platforms and media sizes
/*
@ConfigPlatform({
for: AsideBase
platform: 'android',
defaults: {
type: 'reveal'
}
})
class AndroidAside extends AsideBase {}
```@ConfigCase({
for: AsideBase,
condition: instance => instance.type === 'reveal'
})
class AsideReveal {
constructor(aside: AsideBase) {}
}
*/
// export class Config extends ConfigCase {
// constructor() {
// this._root = this
// this._cases = {}
// super({
// root: this,
// parent: null,
// path: ''
// })
// }
// invoke(instance) {
// return invokeConfig(this, instance)
// }
// _addCase(key, baseCase) {
// let path = baseCase._path.slice()
// path.push(key)
// // Remove empties & duplicates
// path = path
// .filter((value, index) => {
// return value && path.indexOf(value) === index
// })
// .sort()
// if (path.join(' ') === baseCase._path.join(' ')) {
// return baseCase
// }
// return this._createCase(path)
// }
// _createCase(path) {
// if (!path.length) return this
// let pathStr = path.join(' ')
// let configCase = this._cases[pathStr]
// if (!configCase) {
// let parentPath = path.slice(0, path.length - 1)
// configCase = this._cases[pathStr] = new ConfigCase({
// root: this,
// parent: this._createCase(parentPath),
// path: path
// })
// }
// return configCase
// }
// }
// export function invokeConfig(config, object) {
// let platformName = platform.get().name
// let passedCases = [config].concat(
// Object.keys(config._cases)
// .map(name => config._cases[name])
// .filter(configCasePasses)
// .sort(function(a,b) {
// return a._path.length < b._path.length ? -1 : 1
// })
// )
// // Extend the given object with the values of all the passed cases, starting with the
// // most specific.
// let defaults = [object]
// // Also find the most specific case with a component that we should use.
// let ComponentToUse
// for (let i = 0, ii = passedCases.length i < ii i++) {
// defaults.push(passedCases[i]._values)
// if (passedCases[i]._component) {
// ComponentToUse = passedCases[i]._component
// }
// }
// util.defaults.apply(null, defaults)
// return ComponentToUse
// function configCasePasses(configCase) {
// let path = configCase._path
// let key
// for (let i = 0, ii = path.length i < ii i++) {
// if (platformName !== path[i]) return false
// }
// return true
// }
// }

View File

@ -1,7 +1,7 @@
import * as util from 'ionic/util' import * as util from 'ionic/util'
import {platform} from 'ionic/platform/platform' import {Platform} from 'ionic/platform/platform'
let platformMode = platform.getMode() let platformMode = Platform.getMode();
// Low-level: how the user will override // Low-level: how the user will override
// BackButton.config.bind.icon.value = 'ion-chevron-right' // BackButton.config.bind.icon.value = 'ion-chevron-right'

View File

@ -1,7 +1,7 @@
import {engine} from '../engine'; import {Engine} from '../engine';
engine.register({ Engine.register({
name: 'cordova', name: 'cordova',
isMatch() { isMatch() {
return !(!window.cordova && !window.PhoneGap && !window.phonegap); return !(!window.cordova && !window.PhoneGap && !window.phonegap);

View File

@ -1,8 +1,8 @@
import * as util from 'ionic/util'; import * as util from 'ionic/util';
import {engine} from '../engine'; import {Engine} from '../engine';
engine.register({ Engine.register({
name: 'electron', name: 'electron',
isMatch() { isMatch() {
try { try {

View File

@ -42,16 +42,16 @@ class EngineController {
return activeEngine || defaultEngine; return activeEngine || defaultEngine;
} }
set(eng) { set(engine) {
activeEngine = eng; activeEngine = engine;
} }
setDefault(eng) { setDefault(engine) {
defaultEngine = eng; defaultEngine = engine;
} }
register(eng) { register(engine) {
registry[eng.name] = eng; registry[engine.name] = engine;
} }
detect() { detect() {
@ -65,9 +65,9 @@ class EngineController {
} }
export let engine = new EngineController(); export let Engine = new EngineController();
engine.setDefault({ Engine.setDefault({
name: 'default', name: 'default',
ready: util.dom.windowLoad ready: util.dom.windowLoad
}); });

View File

@ -51,14 +51,14 @@ class PlatformController {
} }
} }
export let platform = new PlatformController(); export let Platform = new PlatformController();
const ua = window.navigator.userAgent; const ua = window.navigator.userAgent;
const queryPlatform = (util.getQuerystring('ionicplatform')).toLowerCase() const queryPlatform = (util.getQuerystring('ionicplatform')).toLowerCase()
platform.register({ Platform.register({
name: 'android', name: 'android',
mode: 'md', mode: 'md',
isMatch() { isMatch() {
@ -66,7 +66,7 @@ platform.register({
} }
}); });
platform.register({ Platform.register({
name: 'ios', name: 'ios',
isMatch() { isMatch() {
return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua) return queryPlatform === 'ios' || /ipad|iphone|ipod/i.test(ua)
@ -74,8 +74,8 @@ platform.register({
}); });
// Last case is a catch-all // Last case is a catch-all
platform.setDefault({ Platform.setDefault({
name: 'core' name: 'core'
}); });
platform.set( platform.detect() ); Platform.set( Platform.detect() );