Product Manipulation

Eric McGary edited this page Feb 1, 2013 · 2 revisions

Out of date - Will be updated soon!

Check out the live docs for the most up to date functionality until then.


There may be instances where sub tasks will be contained in seperate modules (especially in node apps), yet you want to manipulate an object or data set throughout the execution of the group. It is possible to do this with the library through product manilpulation. Every task has a `product` attribute available to it. If the task is a sub task contained within a group then its product is set to the groups when it is processed. It is then up to the developer to pass that manipulated product through the `complete` method when the sub task has completed. By default the groups product is simply overwritten during this process, however you can override the `handleProduct` method of the task and handle this yourself. The following example illustrates this...

	var t1 = new MonkeyBars.Task({
		performTask:function(){
			this.complete(this.product + 200);
		}
	});

	var t2 = new MonkeyBars.Task({
		performTask:function(){
			this.complete(this.product / 2);
		}
	});

	var group = new MonkeyBars.SequenceTask({
		product:0,
		tasks:[t1,t2],
		handleProduct:function(product){
			this.product = product / 2;
		},
		onComplete:function(){
			console.log(this.product);
		}
	});

	group.start();