wowjoy-cis-events

1.0.4 • Public • Published

The Custom Event Dispatcher provides the ability to communicate inside your application by dispatching events and listening to them.

Install

npm

npm install --save wowjoy-cis-events

yarn

yarn add  --save wowjoy-cis-events

example

import { CustomEvent } from "wowjoy-cis-events";


CustomEvent.on("SHOW_NAME", (data) => {
	console.log(data.detail);
});


CustomEvent.dispatch("SHOW_NAME", { name: "wowjoy" });


// Remove event listener
CustomEvent.off("SHOW_NAME");

iframe postmessage 通信方案

import { pmEventUtil } from "wowjoy-cis-events";

new pmEventUtil().send("myChannel", data, function (err) {
    // console.log(err)
});
new pmEventUtil().listen("myChannel", function (data) {
    console.log(data);
});

对于跨 tab 页面通信 建议使用 broadcast-channel,详细见说明文档

Event Bus 事件总线

import { E } from "wowjoy-cis-events";

E.on("my.bus.event", callback);

Emitting a bus event

E.emit("my.bus.event");


// you can also pass arguments through
E.emit("my.bus.event", arg1, arg2);

移除事件

E.off("my.bus.event", callback);

E.off("my.bus.event");

/wowjoy-cis-events/

    Package Sidebar

    Install

    npm i wowjoy-cis-events

    Weekly Downloads

    0

    Version

    1.0.4

    License

    MIT

    Unpacked Size

    22.4 kB

    Total Files

    10

    Last publish

    Collaborators

    • wujianing