šŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →
Socket
Sign inDemoInstall
Socket

storage-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

storage-emitter

Emit events between browser tabs

2.0.1
latest
Source
npm
Version published
Weekly downloads
1.9K
-33.6%
Maintainers
1
Weekly downloads
Ā 
Created
Source

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.onversionchange event 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-emitter

API

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

MIT

Keywords

storage

FAQs

Package last updated on 31 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts