0.0.2 • Published 5 years ago

postmessage-event-bus v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

postmessage-event-bus

event bus based on post message

Usage

Install

  1. npm i postmessage-event-bus and require it require('postmessage-event-bus')
  2. <script src="https://unpkg.com/postmessage-event-bus@0.0.1/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