zustand-mutable 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +32 -0
- package/dist/index.js +4 -0
- package/dist/index.umd.cjs +1 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { StateCreator, StoreMutatorIdentifier } from 'zustand/vanilla';
|
|
2
|
+
type Primitive = string | number | bigint | boolean | null | undefined;
|
|
3
|
+
type IfAvailable<T, Fallback = void> = true | false extends (T extends never ? true : false) ? Fallback : keyof T extends never ? Fallback : T;
|
|
4
|
+
type WeakReferences = IfAvailable<WeakMap<any, any>> | IfAvailable<WeakSet<any>>;
|
|
5
|
+
type AtomicObject = Function | Promise<any> | Date | RegExp;
|
|
6
|
+
type DeepMap<T, Mutable extends boolean> = T extends Primitive | AtomicObject ? T : T extends IfAvailable<ReadonlyMap<infer K, infer V>> ? Mutable extends true ? Map<K, DeepMap<V, true>> : ReadonlyMap<DeepMap<K, false>, DeepMap<V, false>> : T extends IfAvailable<ReadonlySet<infer V>> ? Mutable extends true ? Set<DeepMap<V, true>> : ReadonlySet<DeepMap<V, false>> : T extends WeakReferences ? T : T extends object ? Mutable extends true ? {
|
|
7
|
+
-readonly [K in keyof T]: DeepMap<T[K], true>;
|
|
8
|
+
} : {
|
|
9
|
+
readonly [K in keyof T]: DeepMap<T[K], false>;
|
|
10
|
+
} : T;
|
|
11
|
+
type Draft<T> = DeepMap<T, true>;
|
|
12
|
+
type Mutable = <T, Mps extends [StoreMutatorIdentifier, unknown][] = [], Mcs extends [StoreMutatorIdentifier, unknown][] = []>(initializer: StateCreator<T, [...Mps, ["zustand/mutable", never]], Mcs>, produceFn: (recipe: (state: T) => void) => (state: T) => T) => StateCreator<T, Mps, [["zustand/mutable", never], ...Mcs]>;
|
|
13
|
+
declare module "zustand/vanilla" {
|
|
14
|
+
interface StoreMutators<S, A> {
|
|
15
|
+
["zustand/mutable"]: WithMutable<S>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
type Write<T, U> = Omit<T, keyof U> & U;
|
|
19
|
+
type SkipTwo<T> = T extends [any?, any?, ...infer Rest] ? Rest : never;
|
|
20
|
+
type SetStateType<T extends unknown[]> = Exclude<T[0], (...args: any[]) => any>;
|
|
21
|
+
type WithMutable<S> = Write<S, StoreMutable<S>>;
|
|
22
|
+
type StoreMutable<S> = S extends {
|
|
23
|
+
setState: infer SetState;
|
|
24
|
+
} ? SetState extends {
|
|
25
|
+
(...a: infer A1): infer Sr1;
|
|
26
|
+
(...a: infer A2): infer Sr2;
|
|
27
|
+
} ? {
|
|
28
|
+
setState(nextStateOrUpdater: SetStateType<A2> | Partial<SetStateType<A2>> | ((state: Draft<SetStateType<A2>>) => void), shouldReplace?: false, ...a: SkipTwo<A1>): Sr1;
|
|
29
|
+
setState(nextStateOrUpdater: SetStateType<A2> | ((state: Draft<SetStateType<A2>>) => void), shouldReplace: true, ...a: SkipTwo<A2>): Sr2;
|
|
30
|
+
} : never : never;
|
|
31
|
+
export declare const mutable: Mutable;
|
|
32
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.Mutable={}))})(this,function(e){e.mutable=(e,t)=>(n,r,i)=>(i.setState=(e,r,...i)=>{n(typeof e==`function`?t(e):e,r,...i)},e(i.setState,r,i))});
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "zustand-mutable",
|
|
3
|
+
"private": false,
|
|
4
|
+
"description": "A sweet way to use immer-like mutable updates",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"author": "Danilo Britto",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/zustandjs/zustand-mutable.git"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"main": "./dist/index.umd.cjs",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.umd.cjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"sideEffects": false,
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@biomejs/biome": "2.3.10",
|
|
27
|
+
"@ossjs/release": "^0.10.1",
|
|
28
|
+
"@testing-library/jest-dom": "^6.9.1",
|
|
29
|
+
"@testing-library/react": "^16.3.1",
|
|
30
|
+
"@types/node": "^25.0.3",
|
|
31
|
+
"@types/react": "^19.2.7",
|
|
32
|
+
"happy-dom": "^20.0.11",
|
|
33
|
+
"immer": "^11.1.3",
|
|
34
|
+
"limu": "^4.1.1",
|
|
35
|
+
"mutative": "^1.3.0",
|
|
36
|
+
"react": "^19.2.3",
|
|
37
|
+
"typescript": "~5.9.3",
|
|
38
|
+
"vite": "npm:rolldown-vite@7.2.5",
|
|
39
|
+
"vite-plugin-dts": "^4.5.4",
|
|
40
|
+
"vitest": "^4.0.16",
|
|
41
|
+
"zustand": "^5.0.9"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"zustand": "^5.0.9"
|
|
45
|
+
},
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "vite build",
|
|
51
|
+
"test": "pnpm run \"/^test:.*/\"",
|
|
52
|
+
"test:types": "tsc --noEmit",
|
|
53
|
+
"test:lintFormat": "biome check ./src",
|
|
54
|
+
"test:spec": "vitest run",
|
|
55
|
+
"release": "release publish"
|
|
56
|
+
}
|
|
57
|
+
}
|