mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Getting nearer to mixin pattern
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
import * as Platform from '../platform';
|
||||
|
||||
var ILLEGAL_ASSIGN_FIELDS = {};
|
||||
export class Ion {
|
||||
|
||||
constructor() {
|
||||
var platformName = Platform.getPlatform();
|
||||
var platformConfig = this.$config._platforms[platformName];
|
||||
if (platformConfig) {
|
||||
platformConfig._mixins.forEach(mixin => {
|
||||
mixin(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
assign() {
|
||||
for (var i = 0, ii = arguments.length; i < ii; i++) {
|
||||
var obj = arguments[i];
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
/*
|
||||
import {TabbarConfig} from '/components/tabbar/tabbar';
|
||||
import {Draggable} from '/behaviors/draggable';
|
||||
|
||||
import {TabbarConfig} from '../../tabbar';
|
||||
// import {Draggable} from '/behaviors/draggable';
|
||||
|
||||
TabbarConfig.platform('android')
|
||||
.template(require('./android-template.html'))
|
||||
.template('./android-template.html')
|
||||
.mixin(function(tabbar) {
|
||||
Draggable(tabbar);
|
||||
tabbarInstance.setAsHeader();
|
||||
// Draggable(tabbar);
|
||||
// tabbarInstance.setAsHeader();
|
||||
|
||||
tabbar.assign({
|
||||
onDragStart() {},
|
||||
onDrag() {},
|
||||
onDragEnd() {}
|
||||
press() {
|
||||
alert('pressing from android mixin');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
<ion-tabs config-platform-android />
|
||||
*/
|
||||
export var a = 2;
|
||||
|
||||
@@ -1,23 +1,31 @@
|
||||
import {Component, Template} from 'angular2/angular2';
|
||||
import {Inject} from 'angular2/di';
|
||||
import {Ion} from '../ion';
|
||||
import {IonConfigService} from '../../config';
|
||||
|
||||
export var TabbarConfig = IonConfigService();
|
||||
|
||||
@Component({
|
||||
selector: 'ion-tabbar',
|
||||
bind: {
|
||||
title: 'view-title'
|
||||
}
|
||||
},
|
||||
services: [TabbarConfig]
|
||||
})
|
||||
@Template({
|
||||
inline: `<button (click)="press()">Tabbar: {{title}}</button>`
|
||||
})
|
||||
export class Tabbar extends Ion {
|
||||
constructor() {
|
||||
|
||||
// Test that Ion#assign works
|
||||
this.assign({
|
||||
press: () => {
|
||||
alert('pressed!');
|
||||
}
|
||||
});
|
||||
constructor(
|
||||
// Creates a TabbarConfig instance for this specific instance of Tabbar.
|
||||
// this instance is created with a cloned version of all the globally
|
||||
// set config properties.
|
||||
@Inject(TabbarConfig) config
|
||||
) {
|
||||
debugger;
|
||||
this.$config = config;
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user