Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24038] Ti.UI elements: Usage of on() in favour of addEventListener()

GitHub Issuen/a
TypeImprovement
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2016-10-16T16:34:35.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterCreative
AssigneeEric Merriman
Created2016-10-14T07:13:24.000+0000
Updated2017-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()).

Comments

  1. Sharif AbuDarda 2016-10-14

    Thanks for submitting the request. Our engineers will consider it.
  2. Hans Knöchel 2016-10-15

    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.
  3. Creative 2016-10-16

    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.
  4. Hans Knöchel 2016-10-16

    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.
  5. Hans Knöchel 2016-10-18

    Marking as Duplicate of TIMOB-18039 (thx [~uzbbert] and [~michael])
  6. Lee Morris 2017-03-21

    Closing ticket as duplicate with reference to the above comments and links.

JSON Source