Home

Awesome

Redux Owl

Redux One Way Linking

This is a simple method for supporting offline sync. When two way concurrency such as scuttlebutt/CRDT is not possible (e.g. third party api's) or is not desired (complexity), this is a simple alternative.

The basic concept is, try to execute the action, on failure add it to a retry queue. Every so often process the retry queue until success is achieved.

To function properly your app will also need to support the following:

@TODO

improve api (reducer vs store enhancer?) add processing rules

Setup

import {owlReducer, enableOwl} from 'redux-owl'
import {persistStore} from 'redux-persist'

const reducer = combineReducers({
  ...otherReducers,
  owl: owlReducer,
})

//...

persistStore(store, {}, (err) => {
  //does not depend on redux-persist, but be sure enable owl
  //after persistence is complete
  enableOwl(store, {})
})

ActionCreator

import {createOwlAction } from 'redux-owl'

export function createRecordTest(record) {
  return createOwlAction('RECORD_INSERT', record, {})
}

Async Action / Side Effects

import { remoteActionMap } from 'redux-remotes'
import { handleOwlAction } from 'redux-owl'

export default remoteActionMap({
  RECORD_INSERT({action, getState, dispatch, finish}){
    handleOwlAction(action, finish, (success, fail) => {
      if(Math.random() > .5){ setTimeout(success, 1000) }
      else { setTimeout(fail, 1000) }
    })
  }
})