On 1/16/07, Eric H. Jung <[EMAIL PROTECTED]> wrote:
>
> Hi,
> I use the following code to notify observers of custom events. I can pass
> native types like booleans and strings to observers using nsISsupports***
> wrappers, but how can I pass an instance of my own JS XPCOM component
> (non-service) to observers?
>
> var gObsSvc =
> CC["@mozilla.org/observer-service;1"].getService(CI.nsIObserverService);
> gBroadcast = function(subj, topic, data) {
>   var bool =
> CC["@mozilla.org/supports-PRBool;1"].createInstance(CI.nsISupportsPRBool);
>   bool.data = subj;
>   var d;
>   if (typeof(data) == "string") {
>     var  d =
> CC["@mozilla.org/supports-string;1"].createInstance(CI.nsISupportsString);
>       d.data = data;
>     }
>     else {
>       // d is an instance of my custom JS XPCOM component. How to wrap it?
>     }
>     gObsSvc.notifyObservers(bool, topic, d);
> };
>
> // code which calls the above:
> gBroadcast(true, "my-custom-event1", "foobar");
> gBroadcast(false, "my-custom-event2", myCustomJSXPCOMobject);
>
Why are you passing components as a string data parameter?

You can pass the component as an nsISupports parameter ("subject") easily.

Nickolay


>
> Thanks for any suggestions,
> Eric
>
> _______________________________________________
> Project_owners mailing list
> [email protected]
> http://mozdev.org/mailman/listinfo/project_owners
>
>
>
_______________________________________________
Project_owners mailing list
[email protected]
http://mozdev.org/mailman/listinfo/project_owners

Reply via email to