reactish-state 1.1.0 → 1.1.1
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.
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const createState = ({
|
|
4
4
|
middleware
|
|
5
|
-
} = {}) => (initialValue,
|
|
5
|
+
} = {}) => (initialValue, actionBuilder, config) => {
|
|
6
6
|
let value = initialValue;
|
|
7
7
|
const listeners = new Set();
|
|
8
8
|
const get = () => value;
|
|
@@ -24,7 +24,7 @@ const createState = ({
|
|
|
24
24
|
subscribe
|
|
25
25
|
}, config);
|
|
26
26
|
return {
|
|
27
|
-
...
|
|
27
|
+
...actionBuilder?.(set, get),
|
|
28
28
|
get,
|
|
29
29
|
set,
|
|
30
30
|
subscribe
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const createState = ({
|
|
2
2
|
middleware
|
|
3
|
-
} = {}) => (initialValue,
|
|
3
|
+
} = {}) => (initialValue, actionBuilder, config) => {
|
|
4
4
|
let value = initialValue;
|
|
5
5
|
const listeners = new Set();
|
|
6
6
|
const get = () => value;
|
|
@@ -22,7 +22,7 @@ const createState = ({
|
|
|
22
22
|
subscribe
|
|
23
23
|
}, config);
|
|
24
24
|
return {
|
|
25
|
-
...
|
|
25
|
+
...actionBuilder?.(set, get),
|
|
26
26
|
get,
|
|
27
27
|
set,
|
|
28
28
|
subscribe
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reactish-state",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Simple, decentralized (atomic) state management for React.",
|
|
5
5
|
"author": "Zheng Song",
|
|
6
6
|
"license": "MIT",
|
|
@@ -91,10 +91,10 @@
|
|
|
91
91
|
"@rollup/plugin-babel": "^6.0.4",
|
|
92
92
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
93
93
|
"@rollup/plugin-replace": "^6.0.2",
|
|
94
|
-
"@testing-library/jest-dom": "^6.6.
|
|
94
|
+
"@testing-library/jest-dom": "^6.6.4",
|
|
95
95
|
"@testing-library/react": "^16.3.0",
|
|
96
96
|
"@types/jest": "^30.0.0",
|
|
97
|
-
"@types/react": "^19.1.
|
|
97
|
+
"@types/react": "^19.1.9",
|
|
98
98
|
"@types/use-sync-external-store": "^1.5.0",
|
|
99
99
|
"babel-plugin-pure-annotations": "^0.1.2",
|
|
100
100
|
"deplift": "^1.0.1",
|
|
@@ -110,9 +110,9 @@
|
|
|
110
110
|
"jest-environment-jsdom": "^30.0.5",
|
|
111
111
|
"npm-run-all": "^4.1.5",
|
|
112
112
|
"prettier": "^3.6.2",
|
|
113
|
-
"react": "^19.1.
|
|
114
|
-
"react-dom": "^19.1.
|
|
115
|
-
"rollup": "^4.
|
|
113
|
+
"react": "^19.1.1",
|
|
114
|
+
"react-dom": "^19.1.1",
|
|
115
|
+
"rollup": "^4.46.2",
|
|
116
116
|
"typescript": "^5.8.3",
|
|
117
117
|
"typescript-eslint": "^8.38.0"
|
|
118
118
|
}
|
package/types/common.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export type Getter<T> = () => T;
|
|
2
|
-
export type Setter<T> = (newValue: T | ((value: T) => T),
|
|
3
|
-
type: string;
|
|
4
|
-
[key: string]: unknown;
|
|
5
|
-
}) => void;
|
|
2
|
+
export type Setter<T> = (newValue: T | ((value: T) => T), context?: unknown) => void;
|
|
6
3
|
export type Unsubscriber = () => void;
|
|
7
4
|
export type StateListener<T> = (nextValue: T, prevValue: T) => void;
|
|
8
5
|
export type StateSubscriber<T> = (listener: StateListener<T>) => Unsubscriber;
|
|
@@ -11,6 +8,8 @@ export interface State<T> {
|
|
|
11
8
|
set: Setter<T>;
|
|
12
9
|
subscribe: StateSubscriber<T>;
|
|
13
10
|
}
|
|
11
|
+
export type ActionBuilder<T, A> = ((set: Setter<T>, get: () => T) => A) | null | undefined;
|
|
12
|
+
export type StateWithAction<T, A> = Omit<A, keyof State<T>> & State<T>;
|
|
14
13
|
export type SelectorListener = () => void;
|
|
15
14
|
export type SelectorSubscriber = (listener: SelectorListener) => Unsubscriber;
|
|
16
15
|
export interface Selector<T> {
|
package/types/vanilla/state.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type ActionCreator<T, A> = ((set: Setter<T>, get: () => T) => A) | null | undefined;
|
|
3
|
-
type StateWithAction<T, A> = Omit<A, keyof State<T>> & State<T>;
|
|
1
|
+
import type { ActionBuilder, StateWithAction, Config, Middleware } from '../common';
|
|
4
2
|
declare const createState: ({ middleware }?: {
|
|
5
3
|
middleware?: Middleware;
|
|
6
|
-
}) => <T, A>(initialValue: T,
|
|
7
|
-
declare const state: <T, A>(initialValue: T,
|
|
8
|
-
|
|
9
|
-
export { state, createState };
|
|
4
|
+
}) => <T, A>(initialValue: T, actionBuilder?: ActionBuilder<T, A>, config?: Config) => StateWithAction<T, A>;
|
|
5
|
+
declare const state: <T, A>(initialValue: T, actionBuilder?: ActionBuilder<T, A>, config?: Config) => StateWithAction<T, A>;
|
|
6
|
+
type StateBuilder = typeof state;
|
|
7
|
+
export { state, createState, type StateBuilder };
|