Closed Bug 744514 Opened 12 years ago Closed 10 years ago

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

Categories

(Add-on SDK Graveyard :: General, defect, P2)

x86
macOS
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: glind, Unassigned)

References

()

Details

Attachments

(1 file, 1 obsolete file)

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 → --
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
Closed: 10 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: