How async is async?
-
Working on a Knockout application after leaving it alone for a few days. I'm in the middle of a ticket, and now that I'm looking at it again, I don't see why the stateful part of my ViewModel is null.
I guess I see it now. There is an Ajax request in my code (and I see it hitting my server):
Sammy(function() { this.get('#clients', function() { self.app.state.init(); self.app.state.sidebar(_.findWhere(self.app.resource.sidebar.tabs, { name: 'Clients' } )); $.get('/api/its/clients', {}, self.app.state.clients); }); }).run();
where
self.app.state.init = function () { self.app.state.client.client(null); self.app.state.client.clients(null); self.app.state.client.trackingSheets(null); self.app.state.client.trackingSheet(null); }
So WTF, my JavaScript runtime is arbitrarily deciding to call the functions out of order? What are my options for DRY-ly initializing my state?
-
@captain said in How async is async?:
So WTF, my JavaScript runtime is arbitrarily deciding to call the functions out of order? What are my options for DRY-ly initializing my state?
I got hooked on async:
In particular, you probably want waterfall.
-
@boomzilla said in How async is async?:
@captain said in How async is async?:
So WTF, my JavaScript runtime is arbitrarily deciding to call the functions out of order? What are my options for DRY-ly initializing my state?
I got hooked on async:
In particular, you probably want waterfall.
That guy has something something eyes.
-
@captain I'm not sure what specific problem you are experiencing. What is null that shouldn't be and when?
From looking at the code, I'm not sure if mismatched
self.app.state.clients
andself.app.state.client.clients
is an anonymization error or intended?And from my past experience with Knockout… fair warning, it's pretty easy to build up an inefficient, unreadable, tangled mess of dependencies through computeds and subscriptions. (Not saying that's the case here yet.)
-
@dcoder Derp, the mismatch was the problem. My
clients
observable was null and I thought it was getting reset to null by my state initializer.
-
@captain That is why I love TypeScript ;) Such a mismatch gets flagged by both the IDE and by the TS→JS transpiler, so it never even reaches the browser.
-
@dcoder The framework I'm using has some support for TypeScript, so maybe I'll switch after the next feature release.
-
@tsaukpaetra said in How async is async?:
That guy has something something eyes.
"He's got Betty Davis eyes!" - MST3K
If you ever want a database of pale, pale white people, just do page-scrape of all the GitHub user images.