This library is designed for Runnel. Please visit our documentation and learn more.
const { plugin, subscribe } = createPlugin(deepEqual);
const eventBus = createEventBus({
deepEqual,
payloadValidator,
pluginMap: new Map([[window, [metricPlugin]]]), // To observe the window. If the `scope` is smaller than the specified plugin scope, the specified plugin will not function.
});
...
// Example with React.useState
const [metrics, setMetrics] = useState();
subscribe(setMetrics);
-
topic1
with schema{ "type": "number" }
. - No subscribers.
- One publish event with payload
100
.
{
"topic1": {
"onCreatePublish": 1,
"publish": [100],
"onCreateSubscribe": 0,
"subscribe": [],
"schema": { "type": "number" }
}
}
-
topic2
with schema{ "type": "string" }
. - One subscriber.
- No publish events.
{
"topic2": {
"onCreatePublish": 0,
"publish": [],
"onCreateSubscribe": 1,
"subscribe": [],
"schema": { "type": "string" }
}
}