Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm"); | ||
ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm"); | ||
|
||
const { EventManager } = ExtensionCommon; | ||
const { EventEmitter } = ExtensionUtils; | ||
|
||
class HelloEventEmitter extends EventEmitter { | ||
emitHelloEvent() { | ||
console.log("Emitting hello-event from HelloEventEmitter"); | ||
this.emit("hello-event"); | ||
} | ||
} | ||
|
||
this.hello = class extends ExtensionAPI { | ||
getAPI(context) { | ||
const helloEventEmitter = new HelloEventEmitter(); | ||
return { | ||
hello: { | ||
async hello() { | ||
helloEventEmitter.emitHelloEvent(); | ||
return "Hello, world!"; | ||
} | ||
} | ||
}, | ||
onSomething: new EventManager(context, "hello.onSomething", fire => { | ||
const callback = value => { | ||
console.log("Firing hello-event from hello experiments API"); | ||
fire.async(value); | ||
}; | ||
helloEventEmitter.on("hello-event", callback); | ||
return () => { | ||
helloEventEmitter.off("hello-event", callback); | ||
}; | ||
}).api() | ||
}; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,19 @@ | |
"async": true, | ||
"parameters": [] | ||
} | ||
], | ||
"events": [ | ||
{ | ||
"name": "onSomething", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
motin
Author
Owner
|
||
"description": "Description of the event", | ||
"parameters": [ | ||
{ | ||
"name": "param1", | ||
"description": "Description of the first callback parameter", | ||
"type": "number" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] |
The events need to have a "type" property set to "function" (e.g. as the browserAction.onClicked API schema is doing here: https://searchfox.org/mozilla-central/rev/f860c2bf00576959b07e2d9619c7b5088b0005be/browser/components/extensions/schemas/browser_action.json#451)