Skip to content

Commit

Permalink
Bugfix/bad next calls (#19)
Browse files Browse the repository at this point in the history
* Remove bad calls to 'next'

* Fix lint

---------

Co-authored-by: Jakob Nilsson-Ehle <[email protected]>
  • Loading branch information
Nehle and Jakob Nilsson-Ehle authored Apr 27, 2023
1 parent d3d7fc3 commit d39686b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const compositeReducer = compose([errorHandler, reduxLogger, reducer]);
```

### `withDefault(defaultState)`
Returns a reducer that returns the supplied `defaultState` if the `state` it's supplied is `undefined`
Returns a reducer that returns the supplied `defaultState` if the `state` its supplied is `undefined`

```js
import { withDefault } from "horux";
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "horux",
"version": "4.0.2",
"description": "A library of simple everyday reducer utility functions ",
"keywords": ["redux", "reducer", "compose", "higher-order functions"],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions src/map-by-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const mapByType = <TState, TAction extends { type: string }>(
throw new Error(`Key "${key}" in mapByType is not a reducer`);
}
}
return (state, action: TAction, next) => {
return (state, action: TAction) => {
if (!action.type || typeof reducers[action.type] === "undefined") {
return state;
}
return reducers[action.type](state, action, next);
return reducers[action.type](state, action);
};
};

Expand Down
4 changes: 2 additions & 2 deletions src/merge-states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { ComposableReducer } from "./types/composableReducer";
const mergeStates = <TState, TAction>(
reducer: ComposableReducer<TState, TAction>
): ComposableReducer<TState, TAction> => {
return (state, action, next) => {
const nextState = reducer(state, action, next);
return (state, action) => {
const nextState = reducer(state, action);
return Object.assign({}, state, nextState);
};
};
Expand Down
6 changes: 4 additions & 2 deletions test/compose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ describe("compose", () => {
expect(typeof compose([])).toBe("function");
});
it("throws an error if the supplied reducers are not an array", () => {
expect(() => compose({} as any)).toThrowError("Reducers must be an array");
expect(() => compose({} as ComposableReducer<never, never>[])).toThrowError(
"Reducers must be an array"
);
});
it("throws an error if the supplied reducers are not an array of functions", () => {
expect(() => compose([{} as any])).toThrowError(
expect(() => compose([{} as ComposableReducer<never, never>])).toThrowError(
'Reducer at position "0" is not a function'
);
});
Expand Down

0 comments on commit d39686b

Please sign in to comment.