redux-logging-reducer v1.0.2
redux-logging-reducer
Adds logging of dispatched actions to your reducer functionality storing dispatched actions in the reducer's store.
NOTE: Since writing this module, I found it easier to test reducer and redux-observable
epics separately using patterns described here: Writing Epic Unit Tests.
Usage
import { applyMiddleware, createStore } from "redux";
import { logging, log, noLog } from "redux-logging-reducer";
import reducer from "./reducer";
const middleware = [];
describe("Testing actions", () =>
{
let store;
beforeEach(() =>
{
store = createStore(logging(reducer), applyMiddleware(...middleware));
}
);
it("should log dispatched action and return initial state", () =>
{
store.dispatch({type: "MY_ACTION"});
const dispatched = log(store.getState());
const state = noLog(store.getState());
expect(dispatched).toContainEqual({type: "MY_ACTION"});
expect(state).toEqual(reducer.INITIAL_STATE);
}
);
});
Documentation
log(state, fieldName = "@@redux-logging-reducer/log")
state
: Object Redux state fromstore.getState()
.fieldName
: String Field name to extract log of dispatched actions from.- Return: Array Array of dispatched actions.
Extracts the log of dispatched actions from Redux store state.
logging(reducer, fieldName = "@@redux-logging-reducer/log")
reducer
: Function Redux reducer to add logging to.fieldName
: String Field name to store log of dispatched actions in.- Return: Function Redux reducer that will log dispatched actions in
fieldName
.
Monkey patches reducer
to store log of dispatched actions.
noLog(state, fieldName = "@@redux-logging-reducer/log")
state
: Object Redux state fromstore.getState()
.fieldName
: String Field name to remove containing dispatched actions.- Return: Object Redux store state without dispatched actions log.
Removed log of dispatched actions from Redux store state.
Releases
Policy
We follow the semantic versioning policy (semver.org) with a caveat:
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes.
caveat: Major version zero is a special case indicating development version that may make incompatible API changes without incrementing MAJOR version.