This is a JavaScript library to manage ordered callback sets. The usage is simple, you push callbacks, define an order, and call the stack when you need. When you call the stack, the callbacks will be called in compliance with the order. It doesn't matters when you push the callbacks, as long as you define the order before calling the stack. This class is "chainable".
Installation with bower :
bower install djs-call-stack
// Create a new object
var cs = new djs.CallStack();
// Add a callback
cs.add('callback-1', function() {
console.log('Callback 1');
});
// Add another callback
cs.add('callback-2', function() {
console.log('Callback 2');
});
cs.order = ['callback-2', 'callback-1'];
The stack will execute callback-2
and the callback-1
.
cs.run();
cs.reverse().run();
cs.restore();
cs.delete('callback-1');
Then, it will execute only callback-2
.