| Page 1 of 1 | [ 4 posts ] |
|
Hi,
Im having a design problem when using bubbling library to install listeners. First I will provide my perspective of the bubbling library, then my usecase and my design solution. The problem is the solution as you will see involve moving away from the bubbling library. I want to have that as a last resort. So I will be happy if you could help me redesign my usecase so that i can use the bubbling library. 1. Perspective of Bubbling library (When your view about something is wrong, the solution is wrong 100 % ) 1. The YUI Bubbling library installs listeners only to the Body element of the document. Disadvantages, consider, <div class="list"> <input type="button" class="AsyncRequestTrigger"> </div> <div class="editable list"> <input type="button" class="AsyncRequestTrigger"> </div> The problem(usecase) is i want to handle the AsyncRequestTrigger in the two divs differently. One Solution is checking for an ancestor(of the target) with a particular class - this is not an elegant solution. Not elegant because it becomes the responsibility of the element to check whether it is the actual trigger or not. So my solution is to consider each of the div as a separate behavior layer(there by it has listeners attached to it). So that each class under a different behavior layer can behave differently. Question 1). Is it possible using the bubbling library? Question 2). If so can you design it out for me? Many regards, Jiraaya - "To heaven be the glory" |
|
Hello Jiraaya,
You're right, Bubbling set the listeners are the top level in the DOM (document), and this feature is not configurable. About the responsibility inconsistency, the idea in the first place was to provide some mechanism to analyze the contextual meaning of the actions. Specifically the target and the ancestor path, to identify the meaning of the clicks. That said, I agree with you somehow, and from my point of view, this is something that was addressed with the new "delegate" feature for YUI 3.x and YUI 2.8.0. Here is an example: Y.on('delegate', handleClick, '.list', 'click', 'input.AsyncRequestTrigger'); But even this solution, can fail if those containers (.list) will be modified/injected dynamically by another component in the page, in which case you will have to use a more generic delegation process: Y.on('delegate', handleClick, 'document', 'click', '.list input.AsyncRequestTrigger'); in this case, this is exactly the feature that you get with the current bubbling implementation. And you will have to analyze the ancestor path as well, to localize the "list" element, to start the loading process based on that node. This new feature was released today as part of the new 2.8.0 release, so you can use it directly in 2.x. P.S. sorry for the delayed answer... Best Regards, Caridy |
|
@ Caridy
Thank you for the much needed information. Unfortunately, due to life cycle constraints, I had to extend your bubbling library to provide support for multiple behavior layers. Will take consider your solution of using delegate the next prototype comes up. Thank you once again PS: Late knowledge is still knowledge |
|
Hello Jiraaya,
You can combine delegate with YUI if you want. Or you can set the listeners manually for the containers and rely on bubbling to analyze the target and trigger the actions. These are the methods that you will probably need: YAHOO.Bubbling.getAllActions(targetElement, { 'AsyncRequestTrigger': function () { }, 'AsyncRequestTriggerMoreActions': function () { } }); it will return an array with the actions that match the target or its ancestors. Also "getActionName" if you want to get the first to match only. And finally this one: YAHOO.Bubbling.processingAction('click', { event: myEvent, input: MyInputTarget // can be also: anchor: MyAnchorTarget, etc }, { 'AsyncRequestTrigger': function () { }, 'AsyncRequestTriggerMoreActions': function () { } }); In this case, bubbling will match the target, the event and the list of actions that you send. And those actions are not global, are only available for the current execution process. Best Regards, Caridy |
| 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 |
© 2006-2013 Yahoo! Inc. All rights reserved.
All code on this site is licensed under the BSD License unless stated otherwise.
About This Site · Security Contact Info
Powered by phpBB® Forum Software © phpBB Group