Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Mar 14, 2024
1 parent c3a8833 commit e6c5c21
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# ngrx-immer

> Immer wrappers around NgRx methods to mutate state easily
> Immer wrappers around NgRx methods to simplify mutating state
<!-- TOC -->
* [ngrx-immer](#ngrx-immer)
* [Installation](#installation)
* [Functions](#functions)
* [`createImmerReducer` (@ngrx/store)](#createimmerreducer-ngrxstore)
* [`immerOn` (@ngrx/store)](#immeron-ngrxstore)
* [`ImmerComponentStore` (@ngrx/component-store)](#immercomponentstore-ngrxcomponent-store)
* [`immerPatchState` (@ngrx/signals)](#immerpatchstate-ngrxsignals)
* [`immerReducer`](#immerreducer)
* [FAQ](#faq)
* [Resources](#resources)
<!-- TOC -->

## Installation

Expand All @@ -10,12 +23,9 @@ npm install ngrx-immer

> Do not forget to install immer
## Resources
## Functions

- [Immer docs](https://immerjs.github.io/immer/)
- [NgRx docs](https://ngrx.io/docs/)

## `createImmerReducer`
### `createImmerReducer` (@ngrx/store)

Creates an NgRx reducer, but allows you to mutate state without having to use to spread operator.

Expand All @@ -38,7 +48,7 @@ const todoReducer = createImmerReducer(
);
```

## `immerOn`
### `immerOn` (@ngrx/store)

Creates an NgRx reducer, but allows you to mutate state without having to use to spread operator.

Expand All @@ -61,7 +71,7 @@ const todoReducer = createReducer(
);
```

## `ImmerComponentStore`
### `ImmerComponentStore` (@ngrx/component-store)

Wraps Immer around the Component Store `updater` and `setState` methods.

Expand All @@ -80,7 +90,10 @@ export class MoviesStore extends ImmerComponentStore<MoviesState> {
}
```

## `immerPatchState`
### `immerPatchState` (@ngrx/signals)

> [!IMPORTANT]
> Because `@ngrx/signals` is in developer preview, the `immerPatchState` function is also in developer preview. It is ready to try, but may change before becoming stable.
Provides an Immer-version of the `patchState` function from the `@ngrx/signals` package. In addition to partial state objects and updaters that update the state immutably, it accepts updater functions that update the state in a mutable manner. Similar to `patchState`, the `immerPatchState` function can be used to update the state of both SignalStore and SignalState.

Expand All @@ -105,7 +118,7 @@ const UserStore = signalStore(
);
```

Please note, that the updater function can only mutate a change without returning it or return an immutable
Please note, that the updater function can only mutate a change without returning it or return an immutable
state without mutable change.

This one is going to throw a runtime error:
Expand All @@ -118,11 +131,17 @@ immerPatchState(userStore, (state) => {
});
```

## `immerReducer`
### `immerReducer`

Inspired by [Alex Okrushko](https://twitter.com/alexokrushko), `immerReducer` is a reducer method that uses the Immer `produce` method.
This method is used by all the methods in `ngrx-immer` provides.

## FAQ

- See the Immer docs, [Update patterns](https://immerjs.github.io/immer/docs/update-patterns), on how to mutate state

## Resources

- [Immer docs](https://immerjs.github.io/immer/)
- [NgRx docs](https://ngrx.io/docs/)

0 comments on commit e6c5c21

Please sign in to comment.