27min screen cast.
Perhaps more interesting is the visualisation tool that can help you to unpick the relationships between objects.
27min screen cast.
Perhaps more interesting is the visualisation tool that can help you to unpick the relationships between objects.
Or:
Goldilocks and the three vars
While it’s easy to watch for attribute changes of elements in Chrome (no, really, look it up), I’ve often wanted to the same for arbitrary objects in my code.
Well, now, this here gentleman just here says that ain’t no problem.
Good for him!
http://johnkpaul.com/blog/2013/07/20/break-on-property-change/
If you are getting this dialog:
“The last time you opened OpenOffice.org it unexpectedly quit while reopening windows. Do you want to try to reopen it’s windows again?
If you choose not to reopen windows, you may have to open and position the windows yourself.
[Don’t Reopen] [Reopen]”
And the buttons fail to respond, simply delete the folder
~/Library/Saved Application State/org.openoffice.script.savedState
Just a quick note – I’d like to write it up properly, but spent enough time fixing this I can’t afford to write a long post – despite the fact it’s those long fixes that most deserve it.
I was trying to chain multiple jquery promises, and it just wasn’t quite working – what I was doing was something like this:
I have three asynchronous functions, but one of them is dependant on the result of another, and when all have completed I need to do something else.
So, I ran a when, with arguments that were functions which called the asynch functions and returned deferred (promise) objects. When the asynchs completed a callback would declare the promises complete.
Seemed to make sense.
Note that these functions are members of an object (not shown)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
me.prototype.init = function( context ) { $.when( //Asynch data loads - these must all complete before moving on. self.one(), self.two() ).done(function(){ //do stuff }): }); me.prototype.onePointOne = function(){ var self = this, defer = $.Deferred(); this.someAsyncFunctionOne( { callback:function( ){ defer.resolve(); }}); return defer.promise(); }; me.prototype.one = function(){ var self = this, defer = $.Deferred(); $.when( self.onePointOne() ).done(function(){ this.someAsyncFunctionTwo( { callback:function( ){ defer.resolve(); }}); return defer.promise(); }); }; me.prototype.two = function(){ var self = this, defer = $.Deferred(); this.someAsyncFunctionThree( { callback:function( ){ defer.resolve(); }}); return defer.promise(); }; |
Well of course it seemed to make sense, based on what I’d seen in the documentation, but it didn’t work.
Eventually based on an approach seen in this SO answer by Niko, I found a working method was to assign deferred objects to variables, and watch those in with(), calling my functions seperately.
Looks a lot clunkier, but it worked:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
me.prototype.init = function( context ) { var self = this; // Deferred objects named for the functions they monitor // All are members of a self.deferred object, for tidiness // and to distinguish from functions with same name self.deferred.one = $.Deferred(); self.deferred.onePointOne = $.Deferred(); self.deferred.two = $.Deferred(); // Watch these deferred objects $.when( //Asynch data loads - these must all complete before continuing self.deferred.one, self.deferred.two ).done(function(){ //Do something }); // Call the first-level functions self.gettingHsbcInsights(); self.onePointOne(); self.two(); }); me.prototype.onePointOne = function(){ var self = this; this.someAsyncFunctionOne( { callback:function(){ // On async complete, declare this promise resolved self.deferred.onePointOne.resolve(); }}); // Make deferred object a promise self.deferred.onePointOne.promise(); }; me.prototype.one = function(){ var self = this; // Watch deferred object this function is // dependant on $.when( self.deferred.onePointOne ).done(function(){ // When onePointOne() declare complete, // run another async function model.someAsyncFunctionTwo( { callback:function(){ // On async complete, declare this promise resolved self.deferred.one.resolve(); }); }}); // Make deferred object a promise return self.deferred.one.promise(); }); // Call onePointOne(); self.onePointOne(); }; me.prototype.two = function(){ var self = this; this.someAsyncFunctionTwo( { callback:function(){ // On async complete, declare this promise resolved self.deferred.two.resolve(); }}); // Make deferred object a promise self.deferred.two.promise(); }; |
The odd thing about this pattern is that the ‘action’ of each function comes at the end – a little counterintuitive at first!