[ALOY-971] Alloy : Collection events triggered with trigger() method are firing twice
GitHub Issue | n/a |
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2015-01-14T22:06:31.000+0000 |
Affected Version/s | Alloy 1.3.1 |
Fix Version/s | n/a |
Components | n/a |
Labels | community |
Reporter | Noah Lively |
Assignee | Tony Lukasavage |
Created | 2014-03-19T17:17:05.000+0000 |
Updated | 2015-01-14T22:06:31.000+0000 |
Description
Using TI SDK GA 3.2.2 and iPhone Simulator...
I've bound a listener to "my event" on Alloy.Collections.instance('TestModel2'). When I call trigger('my event') once on the collection singleton the listener is fired twice.
See attached project file. Just build and run in the iPhone simulator to see the issue duplicated. You should see an alert fired twice when you click "Hello World"
Attachments
Looks like backbone splits my event on the space and considers "my" end "event" two separate events... When I change to "my_event" it works the way I wanted it to. I'm used to Titanium.Api.fireEvent() and Titanium.Api.addEventListener() accepting event names with spaces. Perhaps it should be added to the Alloy docs that backbone splits events on space.
As stated on http://docs.appcelerator.com/backbone/0.9.2/#Events-on "The event string may also be a space-delimited list of several events..." So you're right that Backbone (which underlies Alloy models/collections) is treating your "my event" as two events. Honestly, until seeing this ticket, it never occurred to me to name events with spaces. I'm surprised to learn that it actually works with Titanium events (in both Classic and Alloy styles). We'll investigate to see if this is something we can support without breaking existing apps that use space-delimited events currently.