Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeetiss/cross-storeon
https://github.com/jeetiss/cross-storeon
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeetiss/cross-storeon
- Owner: jeetiss
- License: mit
- Created: 2019-10-22T20:39:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T12:38:21.000Z (almost 2 years ago)
- Last Synced: 2024-10-06T10:30:48.945Z (about 2 months ago)
- Language: JavaScript
- Size: 1.29 MB
- Stars: 3
- Watchers: 3
- 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 = 0return 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