0.0.0 • Published 8 years ago
@gorangajic/storage-emitter v0.0.0
storage-emitter
Emit events between browser tabs.
It's a small wrapper around
window.onstorage event,
which is a part of WebStorage specification and available in IE8+ browsers.
It works like a regular instance of EventEmitter, with the only difference that event is fired in all open tabs for same domain.
Possible applications:
- perform logout in all open tabs
- sync in-memory objects between browser tabs, like swarm.js
- polyfill
indexeddb.onversionchangeevent in Safari
Example
import sEmitter from 'storage-emitter'
// listen to "logout" event
sEmitter.on('logout', () =>
location.reload()
})
// call "logout" from another tab
sEmitter.emit('logout')Installation
$ yarn add storage-emitter
$ npm i -S storage-emitterAPI
sEmitter.on(event, callback)
Subscribe on event across all open application instances.
sEmitter.emit(event, args)
Emit event with args to all open tabs.
sEmitter.off(event)
Unsubscribe from all events or one specific event.
License
0.0.0
8 years ago