Last Comment Bug 744514 - observer-service, when observing "*", topic is unreliable (in callback)
: observer-service, when observing "*", topic is unreliable (in callback)
Status: RESOLVED INVALID
:
Product: Add-on SDK
Classification: Client Software
Component: General (show other bugs)
: unspecified
: x86 Mac OS X
: P2 normal (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
:
Mentors:
https://github.com/mozilla/addon-sdk/...
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-11 11:54 PDT by Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat )
Modified: 2014-02-09 09:45 PST (History)
4 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---


Attachments
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/592 (355 bytes, text/html)
2012-11-26 11:51 PST, Irakli Gozalishvili [:irakli] [:gozala] [@gozala]
rFobic: review+
Details
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/592#attch-to-bugzilla (409 bytes, text/html)
2012-11-26 11:51 PST, Irakli Gozalishvili [:irakli] [:gozala] [@gozala]
rFobic: review+
Details

Description Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ) 2012-04-11 11:54:47 PDT
When 

   observer.add("*",somecallback);

the `Observer` will have '*' as its topic.  The callback can't see what the true topic was.

I am not sure that there is a good way around this, other than allowing a 4th argument to `callback`, which is filled with the true topic.  Drawback: this would be inconsistent with the previous MDN usage/idiom.

At the very least, it deserves a warning in the docs.  

Code:

    var log_it = function (subject,data){console.log("OBSERVED",subject,data,"TOPIC:", this.topic)};
    observer.add("*",log_it);
Comment 1 Wes Kocher (:KWierso) 2012-04-12 11:19:14 PDT
At this point, we'd rather just document this quirk.
Comment 2 Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ) 2012-04-12 11:55:41 PDT
That's fair.  I saw no obvious way to get it onto the object that goes into the callback, unless the object gets proxycopied or something on the way in, with an added ".thistopic".  

It's a bit annoying, and removes a lot of the usefulness of "*", but that's life!
Comment 3 Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ) 2012-05-30 13:02:24 PDT
This seems to be broken under the recent revisions/simplifications to `observer-server.js`.

Suggestions might be...

1)  link to the xpcom docs, which could listen to "*"
2)  emit to "*" and always listen on it?

Messy version illustrating examples:  https://gist.github.com/2838598
Comment 4 Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ) 2012-09-28 14:30:54 PDT
Reopening.  On Android, lots of functionality is done over the observer bus.  In particular, I want to handle *every kind of message* in one way or another, *and know* when a new type of message appears, as part of UX observation of the interface.

Add a fourth argument of the actual topic helps tremendously.  

See:  https://github.com/mozilla/addon-sdk/pull/592

(This needs a bit of doc update and testing.  It should be fully backward compatible.)
Comment 5 Wes Kocher (:KWierso) 2012-09-28 14:50:37 PDT
CCing Irakli since he's all over observer-service's history.
Comment 6 Irakli Gozalishvili [:irakli] [:gozala] [@gozala] 2012-11-26 11:51:15 PST
Created attachment 685272 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/592

Pointer to Github pull-request
Comment 7 Irakli Gozalishvili [:irakli] [:gozala] [@gozala] 2012-11-26 11:51:26 PST
Created attachment 685273 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/592#attch-to-bugzilla

Pointer to Github pull-request
Comment 8 Erik Vold [:erikvold] (please needinfo? me) 2014-02-09 09:45:59 PST
The observer-service was removed in bug 958908 system/events should be used instead now, which supports '*' as Irakli noted here https://github.com/mozilla/addon-sdk/pull/592#issuecomment-11359722

Note You need to log in before you can comment on or make changes to this bug.