Ticket #2528236 (closed defect)

Reporter


Luke Smith
Opened: 09/9/09
Last modified: 09/29/09
Status: closed
Type: defect
Resolution: fixed

Owner


Adam Moore
Target Release: 3.0.0 GA
Priority: P3 (normal)
Summary: Y.on returns ineffective detach handle when subscriptions are defered
Description:

var handle = Y.on('click', fn, '#notOnThePageYet');
... time passes. The element is added to the page and the subscription is set up

handle.detach(); // does not detach the click handler

Y.on returns the "available" event handle I believe. This exposes two issues:
1) the returned handle is ineffective for the targeted subscription
2) Y.on('click', fn, '.many-elements') returns an array of handles if elements are present, but if deferral is triggered Y.on doesn't know how many would be captured if any at all, so what should be
returned?

Type: defect Observed in Version: development master
Component: Event Severity: S3 (normal)
Assigned To: Adam Moore Target Release: 3.0.0 GA
Location: Library Code Priority: P3 (normal)
Tags: Relates To:
Browsers: N/A
URL:
Test Information:

Attachments

Attachment #1: deferred_sub.html (download)

Change History

Luke Smith

YUI Contributor

Posted: 09/10/09

Perhaps rather than return an array of handles when multiple events are hooked up, a single object be returned with a detach method that iterates the array of handles stored in another property. This would allow the use of onAvailable in the Event and special event code to capture the handle returned from the deferred Y.on and modify the handle originally returned.

E.g. in the mouseenter code in the deferral for selector strings resulting in no elements
if (Lang.isString(el)) {
// Need to use Y.all because if el is a string it could be a
// selector that returns a NodeList
element = Y.all(el);

if (element.size() === 0) { // Not found, check using onAvailable
tmpHandle = Event.onAvailable(el, function() {
var newHandle = Y.on.apply(Y, args);
Y.mix(tmpHandle, newHandle); // replace detach handle object properties.
}, Event, true, false);

return tmpHandle;
}
}

This would allow a call to handle.detach() before the elements are found to cancel the pending subscription, but after the elements are found it would properly detach the subscriber(s).

Adam Moore

YUI Contributor

Posted: 09/10/09
  • milestone changed to 3.1.0
  • status changed from new to accepted

Adam Moore

YUI Contributor

Posted: 09/16/09
  • milestone changed from 3.1.0 to 3.0.0 GA

Adam Moore

YUI Contributor

Posted: 09/16/09
  • resolution changed to fixed
  • status changed from accepted to checkedin

all event listeners configured to return an event handle will always get a single object. Previously, requests that resulted in multiple listeners returned an array. onAvailable and lazy DOM listener detach handles now work as expected. [fixes #2528236]. [fixes #2528239].
View Commit: bc8660dcb747bedc141ca9061de83f6f32f8018f

Adam Moore

YUI Contributor

Posted: 09/16/09

all event listeners configured to return an event handle will always get a single object. Previously, requests that resulted in multiple listeners returned an array. onAvailable and lazy DOM listener detach handles now work as expected. [fixes #2528236]. [fixes #2528239].
View Commit: bc8660dcb747bedc141ca9061de83f6f32f8018f

George

YUI Developer

Posted: 09/29/09
  • status changed from checkedin to closed