Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

immer-reducer

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immer-reducer - npm Package Compare versions

Comparing version 0.7.5 to 0.7.6

9

lib/immer-reducer.d.ts

@@ -69,2 +69,11 @@ import { Draft } from "immer";

}, immerReducerClass: T): action is Actions<T>;
interface Reducer<State> {
(state: State | undefined, action: any): State;
}
/**
* Combine multiple reducers into a single one
*
* @param reducers two or more reducer
*/
export declare function composeReducers<State>(...reducers: (Reducer<State | undefined>)[]): Reducer<State>;
/** The actual ImmerReducer class */

@@ -71,0 +80,0 @@ export declare class ImmerReducer<T> {

@@ -38,2 +38,22 @@ "use strict";

exports.isActionFrom = isActionFrom;
/**
* Combine multiple reducers into a single one
*
* @param reducers two or more reducer
*/
function composeReducers() {
var reducers = [];
for (var _i = 0; _i < arguments.length; _i++) {
reducers[_i] = arguments[_i];
}
return function (state, action) {
return (reducers.reduce(function (state, subReducer) {
if (typeof subReducer === "function") {
return subReducer(state, action);
}
return state;
}, state) || state);
};
}
exports.composeReducers = composeReducers;
/** The actual ImmerReducer class */

@@ -40,0 +60,0 @@ var ImmerReducer = /** @class */ (function () {

2

package.json
{
"name": "immer-reducer",
"version": "0.7.5",
"version": "0.7.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "lib/immer-reducer.js",

@@ -252,2 +252,31 @@ # immer-reducer

**Warning:** Due to how immer-reducers action generation works, adding default
parameters to the methods will NOT pass it to the action payload, which can
make your reducer impure and the values will not be available in middlewares.
```ts
class MyImmerReducer extends ImmerReducer<State> {
addItem (id: string = uuid()) {
this.draftState.ids.push([id])
}
}
immerActions.addItem() // generates empty payload { payload: [] }
```
As a workaround, create custom action creator wrappers that pass the default parameters instead.
```ts
class MyImmerReducer extends ImmerReducer<State> {
addItem (id) {
this.draftState.ids.push([id])
}
}
const actions = {
addItem: () => immerActions.addItem(id)
}
```
## 📚 Examples

@@ -327,1 +356,32 @@

```
### `function composeReducers<State>(...reducers)`
Utility that reduces actions by applying them through multiple reducers.
This helps in allowing you to split up your reducer logic to multiple `ImmerReducer`s
if they affect the same part of your state
Example
```ts
class MyNameReducer extends ImmerReducer<NamesState> {
setFirstName(firstName: string) {
this.draftState.firstName = firstName;
}
setLastName(lastName: string) {
this.draftState.lastName = lastName;
}
}
class MyAgeReducer extends ImmerReducer<AgeState> {
setAge(age: number) {
this.draftState.age = 8;
}
}
export const reducer = composeReducers(
createReducerFunction(MyNameReducer, initialState),
createReducerFunction(MyAgeReducer, initialState)
)
```

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc