Skip to content

Commit c3775da

Browse files
committed
refactor(apply): reuse mutative apply() with mutable mode
1 parent 70568e9 commit c3775da

File tree

6 files changed

+16
-164
lines changed

6 files changed

+16
-164
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"eslint-plugin-prettier": "^5.1.3",
5858
"jest": "^29.7.0",
5959
"jest-environment-jsdom": "^29.7.0",
60-
"mutative": "^1.1.0",
60+
"mutative": "^1.2.0",
6161
"prettier": "^3.2.5",
6262
"rimraf": "^5.0.7",
6363
"rollup": "^4.22.5",
@@ -82,6 +82,6 @@
8282
}
8383
},
8484
"peerDependencies": {
85-
"mutative": "^1.0"
85+
"mutative": "^1.2.0"
8686
}
8787
}

src/apply.ts

Lines changed: 0 additions & 96 deletions
This file was deleted.

src/index.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
import { create } from 'mutative';
2-
import { apply } from './apply';
3-
4-
export { apply } from './apply';
1+
import { create, apply as baseApply, Patches } from 'mutative';
52

63
/**
74
* Transactional updates to the base state with the recipe.
85
*/
9-
export const mutate = <T>(baseState: T, recipe: (state: T) => void) => {
6+
export const mutate = <T extends object>(
7+
baseState: T,
8+
recipe: (state: T) => void
9+
) => {
1010
const [, patches, inversePatches] = create(baseState, recipe, {
1111
enablePatches: true,
1212
});
13-
apply(baseState, patches);
13+
baseApply(baseState, patches, { mutable: true });
1414
return { inversePatches, patches };
1515
};
16+
17+
export const apply = <T extends object>(baseState: T, patches: Patches) => {
18+
baseApply(baseState, patches, { mutable: true });
19+
};

src/interface.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/utils.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,10 +3946,10 @@ ms@^2.1.1:
39463946
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
39473947
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
39483948

3949-
mutative@^1.1.0:
3950-
version "1.1.0"
3951-
resolved "https://registry.yarnpkg.com/mutative/-/mutative-1.1.0.tgz#ff3e12a9903702e0487428510f8502dd4667e908"
3952-
integrity sha512-2PJADREjOusk3iJkD3rXV2YjAxTuaLxdfqtqTEt6vcY07LtEBR1seHuBHXWEIuscqRDGvbauYPs+A4Rj/KTczQ==
3949+
mutative@^1.2.0:
3950+
version "1.2.0"
3951+
resolved "https://registry.yarnpkg.com/mutative/-/mutative-1.2.0.tgz#db75b60b436ad0a940e2e47bffb6661dd77c2754"
3952+
integrity sha512-1muFw45Lwjso6TSBGiXfbjKS01fVSD/qaqBfTo/gXgp79e8KM4Sa1XP/S4iN2/DvSdIZgjFJI+JIhC7eKf3GTg==
39533953

39543954
39553955
version "0.0.8"

0 commit comments

Comments
 (0)