Skip to content

A module to transmit DOM-based events setup and responses between a worker and the main (UI) threads across the message channel.

Notifications You must be signed in to change notification settings

bloodyKnuckles/worker-event-bridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

worker-event-bridge

main (UI) thread usage

var eventBridgeMain = require('worker-event-bridge/main')

var worker = new Worker('./worker.js')
eventBridgeMain(worker)

worker thread usage

var eventBridgeWorker = require('worker-event-bridge/worker')

eventBridgeWorker('select', 'change', function (val) {
  console.log(val) // reports selected value
})

A Cycle.js implementation example.

use in existing message channels

main.js

var eventBridgeMain = require('worker-event-bridge/main')

var worker = new Worker('./worker.js')
worker.addEventListener('message', function (evt) {
  evt.data.forEach(function (data) {
    if ( 'event' === data.cmd ) {
      eventBridgeMain.addListener(worker, data.event)
    }
  })
}, false)

worker.js

var eventBridgeWorker = require('worker-event-bridge/worker')

eventBridgeWorker.send('select', 'change')

self.addEventListener('message', function (evt) {
  eventBridge.receive(evt, 'select', 'change', function (val) {
    console.log(val)
  })
}, false)

license

MIT

About

A module to transmit DOM-based events setup and responses between a worker and the main (UI) threads across the message channel.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published