The command pattern - using it on deferred objects in javascript
20 Mar 2015
Reading time: 1 minute
In the previous article we created some commands an ran them through the system.
In this article I will show how easy it is to make these events wait for each other to complete.
It really is a case of making each function take a callback.
First we will make the log event take a few moments by performing a jquery slidedown.
Importantly we have added a second arguement, callback.
Now just assing up the callbacks…
So what effect does this have on the calls? I have a warning, it looks really nasty!
As you can see in the callback example all the commands are run in sequence. This is important so that the state of the UI is predictable.
In a future post we will look at making the commands run by user interaction.