is having to build constructs like this.
I need to load a bunch of templates up and then perform the rest of my actions. Event Driven programming frees you from excessively specifying order in code. Overdoing the Sequence bit in Sequence, Selection and Iteration. Except when you really need sequence, the code becomes messy. The sad part is this isn't even a great solution since it loads files one at a time. Ideally you wanna parallelize this.
If the problem is working with templates, then you need a better way of working with templates :D. jQuery, which you are using here, doesn't provide one. You know where I'm going with this.ReplyDelete
On a more serious note: A simple way to solve this problem would be make the second request only after the first one has completed. That way, you'd be guaranteed about the sequence. However, that's not what you are looking for.
What you need here is not to maintain execution order. What you want is a way to be notified when all your async operations are complete. There are some patterns to do this. For example, an interface for this would be an object to which you can add async operations, which would trigger a callback when all the async operations are complete. This should be trivial to implement in almost any framework, or even in pure JS.
yeah, I know what you mean. A single callback which maintains state and does something when all operations are completed. But then I'd either have to maintain state in some form or run through my template list and see what's loaded. Either way it's state maintenance and verification which is ugly in it's own way.ReplyDelete
Building the abstraction to hide it away is meaningless if its the only example in my code :/.
re jquery, Im using jqote since its based on John Resig's microtemplating thing. Btw, I was looking for you last week precisely because I wanted to talk about this barrier I was perceiving between adopting jquery or dojo in this little side project. (I'm building a better utorrent extension for chrome, the one that's out isn't very good.)
AFAIK, neither libraries solve this problem. Dojo one-ups jQuery by solving the single-event-multiple-handlers problem, which is far more common, but doesn't address your case. Your case is exactly the opposite, in fact - multiple-events-single-handler. Like I said, it shouldn't be hard to fix this with the pattern I provided.ReplyDelete
I didn't understand the bit where you said you'd have to "run through my template list and see what's loaded". I guess I'll catch you over chat for this?
sounds good. How long are you in Delhi?ReplyDelete