postmessage-event-bus
v0.0.2
Published
event bus based on post message
Downloads
4
Readme
postmessage-event-bus
event bus based on post message
Usage
Install
npm i postmessage-event-bus
and require itrequire('postmessage-event-bus')
<script src="https://unpkg.com/[email protected]/eventBus.min.js"></script>
API
CreatePostMessageEventBus({
success: function () {
console.log('registry successed')
},
receive: function (data) {
console.log('receive post message data,data.name is message type', data, data.name)
},
request: function (cmd) {
console.log('other window need u send some event. cmd is the message type', cmd)
this.send({
name: 'change', // message type
sum: 100 // value
... // other values
})
},
on: ['increase', 'decrease'], // events that u wanna listen
emit: ['change'] // events that u will dispatch
})
Demo
https://zeyongtsai.github.io/postmessage-event-bus/root.html