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

@storeon/crosstab

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storeon/crosstab

Module for storeon to sync state at different tabs of the browser

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51
decreased by-17.74%
Maintainers
2
Weekly downloads
 
Created
Source

Storeon Crosstab

Storeon logo by Anton Lovchikov

Module for Storeon to synchronize actions for browser tabs with filtering of events that need to be synchronized.

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

Example

Example

Installation

npm install @storeon/crosstab
# or
yarn add @storeon/crosstab

Usage

If you want sync state between tabs of the browser you should import the crossTab from @storeon/crosstab and add this module to createStore.

import { createStoreon } from 'storeon'
import { persistState } from '@storeon/localstorage'
import { crossTab } from '@storeon/crosstab'

const increment = store => {
  store.on('@init', () => ({ count: 0, openMenu: false }))
  store.on('inc', ({ count }) => ({ count: count + 1 }))
  store.on('toggleMenu', ({ openMenu }) => ({ openMenu: !openMenu }))
}

const store = createStoreon([
  increment,
  persistState(),
  crossTab({ filter: (event, data) => event !== 'toggleMenu' })
])

store.on('@changed', (store) => {
  document.querySelector('.counter').innerText = store.count
})

API

import crossTab from '@storeon/crosstab'

const moduleCrossTab = crossTab({
  filter: (event, data) => event !== 'dec',
  key: 'storeon-crosstab'
})

Function crossTab could have options:

  • key: key for sync data in local storage.
  • 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.

Server-side rendering

@storeon/crosstab is not compatible with server-side rendering since it require window to operate. You can exclude it during server-side render process.

const store = createStoreon([
  increment,
  ...typeof window !== 'undefined' ? [
    crossTab({ filter: (event, data) => event !== 'toggleMenu' })
  ] : []
])

Sponsor

Sponsored by Evrone

LICENSE

MIT

FAQs

Package last updated on 04 Jun 2020

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