[TIMOB-24038] Ti.UI elements: Usage of on() in favour of addEventListener()
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Critical |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2016-10-16T16:34:35.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Creative |
Assignee | Eric Merriman |
Created | 2016-10-14T07:13:24.000+0000 |
Updated | 2017-03-21T23:13:49.000+0000 |
Description
I'd like to suggest the implementation of jQuery like event setters for Ti.UI.* elements, like:
on()
once()
off()
Versus the current functions:
addEventListener()
removeEventListener()
These functions would then apply on every *Ti.UI.xxx* element. This setup has currently already been implemented on controllers and it is imho cleaner and provides some better functionality (especially off()
and once()
).
Thanks for submitting the request. Our engineers will consider it.
In general, I like this idea. If would "only" rename it, there shouldn't be any trouble. We would also need to change the way Alloy works, update all unit-tests, update our new module templates, and deprecate the old way for at least one major version. So it *could* be considered for 6.1.0 / 6.2.0 and remove it in 7.0.0 / 8.0.0 or we allow them to live along with each other, since we only change the public API. But for the next releases, we want to primary focus on bug fixes, rather then introducing new features and behaviors, so we won't schedule it for a concrete version for now. Thanks! *EDIT*: And if we go with "on" and "off", we should also replace "fireEvent" with "emit", right? I made a proof-of-concept [here](https://github.com/appcelerator/titanium_mobile/compare/master...hansemannn:TIMOB-24038) that replaces the above mentioned methods on iOS and it works as expected. The same needs to be done for Android of course.
I guess you could even go with the backbone setup, see: http://backbonejs.org/#Events on(), once(), off(), trigger() ... One way to tackle this improvement is to search for all 'addEventListener' occurrences and determine whether it's worth it to replace it. In any case, the aim would be to create a uniform API for events (so it would make sense to go with the Backbone Dispatcher, since its already used within backbone). If all could work on the existing backbone dispatcher code then that would be awesome.
once()
would be a new feature that introduces a new behavior.emit()
is very known in the NodeJS area, so I used that for now. But as said before, we will put it on hold for now.Marking as Duplicate of TIMOB-18039 (thx [~uzbbert] and [~michael])
Closing ticket as duplicate with reference to the above comments and links.