| Page 1 of 1 | [ 4 posts ] |
Daniel Cook
|
I am using the IO module as suggested in the documentation and I am passing through a few arguments. The problem lies in the fact that if I rerun this code a few times, I am subscribing multiple times to the 'io:complete' event with different arguments. The solution I came up with was to store the subscription in a variable and then, later, detach but that is rather cumbersome. Any ideas?
-dcunited
Code: var eventSubscription; function sendData(callback){ eventSubscription = Y.on('io:complete', handleResponse , this, {callback: callback} ); var request = Y.io('somesite.com'); } function handleResponse(trans, response, args){ eventSubscription.detach(); args.callback(); } sendData(function(){ alert('first'); }); sendData(function(){ alert('second'); }); |
|
You don't have to listen globally, the examples on the IO landing page just don't show the transactional event listeners.
This example shows both: http://developer.yahoo.com/yui/3/exampl ... o-get.html In your case you want to listen on each transaction and not globally. |
Daniel Cook
|
Thanks Dav.
|
|
davglass wrote: In your case you want to listen on each transaction and not globally. The idea is still nice though. I was just checking the API for something like a Y.once() a few days ago while refactoring some jQuery code that was using their one() method to execute some code just once after a particular ajax call had run (sort of like an onready for an iframe, but for a div with dynamic content). Wasn't much to work around it of course, but it would be a nice shortcut for sure, especially with quick anonymous functions. Didn't find a ticket for something like this, so I created ticket 2528618 Update: This is coming in YUI 3.1.0 (see ticket for details) |
| Page 1 of 1 | [ 4 posts ] |
| You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum |
© YUI Library - Site Credits
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group