https://github.com/jeetiss/cross-storeon
  
  
     
    https://github.com/jeetiss/cross-storeon
  
        Last synced: 28 days ago 
        JSON representation
    
- Host: GitHub
- URL: https://github.com/jeetiss/cross-storeon
- Owner: jeetiss
- License: mit
- Created: 2019-10-22T20:39:09.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T12:38:21.000Z (almost 3 years ago)
- Last Synced: 2025-03-16T16:47:30.937Z (8 months ago)
- Language: JavaScript
- Size: 1.29 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 22
- 
            Metadata Files:
            - Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
 
Awesome Lists containing this project
README
          # Cross Storeon

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.
[Storeon]: https://github.com/storeon/storeon
[Size Limit]: https://github.com/ai/size-limit
## Installation
```
npm install cross-storeon
# or
yarn add cross-storeon
```
## API
```js
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