https://github.com/clarus/redux-ship-logger
A logger for Redux Ship
https://github.com/clarus/redux-ship-logger
Last synced: about 2 months ago
JSON representation
A logger for Redux Ship
- Host: GitHub
- URL: https://github.com/clarus/redux-ship-logger
- Owner: clarus
- License: mit
- Created: 2016-10-02T16:58:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-28T07:24:53.000Z (over 8 years ago)
- Last Synced: 2025-04-14T22:47:27.109Z (about 2 months ago)
- Language: JavaScript
- Size: 524 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# redux-ship-logger
> A logger for the [Redux Ship](https://github.com/clarus/redux-ship) effect system
## Getting started
Redux Ship Logger is useful to debug projects written with the [Redux Ship](https://github.com/clarus/redux-ship) effect system.
```
npm i redux-ship-logger
```Redux Ship Logger provides two functions, one to log the commits and patches (the model part) and one to log the asynchronous actions (the controller part).
## API
* [`logCommit`](#logCommit)
* [`logControl`](#logControl)### `logCommit`
```js
(
applyCommit: (state: State, commit: Commit) => Patch
) => ReduxMiddleware
```Returns a Redux middleware to log the *commits* and the *patches* sent to Redux.
* `applyCommit` the function computing the patch associated to the current commit
#### Example
```js
// store.js
import {applyMiddleware, createStore} from 'redux';
import {logCommit} from 'redux-ship-logger';
import * as Controller from './controller';
import * as Model from './model';const middlewares = [
logCommit(Controller.applyCommit),
];function reduce(state, commit) {
return Model.reduce(state, Controller.applyCommit(state, commit));
}export default createStore(reduce, Model.initialState, applyMiddleware(...middlewares));
```
### `logControl`
```js
(
control: (action: Action) => Ship
) => (action: Action) => Ship
```Returns a controller with the same behavior as `control` but logging its snapshots. Also logs a stringified JSON of the snapshot ready to be used in tests with `Ship.simulate`.
* `control` the controller to log
#### Example
```js
// index.js
import * as Ship from 'redux-ship';
import {logControl} from 'redux-ship-logger';
import store from './store';
import * as Controller from './controller';
import * as Effect from './effect';function dispatch(action: Controller.Action): void {
Ship.run(Effect.run, store, logControl(Controller.control)(action));
}
```