improve options handling between classes

This commit is contained in:
2016-05-14 23:24:11 +02:00
parent 1f3f2ae92f
commit 454a999a42
10 changed files with 54 additions and 16 deletions

View File

@ -2,7 +2,6 @@
import * as plugins from "./taskbuffer.plugins"
import * as helpers from "./taskbuffer.classes.helpers"
export class Task {
name:string;
task:any;
@ -16,7 +15,14 @@ export class Task {
preTask:Task;
afterTask:Task;
constructor(optionsArg:{taskFunction:any,preTask?:Task,afterTask?:Task, buffered?:boolean, bufferMax?:number}){
constructor(optionsArg:{
taskFunction:any,
preTask?:Task,
afterTask?:Task,
buffered?:boolean,
bufferMax?:number,
name?:string
}){
if (!optionsArg){optionsArg = {taskFunction:function(){}}}
var options = optionsArg;
this.task = optionsArg.taskFunction;
@ -26,6 +32,7 @@ export class Task {
this.idle = true;
this.buffered = options.buffered;
this.bufferMax = options.bufferMax;
this.name = options.name;
}
trigger(){

View File

@ -6,8 +6,11 @@ import helpers = require("./taskbuffer.classes.helpers");
export class Taskchain extends Task {
taskArray:Task[];
private _oraObject;
constructor(taskArrayArg:Task[]|Task){
super({
constructor(optionsArg:{
taskArray:Task[]
name?:string
}){
let options = plugins.lodash.assign(optionsArg,{
taskFunction: () => { // this is the function that gets executed when TaskChain is triggered
if(this.taskArray.length = 0) return; //make sure there is actually a Task available to execute
let startDeferred = plugins.Q.defer(); // this is the starting Deferred object
@ -21,6 +24,8 @@ export class Taskchain extends Task {
startDeferred.resolve();
}
});
super(options);
this.taskArray = optionsArg.taskArray;
this._oraObject = plugins.beautylog.ora("Taskchain idle","blue");
}
addTask(taskArg:Task){
@ -32,10 +37,17 @@ export class Taskchain extends Task {
shiftTask(){
};
trigger(){
this._oraObject.start(this.name + "running");
}
};
let myTask = new Taskchain(
new Task({
taskFunction:function(){}
})
{
taskArray: [
new Task({
taskFunction:function(){}
})
]
}
);

View File

@ -1,3 +1,4 @@
/// <reference path="./typings/main.d.ts" />
export import beautylog = require("beautylog");
export let Q = require("q");
export let lodash= require("lodash");