Re: [jetpack] Passing an object to an observer

42 views
Skip to first unread message

Jeff Griffiths

unread,
Jul 28, 2012, 11:17:45 AM7/28/12
to mozilla-la...@googlegroups.com
This is because the observer service implementation included with the
SDK only takes a function as a callback - this is different ( simpler?
) from how observers work in lower-level code. The documentation is
here:

https://addons.mozilla.org/en-US/developers/docs/sdk/1.8/packages/api-utils/observer-service.html

cheers, Jeff

On Fri, Jul 27, 2012 at 9:17 PM, Yansky . <thego...@gmail.com> wrote:
> Hi, I seem to be encountering an error when I try to pass an object rather
> than a function callback to an observer. I'm not sure if it's a problem with
> my code or a bug with the SDK.
> My code:
>
> var observers = require("observer-service");
> var ob;
> exports.main = function() {
> ob = {
> observe:function(subject,data){
> console.log('document-element-inserted')
> }
> };
> observers.add('document-element-inserted', ob);
> };
> exports.onUnload = function (reason) {
> observers.remove('document-element-inserted', ob);
> };
>
> The error message I get is:
> error: An exception occurred.
> Traceback (most recent call last):
> File
> "resource://jid1-nmj9rnjh73jn8g-at-jetpack/api-utils/lib/system/events.js",
> line 58, in
> data: data
> File
> "resource://jid1-nmj9rnjh73jn8g-at-jetpack/api-utils/lib/observer-service.js",
> line 35, in listener
> callback.call(target || callback, subject, data);
> TypeError: callback.call is not a function
>
> I'm using version 1.8.1 of the SDK with Firefox Aurora 16.0a2 on OSX 10.7.4
>
> --
> You received this message because you are subscribed to the Google Groups
> "mozilla-labs-jetpack" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/mozilla-labs-jetpack/-/WgHOA-gEVHUJ.
> To post to this group, send email to mozilla-la...@googlegroups.com.
> To unsubscribe from this group, send email to
> mozilla-labs-jet...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mozilla-labs-jetpack?hl=en.

ZER0

unread,
Jul 28, 2012, 11:46:32 AM7/28/12
to mozilla-la...@googlegroups.com
On Sat Jul 28 17:17:45 2012, Jeff Griffiths wrote:

> This is because the observer service implementation included with the
> SDK only takes a function as a callback - this is different ( simpler?
> ) from how observers work in lower-level code. The documentation is
> here:
>
> https://addons.mozilla.org/en-US/developers/docs/sdk/1.8/packages/api-utils/observer-service.html

Actually not, Jeff. In accordance with the docs we supports both
functions and objects:

https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/api-utils/observer-service.html#add%28topic%2C_callback%2C_thisObject%29

I think we introduced that regression during one refactoring around
events, I think Irakli worked on it probably he knows better if it's a
bug/regression or if we removed that functionality without updates the
docs.

Jeff Griffiths

unread,
Jul 28, 2012, 12:37:25 PM7/28/12
to mozilla-la...@googlegroups.com
Ah, you're right! I didn't read the fine print in the docs. Can you
log a bug for this issue then?

Jeff
> --
> You received this message because you are subscribed to the Google Groups "mozilla-labs-jetpack" group.

ZER0

unread,
Jul 28, 2012, 3:57:07 PM7/28/12
to mozilla-la...@googlegroups.com
On Sat Jul 28 18:37:25 2012, Jeff Griffiths wrote:

> Ah, you're right! I didn't read the fine print in the docs. Can you
> log a bug for this issue then?

Sure!
Here the bug: https://bugzilla.mozilla.org/show_bug.cgi?id=778479

Reply all
Reply to author
Forward
0 new messages