1.0.4 • Published 2 years ago

wowjoy-cis-events v1.0.4

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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");
1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago