Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-536] Firing custom events with data that includes a view causes listener to not listen

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionDuplicate
Resolution Date2011-04-15T02:31:21.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labels1.0, callback, custom, event
ReporterNoah
AssigneeReggie Seagraves
Created2011-04-15T02:31:20.000+0000
Updated2017-03-09T21:20:40.000+0000

Description

Using SDK1.0


This Works:

Titanium.App.addEventListener('customEvent', function(e) {
  Ti.API.debug("FIRED!");
});
Titanium.App.fireEvent('customEvent', {foo:'bar'});

But, this does not work. Event appears to fire (in console), but callback is never executed:

var tableView = Titanium.UI.createTableView();
Titanium.UI.currentWindow.add(tableView);

Titanium.App.addEventListener('customEvent', function(e) {
  Ti.API.debug("FIRED!"); // never executed
});
Titanium.App.fireEvent('customEvent', {foo:tableView});

This also does not work, but perhaps is not expected to work. Event is never fired:

var tableView = Titanium.UI.createTableView();
Titanium.UI.currentWindow.add(tableView);

tableView.addEventListener('customEvent', function() {
  Ti.API.debug("FIRED!"); // never executed
});
tableView.fireEvent('customEvent'); // never fires (according to console)

Comments

  1. Noah 2011-04-15

    The documentation does in fact state that the event data must be JSON serializeable. That is not true in the second case, which is consistant with the documentation.

    The third example however is expected to work based on the documentation that says it does. See Ticket #581.

  2. hal 2011-04-15

    Maybe I'm missing something, but why should example 3 work?
    Surely the line

       tableView.fireEvent('customEvent');
       

    should be

       Ti.App.fireEvent('customEvent');
       

    put inside a

       tableView.addEventListener ?
       
  3. hal 2011-04-15

    Noah
    I take your point that the functionality is indeed in the docs, so my suggestion could be used as an alternative if anyone is having issues with implementing example 3. However, I am still not clear about the advantages of example 3. Is it just the tearing down that's mentioned in #581 ?

  4. hal 2011-04-15

    For the reason why example 2 doesn't work, see this http://developer.appcelerator.com/question/1221/passing-callback-with-fireevent"> Q&A

    Therefore, I think this ticket is just a duplication of #581. I propose that it be closed.

  5. Stephen Tramer 2011-04-15

    Dupe of #581.

  6. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source