[Project_owners] How to pass custom JS XPCOM component to observers?

Nickolay Ponomarev asqueella at gmail.com
Mon Jan 15 15:30:30 PST 2007


On 1/16/07, Eric H. Jung <eric.jung at yahoo.com> 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
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>
>


More information about the Project_owners mailing list