Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cross-storeon

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cross-storeon

Module for storeon to sync state at different sources

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Cross Storeon

Storeon logo by Anton Lovchikov

Module for Storeon to synchronize actions through different ways with filtering of events that need to be synchronized.

It size is 131 bytes (minified and gzipped) and uses Size Limit to control size.

Installation

npm install cross-storeon
# or
yarn add cross-storeon

API

import crossstore from 'cross-storeon'

const crossTab = function ({ key, filter }) {
  var ignoreDate = 0
  var counter = 0

  return crossstore({
    key,
    filter,
    send: function (event) {
      ignoreDate = Date.now() + '' + counter++
      localStorage[key] = JSON.stringify([event, ignoreDate])
    },

    subscribe: function (cb) {
      window.addEventListener('storage', function (event) {
        if (event.key === key) {
          var tip = JSON.parse(event.newValue)

          if (ignoreDate !== tip[1]) {
            cb(tip[0])
          }
        }
      })
    }
  })
}

Function crossstore could have options:

  • key: key.
  • filter: callback function to filter actions to be synchronized. Should return true if need sync this action. Takes parameters of an event name and a data that is sent.
  • send: callback to send events to different stores
  • subscribe: callback to subscribe on events from different stores

LICENSE

MIT

FAQs

Package last updated on 29 Oct 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc