Skip to content

Commit

Permalink
add miox-vue2x widgets methods
Browse files Browse the repository at this point in the history
  • Loading branch information
evio committed Oct 26, 2016
1 parent 1ded0d9 commit b93b796
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
8 changes: 4 additions & 4 deletions build/miox.vue2x.umd.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miox-vue2x",
"version": "0.0.3",
"version": "0.0.1",
"description": "miox-vue2x",
"main": "src/index.js",
"author": "沈赟杰",
Expand Down
14 changes: 9 additions & 5 deletions src/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

import { EventEmitter } from 'events';
import { Params, Events } from './params';
import { Params, Events, Inits } from './params';
import { each, compile, isFunction, isComponent, isVueObject, isObject } from './util';

export default class Component extends EventEmitter {
Expand Down Expand Up @@ -72,6 +72,10 @@ export default class Component extends EventEmitter {
this.__defineTemplateCompile__();
this.__defineFunctionalCompile__();
this.__defineRenderCompile__();

Inits.forEach(init => {
init(this.__dataBase__);
});
}

/**
Expand Down Expand Up @@ -125,14 +129,14 @@ export default class Component extends EventEmitter {
* @private
*/
__defineExtendCompile__(){
if ( isFunction(this['extends']) ){
const result = this['extends']();
if ( isFunction(this.extends) ){
const result = this.extends();

if ( result ){
this.__dataBase__.extends = result;
}
} else if ( isVueObject(this['extends']) ) {
this.__dataBase__.extends = this['extends'];
} else if ( isVueObject(this.extends) ) {
this.__dataBase__.extends = this.extends;
} else {
return;
}
Expand Down
41 changes: 41 additions & 0 deletions src/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Promise } from 'es6-promise';
import isClass from 'is-class';
import Vue from 'vue';
import { makeDirectiveUrlParams, toLinkString } from './util';
import { Params, Events, Inits } from './params';

export default class Engine {
constructor(ctx){
Expand Down Expand Up @@ -51,4 +52,44 @@ export default class Engine {

return wrapElement;
}

addParam(name){
Params.push(name);
return this;
}

addParams(...args){
args.forEach(arg => {
this.addParam(arg);
});
return this;
}

addEvent(name){
Events.push(name);
return this;
}

addEvents(...args){
args.forEach(arg => {
this.addEvent(arg);
});
return this;
}

addCompiler(fn){
if ( typeof fn === 'function' ){
Inits.push(fn);
}else{
throw new Error('addInit methods need a function object');
}
return this;
}

addCompilers(...args){
args.forEach(arg => {
this.addCompiler(arg);
});
return this;
}
}

0 comments on commit b93b796

Please sign in to comment.