@nwhite: I'm not too sure why such a 'run' function would be useful. If all the functions in the chain are to be called in order, immediately, then why go to the hassle of creating a chain for them? Why not just call the required functions in order?
I thought that Chain is useful for when at least one of the conditions for moving to the next function in the chain is satisfied "later", say after a transition or Ajax request. In this case I suspect such a 'run' function would not give the desired effect. On Mon, Apr 27, 2009 at 8:30 AM, nwhite <[email protected]> wrote: > @Michal - your reference info is great. > > I have heard/seen a lot of confusion/hassle around the need for 'callChain' > within chained methods for auto run chaining actions. > > The example below automatically calls the next function in the chain stack > without the need for using 'callChain'. It supports passing arguments to > each function in the chain and returning the value of the final function in > the chain. > > I think it makes the usage of chains a lot more convenient as it fully > decouples 'Chain' from the actual chained functions. > > > Chain.implement({ > run : function(){ > while(this.$chain.length) var arguments = > this.$chain.shift().apply(this,$splat(arguments)); > return arguments; > } > }); > > var myChain = new Chain(); > > myChain.chain( > function(x){ console.log('chain',x); return ++x; }, > function(x){ console.log('chain',x); return ++x; }, > function(x){ console.log('chain',x); return ++x; } > ); > > var x = myChain.run(1); > console.log(x); > > /* output > chain 1 > chain 2 > chain 3 > 4 > */ > > > > > On Mon, Apr 27, 2009 at 12:10 AM, Michal Charemza <[email protected]> > wrote: >> >> Just for reference, there is also quite a long post over at MooForum >> discussing chaining >> http://www.mooforum.net/help12/chain-guide-t1347.html (erm... written by >> me!) >> >> Michal. >> >> >> On 27 Apr 2009, at 02:37, nutron wrote: >> >>> Chain has 2 main methods and you have to use both in order for it to do >>> anything: >>> >>> chain - pushes a function onto the stack >>> callChain - calls the next function on the stack >>> >>> so if you want to do: >>> >>> this.fn1().chain(this.fn2.bind(this)); >>> >>> then fn1 has to have this in it: >>> >>> fn1: function(){ >>> ...some logic that you want to execute >>> this.callChain(); >>> return this; >>> } >>> >>> On Sun, Apr 26, 2009 at 6:17 PM, nwhite (via Nabble) >>> <ml-user%2b93763-1341009...@...> wrote: >>> >>> if(this.options.preload){ >>> new Asset.images(['/images/myImage.png', '/images/myImage2.gif'], { >>> >>> >>> >>> onComplete: this.setUp >>> >>> }); >>> } >>> >>> >>> On Sun, Apr 26, 2009 at 6:06 PM, mmjaeger <mmjae...@...> wrote: >>> >>> I'm not sure whether that would work. >>> >>> the following code actually does work but I hopped there is an easier >>> way to do it: >>> >>> /* >>> >>> if (this.options.preload) { >>> var callback = new Chain(); >>> this._preload(callback); >>> callback.chain ( >>> function() { >>> this.setUp(); >>> }.bind(this) >>> ) >>> } else { >>> this.setUp(); >>> }*/ >>> >>> On Apr 26, 5:17 pm, "asgaroth.belem" <asgaroth.be...@...> wrote: >>> > I think all you have to do is (not sure, sorry for any mistakes): >>> > >>> > this.function1().chain(this.function2()); >>> > >>> > thats what chain is for, it wont execute function2 until function 1 >>> > has ended. at least is what I think, i dont really use chain much. >>> > >>> > On 26 abr, 18:38, mmjaeger <mmjae...@...> wrote: >>> > >>> > > Hello >>> > > Hope somebody can help - I'm struggling with chaining two functions >>> > >>> > > this is the code I got: >>> > >>> > > this.function1().chain( >>> > > function() { >>> > > this.function2(); >>> > > } >>> > > ); >>> > >>> > > function1 has an onComplete event - like this: >>> > >>> > > I put the following in there: >>> > >>> > > onComplete: function() { >>> > > this.callChain(); >>> > >>> > > } >>> > >>> > > function1 is basically a function to preload some image - when they >>> > > are loaded, I like to continue to execute function2. >>> > >>> > > Thank you in advance for your help. >>> > >>> > > What am I missing? >>> >>> >>> The MooTools Tutorial: www.mootorial.com Clientcide: www.clientcide.com >>> >>> View this message in context: Re: [Moo] Re: Struggling with chain >>> Sent from the MooTools Users mailing list archive at Nabble.com. >> > >
