-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add ol.Observable.unByKey #2794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LGTM and +1 on deprecating |
@@ -99,5 +109,5 @@ ol.Observable.prototype.un = function(type, listener, opt_this) { | |||
* @api stable | |||
*/ | |||
ol.Observable.prototype.unByKey = function(key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function could be a simple alias:
ol.Observable.prototype.unByKey = ol.Observable.unByKey;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A @function
jsdoc tag is probably needed in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This indeed works! I keep forgetting about that annotation. I'm amending the commit. Thanks.
Looks good to me too. Hard to imagine 4.0 at this point, and it feels sloppy to have something deprecated immediately after 3.0. So I wouldn't be motivated to add anything to the docs (it would show up on almost every type), but that's a personal opinion. |
Agree with @tschaub. I'll add in the docs that using the static function rather than the method is encouraged. |
Thanks, please merge |
The ol.Observable.prototype.unByKey was supposed to handle removing of listeners registered using `ol.Observable.prototype.on` and `ol.Observable.prototype.once`. However, the underlying google library code called by unByKey only requires the key, not the `ol.Observable` object on which the registration was triggered. Moreover, this method was unconvenient and in practice misused. Example or real world code: ```javascript var map = new ol.Map(); var key = map.on(listener); view.unByKey(key); ``` A function was added in openlayers#2794, in particular to fix this kind of code. This PR pushes forward the removal process of the old method in favor of the unByKey function by marking it `@deprecated` and pointing to the right usage. Please merge when deemed appropriate.
The ol.Observable.prototype.unByKey was supposed to handle removing of listeners registered using `ol.Observable.prototype.on` and `ol.Observable.prototype.once`. However, the underlying google library code called by unByKey only requires the key, not the `ol.Observable` object on which the registration was triggered. Moreover, this method was unconvenient and in practice misused. Example or real world code: ```javascript var map = new ol.Map(); var key = map.on(listener); view.unByKey(key); ``` A function was added in openlayers#2794, in particular to fix this kind of code. This PR pushes forward the removal process of the old method in favor of the unByKey function by marking it `@deprecated` and pointing to the right usage. Please merge when deemed appropriate.
The ol.Observable.prototype.unByKey was supposed to handle removing of listeners registered using `ol.Observable.prototype.on` and `ol.Observable.prototype.once`. However, the underlying google library code called by unByKey only requires the key, not the `ol.Observable` object on which the registration was triggered. Moreover, this method was unconvenient and in practice misused. Example or real world code: ```javascript var map = new ol.Map(); var key = map.on(listener); view.unByKey(key); ``` A function was added in openlayers#2794, in particular to fix this kind of code. This PR pushes forward the removal process of the old method in favor of the unByKey function by marking it `@deprecated` and pointing to the right usage. Please merge when deemed appropriate.
Today we have
ol.Observable.prototype.unByKey
:So it is a method wrapping a static function. That means it could instead be static:
Having a static function (
ol.Observable.unByKey
) would be more convenient. Because when it is the time to unregister your listeners you may not have a reference to the object you registered your listeners on. You may even have an array of listener ids for listeners on multiple observables.Please review.
We could also consider
@deprecate
'ingol.Observable.prototype.unByKey
.