chrome-ext-mst-sync
v0.0.19
Published
Allows easy syncing of mobx state tree stores between Chrome extension pages.
Downloads
5
Readme
Overview
chrome-ext-mst-sync
is a library that allows you to easily sync mobx-state-tree
stores across the various Chrome extension pages(background, browser action, and content scripts).
The idea is that you have one store(in the background script) as your source of truth and any actions used on that store are synced to the listeners. However, the stores that act as listeners as used as regular MST stores.
Usage
Background script:
const { createStoreSync } = require('chrome-ext-mst-sync')
const storeId = 'mystore'
const store = MyStore.create()
const storeSync = createStoreSync(storeId, store, {
truthStore: true
})
// start listening
storeSync.start()
Browser action script:
const { createStoreSync, getStore } = require('chrome-ext-mst-sync')
const snapshot = await getStore(storeId)
const store = MyStore.create(snapshot)
const storeSync = createStoreSync(storeId, store, {
truthStore: false
})
// start listening
storeSync.start()
// Now we can use the store as usual and all actions will be run in the background script and synced back here
store.doSometing()