observer-service, when observing "*", topic is unreliable (in callback)

RESOLVED INVALID

Status

Add-on SDK
General
P2
normal
RESOLVED INVALID
5 years ago
4 years ago

People

(Reporter: Gregg Lind (Fx Strategy and Insights - Shield - Heartbeat ), Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(URL)

Attachments

(1 attachment, 1 obsolete attachment)

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);
At this point, we'd rather just document this quirk.
Component: General → Documentation
Priority: -- → P2
QA Contact: general → documentation
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!
Assignee: nobody → wbamberg
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
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.)
Assignee: wbamberg → nobody
Component: Documentation → General
CCing Irakli since he's all over observer-service's history.
Priority: P2 → --

Updated

5 years ago
Priority: -- → P2
Created attachment 685272 [details]
Pointer to Github pull request: https://github.com/mozilla/addon-sdk/pull/592

Pointer to Github pull-request
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
Attachment #685272 - Flags: review+
Attachment #685273 - Flags: review+
Attachment #685273 - Attachment is obsolete: true
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
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.