Skip to content

Commit

Permalink
Changed README.md to represent the change
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexxzz committed Dec 1, 2018
1 parent 789114c commit 38c5257
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ expect(store.getState().firstName).toEqual("Charlie");
expect(store.getState().lastName).toEqual("Brown");
```

Under the hood the class is desconstructed to following actions:
Under the hood the class is deconstructed to following actions:

```js
{
Expand All @@ -87,11 +87,31 @@ Under the hood the class is desconstructed to following actions:

So the method names become the Redux Action Types and the method arguments
become the action payloads. The reducer function will then match these
actions against the class and calls the approciate methods with the payload
actions against the class and calls the appropriate methods with the payload
array spread to the arguments. But do note that the action format is not part of
the public API so don't write any code relying on it. The actions are handled
by the generated reducer function.

If there is a need for some reason to access to the action type name, for example to
integrate with side effects libraries such as [redux-observable](https://github.com/redux-observable/redux-observable/) or [redux-saga](https://github.com/redux-saga/redux-saga),
you can access it using `type` property of the action creator function:
```ts
// Get the action name to subscribe to
const setFirstNameActionTypeName = ActionCreators.setFirstName.type;

// Get the action type to have a type safe Epic
type SetFirstNameAction = typeof ReturnType<ActionCreators.setFirstName>;

const setFirstNameEpic: Epic<SetFirstNameAction> = action$ =>
action$
.ofType(setFirstNameActionTypeName)
.pipe(
// action.payload - recognized as string
map(action => action.payload.toUpperCase()),
...
);
```

The generated reducer function executes the methods inside the `produce()`
function of Immer enabling the terse mutatable style updates.

Expand Down

0 comments on commit 38c5257

Please sign in to comment.