English
Event
About 164 wordsLess than 1 minute
2025-11-24
An EventBus-like utility for communication within plugins. It is shared by all plugins and remains alive during the host lifecycle.
Method Description
| Aspect | Description | Definition |
|---|---|---|
| onEvent | Listen to an event | onEvent=>(eventName, fn){} |
| emitEvent | Emit an event | emitEvent=>(eventName, opt){} |
| hasEvent | Check whether an event is being listened to | hasEvent=>(eventName){} |
| findOffEvent | Remove a specified listener | findOffEvent=>(eventName, predicate){} |
Code Example
onEvent
{
event: "form.render.end",
functional: function (pluginExecResult, options) {
console.log("custom plugin: form.render.end exec");
let {bizApi}=options;
let listener= (opt)=>{
console.log("customEvent::", opt);
}
// Listen to event
bizApi.onEvent("customEvent", listener);
// Check whether the event is being listened to
console.log("hasEvent::",bizApi.hasEvent("customEvent"));//expect out: hasEvent:: true
// Emit event
bizApi.emitEvent("customEvent",{test:"test 1"})//expect out: customEvent::{test:"test 1"}
// Remove the specified listener
bizApi.findOffEvent("customEvent", lis=>lis===listener);
// Emit the event again
bizApi.emitEvent("customEvent",{test:"test 2"})//expect out: nothing
}
}Notes
- Communication is only available within the lifecycle of the current create/edit page
