SinkContainer

SinkContainer use to keep store and all the sinks within the same scope.

Since SinkFactory is an instance of SinkContainer the API is the same, all the code example will be using SinkFactory for easier understanding the usage.

createStore(SinkConfiguration) => Store

Create sink store, it can take reducers, middlewares and devToolOptions with configuration

interface SinkConfiguration {
  // regular reducers
  reducers: { [key: string]: (state, action) => state },
  // predefined state
  preloadedState: { ...state },
  // additional middlewares
  middlewares: Array<ReduxMiddleware>,
  // use effect trace, default false
  useEffectTrace?: boolean;
  // use effect, default false
  useTrigger?: boolean;
  // required compose function from redux-dev-tool
  devToolOptions: {
    // devTool compose function
    devToolCompose: Function,
    // should devTool disabled
    disabled?: boolean,
    // other devTool properties
    [key: string]: any
  }
}

getSink(SinkClass) => SinkInstance

Get sink from the current container using sink class

type SinkClass = Constructor => SinkInstance

getEffectTasks() => Array<Promise>

Get currently running async effects

import { SinkFactory } from 'redux-sink';

Promise.all(SinkFactory.getEffectTasks()).then(() => {
  // do something when all effects completed
});

getStore() => Store

Get underlining redux store from the container

import { SinkFactory } from 'redux-sink';

// use store to dispatch a location event, just like regular redux
SinkFactory.getStore().dispatch({ 
  type: 'navigation/loaction',
  payload: { pathname: '/' }
});

// get global state of the store
const state = SinkFactory.getStore().getState();

Last updated