0.12.7 • Published 5 years ago

akingo-redux-sync v0.12.7

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

js-standard-style

redux sync

A store enhancer for Redux which allows to mirror one store as a part of another and keeps them in sync.

About

Although one of the core principles of Redux is referring to a single source of truth, depending on the application its not always possible. Environments like iframes or Web Worker can't share code directly as they are running in a different context. While its possible to use just one store and pass each data manually, another approach is to run these stores separate and automatically synchronize data changes. This allows to access the data at a single store and invoke changes across scope boundaries (e.g. triggering an action which changes the values outside will also transfer the value into the iframe store).

Usage

Install

npm install --save redux-sync

General setup

1.) Configure the redux store which should be synchronized

import syncStore from 'redux-sync'

// optional
const middlewares = [
  thunkMiddleware,
  loggerMiddleware
]

const finalCreateStore = compose(
  applyMiddleware(...middlewares),
  syncStore()
)(createStore)

const store = finalCreateStore(reducer, initialState)

2.) Configure the redux store which should should contain the synchronized store

import syncStore from 'redux-sync'

// optional
const middlewares = [
  thunkMiddleware,
  loggerMiddleware
]

const finalCreateStore = compose(
  applyMiddleware(...middlewares),
  syncStore('subtree')
)(createStore)

const store = finalCreateStore(reducer, initialState)

FAQ

Copying data from one store to another sounds like redundant data management...

No question it is, but regarding the aspect that this module is meant to ease the state management between different context it provides the advantages of completeness and performance.

Why not using redux persist ?

Indeed using a layer in between which can be accessed from both could be used, but the focus is actual not on persistence (you could still do it if you like) but on communication and optimized synchronization of substates.

TODO

  • add example
  • checkout more lightweight alternatives (current total ~ 39kb), e.g. for patching
  • support include/exclude filter options
  • integrate webworker and websocket adapter

Development

To build your own version run npm run dev for development (incl. watch) or npm run build for production (minified).

0.12.7

5 years ago

0.12.6

5 years ago

0.12.5

5 years ago

0.12.4

5 years ago

0.12.3

5 years ago

0.12.2

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.0

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

7 years ago

0.6.0-beta.3

7 years ago

0.6.0-beta.2

7 years ago

0.6.0-beta.1

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago