Sample code of Chain in Official Doc not working?

37 views
Skip to first unread message

Chris Jiang

unread,
Apr 21, 2012, 12:53:45 PM4/21/12
to mootool...@googlegroups.com
Hi guys, basically, I'm trying to implement an standalone chain controller to my project, but the official sample code seems not working, and I can't find why. How should I create a set of functions to be executed one after each? @@"
    var Todo = new Class({
        Implements: Chain,
        initialize: function(){
            this.chain.apply(this, arguments);
        }
    });
 
    var myTodoList = new Todo(
        function(){ alert('get groceries'); },
        function(){ alert('go workout'); },
        function(){ alert('code mootools documentation until eyes close involuntarily'); },
        function(){ alert('sleep'); }
    );

Arian Stolwijk

unread,
Apr 21, 2012, 1:02:37 PM4/21/12
to mootool...@googlegroups.com
You could of course use .callChain()

Rob Johnson

unread,
Apr 21, 2012, 1:19:46 PM4/21/12
to mootool...@googlegroups.com
I normally do something like this:

new Chain().chain(
    function(){ alert('get groceries'); this.callChain(); },
    function(){ alert('go workout'); this.callChain(); },
    function(){ alert('code mootools...'); this.callChain(); },
    function(){ alert('sleep'); this.callChain(); }
).callChain();

http://jsfiddle.net/D5reU/


hamburger

unread,
Apr 23, 2012, 7:17:00 AM4/23/12
to MooTools Users
We still had this here:
it starts immediately.

var Todo = new Class({
Implements: Chain,
initialize: function() {
this.chain.apply(this, arguments);
this.callChain();
}
});

var myTodoList = new Todo(
function() {...
alert('get groceries');
this.callChain.delay(500, this);
}, function() {
alert('go workout');
this.callChain.delay(3000, this);
}, function() {
alert('code mootools...');
this.callChain.delay(500, this);
}, function() {
alert('sleep')
}
);

cheers hamburger

Chris Jiang

unread,
May 3, 2012, 3:49:18 AM5/3/12
to mootool...@googlegroups.com
Thank you all for replying. I've solved this and found it's a logic problem I got confused with how it works. Cheers!
Reply all
Reply to author
Forward
0 new messages