redux-appstate

1.1.0 • Public • Published

Redux-AppState Build Status

Appstate is a Javascript state manager, based on Cerebral signals conception. Appstate use Redux as main state storage.

Usage

Apply middleware

  const configureAppState = require('redux-appstate');
 
  const middlewares = [
    configureAppState({ // should be first
      // services will be available in all signal actions.
      services: {
        api,
        // ...
      },
      // log all errors that occures in signal
      logError, // default "console.error"
      // log result of successful signal execution.
      logSuccess, // default "() => {}"
    }),
    // other middlewares
  ]
 
  const store = createStore(reducer, applyMiddleware(...middlewares));

Dispatch signal with args

  const signalActions = [
    syncAction,
    [
     asyncAction, { // outputs mapping
       success: [successSyncAction],
       error: [errorSyncAction]
      }
    ]
  ];
 
  store.dispatch(signalActions, args); // dispatch signal with arguments object

Signal actions interface

function syncAction ({
  args,
  getState, // get currect redux store state
  output, // output({ newArg: 'value' }) - extend "args" with "newArg"
  dispatch, // dispatch redux action. Only sync actions allowed to dispatch
  services,
}) {
}
 
function asyncAction ({
  args,
  getState,
  output, // output.success() or output.error(). outputs properties defines by outputs mapping object 
          // one and only one of outputs must be called to resolve async action
  services,
}) {
}

Package Sidebar

Install

npm i redux-appstate

Weekly Downloads

0

Version

1.1.0

License

MIT

Last publish

Collaborators

  • eugeny-dementev