Objective Redux

Redux made better, objectively.

ReducerInjector

class ReducerInjector

An object that handles injection of reducers into the Redux store that is managed by an ObjectiveStore.
This can be used when middleware or another part of the application also needs to handle injection. For example, this should be used when Redux-Injectors is being used with Objective Redux.

Examples

import { ReducerInjector, ObjectiveStore } from 'objective-redux';
import { createInjectorsEnhancer } from 'redux-injectors';
import { initialState, initialReducers } from './elsewhere';

const injector = new ReducerInjector(initialReducers);

const createReducer = injector.getReducerCreationFn();
const runSaga = injector.getRunSagaFn();

const middleware = [
  createInjectorsEnhancer({ createReducer, runSaga }),
];

const objectiveStore = new ObjectiveStore({
  reducer,
  initialState,
  middleware,
  injector,
});

constructor

public constructor(initialReducers: Record<string, any> = {}): ReducerInjector

Creates an injector instance.

Parameters

initialReducers: Record<string, any> = {}
The initial reducers to add to the combine reducer.

Returns

ReducerInjector

Examples

const injector = new ReducerInjector({
  MyReducer: reducerOne,
});

getReducerCreationFn

public getReducerCreationFn(): CreateReducerFn

A function that can be used to get add additional reducers to the store.

Returns

CreateReducerFn
A function that takes a map of reducers. The reducers are added to the initial reducers and the reducers
internal to Objective Redux, resulting in a final, combined reducer.

Examples

const initialReducers = {
  MyInitialReducer: reducerOne,
};

const injector = new ReducerInjector(initialReducers);
const reducerCreationFn = injector.getReducerCreationFn();

const objectiveStore = new ObjectiveStore({
  injector,
});

const nextReducer = reducerCreationFn({
  MyInitialReducer: reducerTwo,
});

objectiveStore.replaceReducer(nextReducer);

getSagaRunningFn

public getSagaRunningFn(): RunSagaFn

Returns

RunSagaFn

setGetObjectiveReduxReducers

public setGetObjectiveReduxReducers(getObjectiveReduxReducers: () => Record<string, Reducer>): void

This function should not be called directly.
Sets the get function for retrieving the reducers internal to Objective Redux.

Parameters

getObjectiveReduxReducers: () => Record<string, Reducer>
Function that can be called to get the reducers internal to Objective Redux.
This only be used by the ObjectiveStore and should not be called directly.

Returns

void

Examples

// Do not use this function directly!

setSagaRunningFn

public setSagaRunningFn(sagaRunningFn: any): void

This function should not be called directly.
Sets the get function for running a Saga.

Parameters

sagaRunningFn: any
Function used to run a saga.

Returns

void

Examples

// Do not use this function directly!