react-store-input 0.2.2 → 0.2.4
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/create_render.js +14 -18
- package/dist/create_render.mjs +15 -19
- package/dist/index.js +24 -17
- package/dist/index.mjs +28 -21
- package/dist/use_form_store.js +30 -21
- package/dist/use_form_store.mjs +35 -26
- package/dist/use_selector.js +14 -18
- package/dist/use_selector.mjs +15 -19
- package/dist/use_store_component.js +1 -1
- package/dist/use_store_component.mjs +1 -1
- package/dist/use_store_controller.js +1 -1
- package/dist/use_store_controller.mjs +1 -1
- package/dist/use_store_input.js +1 -1
- package/dist/use_store_input.mjs +1 -1
- package/dist/use_store_input_with_name.d.mts +1 -1
- package/dist/use_store_input_with_name.d.ts +1 -1
- package/dist/use_store_input_with_name.js +1 -1
- package/dist/use_store_input_with_name.mjs +1 -1
- package/dist/use_subscribe.js +1 -1
- package/dist/use_subscribe.mjs +1 -1
- package/package.json +5 -5
package/dist/create_render.js
CHANGED
|
@@ -26,29 +26,25 @@ __export(create_render_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(create_render_exports);
|
|
27
27
|
|
|
28
28
|
// src/use_selector.tsx
|
|
29
|
-
var import_react2 = require("react");
|
|
30
|
-
|
|
31
|
-
// src/use_subscribe.tsx
|
|
32
29
|
var import_react = require("react");
|
|
33
|
-
function
|
|
30
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
31
|
+
const [state, setState] = (0, import_react.useState)(selector(store.state));
|
|
32
|
+
const stateRef = (0, import_react.useRef)(state);
|
|
34
33
|
(0, import_react.useEffect)(() => {
|
|
35
|
-
|
|
34
|
+
stateRef.current = state;
|
|
35
|
+
}, [state]);
|
|
36
|
+
(0, import_react.useEffect)(() => {
|
|
37
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
38
|
+
const result = selector(newState);
|
|
39
|
+
if (compare(stateRef.current, result)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setState(result);
|
|
43
|
+
});
|
|
36
44
|
return () => {
|
|
37
45
|
unsubscribe();
|
|
38
46
|
};
|
|
39
|
-
}, [
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// src/use_selector.tsx
|
|
43
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
44
|
-
const [state, setState] = (0, import_react2.useState)(selector(store.state));
|
|
45
|
-
useSubscribe(store, (newState) => {
|
|
46
|
-
const result = selector(newState);
|
|
47
|
-
if (compare(state, result)) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
setState(result);
|
|
51
|
-
});
|
|
47
|
+
}, []);
|
|
52
48
|
return state;
|
|
53
49
|
}
|
|
54
50
|
|
package/dist/create_render.mjs
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
// src/use_selector.tsx
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function useSubscribe(store, subscriber) {
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
4
|
+
const [state, setState] = useState(selector(store.state));
|
|
5
|
+
const stateRef = useRef(state);
|
|
7
6
|
useEffect(() => {
|
|
8
|
-
|
|
7
|
+
stateRef.current = state;
|
|
8
|
+
}, [state]);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
11
|
+
const result = selector(newState);
|
|
12
|
+
if (compare(stateRef.current, result)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setState(result);
|
|
16
|
+
});
|
|
9
17
|
return () => {
|
|
10
18
|
unsubscribe();
|
|
11
19
|
};
|
|
12
|
-
}, [
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/use_selector.tsx
|
|
16
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
17
|
-
const [state, setState] = useState(selector(store.state));
|
|
18
|
-
useSubscribe(store, (newState) => {
|
|
19
|
-
const result = selector(newState);
|
|
20
|
-
if (compare(state, result)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
setState(result);
|
|
24
|
-
});
|
|
20
|
+
}, []);
|
|
25
21
|
return state;
|
|
26
22
|
}
|
|
27
23
|
|
package/dist/index.js
CHANGED
|
@@ -79,30 +79,37 @@ function useStore(initialState) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// src/use_selector.tsx
|
|
82
|
-
var import_react3 = require("react");
|
|
83
|
-
|
|
84
|
-
// src/use_subscribe.tsx
|
|
85
82
|
var import_react2 = require("react");
|
|
86
|
-
function
|
|
83
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
84
|
+
const [state, setState] = (0, import_react2.useState)(selector(store.state));
|
|
85
|
+
const stateRef = (0, import_react2.useRef)(state);
|
|
87
86
|
(0, import_react2.useEffect)(() => {
|
|
88
|
-
|
|
87
|
+
stateRef.current = state;
|
|
88
|
+
}, [state]);
|
|
89
|
+
(0, import_react2.useEffect)(() => {
|
|
90
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
91
|
+
const result = selector(newState);
|
|
92
|
+
if (compare(stateRef.current, result)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
setState(result);
|
|
96
|
+
});
|
|
89
97
|
return () => {
|
|
90
98
|
unsubscribe();
|
|
91
99
|
};
|
|
92
|
-
}, [
|
|
100
|
+
}, []);
|
|
101
|
+
return state;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
|
-
// src/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
});
|
|
105
|
-
return state;
|
|
104
|
+
// src/use_subscribe.tsx
|
|
105
|
+
var import_react3 = require("react");
|
|
106
|
+
function useSubscribe(store, subscriber) {
|
|
107
|
+
(0, import_react3.useEffect)(() => {
|
|
108
|
+
const unsubscribe = store.subscribe(subscriber);
|
|
109
|
+
return () => {
|
|
110
|
+
unsubscribe();
|
|
111
|
+
};
|
|
112
|
+
}, []);
|
|
106
113
|
}
|
|
107
114
|
|
|
108
115
|
// src/use_store_controller.tsx
|
package/dist/index.mjs
CHANGED
|
@@ -43,30 +43,37 @@ function useStore(initialState) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// src/use_selector.tsx
|
|
46
|
-
import { useState } from "react";
|
|
46
|
+
import { useEffect, useRef as useRef2, useState } from "react";
|
|
47
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
48
|
+
const [state, setState] = useState(selector(store.state));
|
|
49
|
+
const stateRef = useRef2(state);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
stateRef.current = state;
|
|
52
|
+
}, [state]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
55
|
+
const result = selector(newState);
|
|
56
|
+
if (compare(stateRef.current, result)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
setState(result);
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
unsubscribe();
|
|
63
|
+
};
|
|
64
|
+
}, []);
|
|
65
|
+
return state;
|
|
66
|
+
}
|
|
47
67
|
|
|
48
68
|
// src/use_subscribe.tsx
|
|
49
|
-
import { useEffect } from "react";
|
|
69
|
+
import { useEffect as useEffect2 } from "react";
|
|
50
70
|
function useSubscribe(store, subscriber) {
|
|
51
|
-
|
|
71
|
+
useEffect2(() => {
|
|
52
72
|
const unsubscribe = store.subscribe(subscriber);
|
|
53
73
|
return () => {
|
|
54
74
|
unsubscribe();
|
|
55
75
|
};
|
|
56
|
-
}, [
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// src/use_selector.tsx
|
|
60
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
61
|
-
const [state, setState] = useState(selector(store.state));
|
|
62
|
-
useSubscribe(store, (newState) => {
|
|
63
|
-
const result = selector(newState);
|
|
64
|
-
if (compare(state, result)) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
setState(result);
|
|
68
|
-
});
|
|
69
|
-
return state;
|
|
76
|
+
}, []);
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
// src/use_store_controller.tsx
|
|
@@ -211,7 +218,7 @@ function useStoreInputWithName(ref, store, props) {
|
|
|
211
218
|
}
|
|
212
219
|
|
|
213
220
|
// src/use_store_component.tsx
|
|
214
|
-
import { useCallback, useRef as
|
|
221
|
+
import { useCallback, useRef as useRef3 } from "react";
|
|
215
222
|
import { jsx } from "react/jsx-runtime";
|
|
216
223
|
function useStoreComponent(store) {
|
|
217
224
|
const input = useCallback(function Component(props) {
|
|
@@ -237,7 +244,7 @@ function Input({
|
|
|
237
244
|
toStateValue,
|
|
238
245
|
...props
|
|
239
246
|
}) {
|
|
240
|
-
const ref =
|
|
247
|
+
const ref = useRef3(null);
|
|
241
248
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
242
249
|
...props,
|
|
243
250
|
getter,
|
|
@@ -255,7 +262,7 @@ function Select({
|
|
|
255
262
|
toStateValue,
|
|
256
263
|
...props
|
|
257
264
|
}) {
|
|
258
|
-
const ref =
|
|
265
|
+
const ref = useRef3(null);
|
|
259
266
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
260
267
|
...props,
|
|
261
268
|
getter,
|
|
@@ -273,7 +280,7 @@ function Textarea({
|
|
|
273
280
|
toStateValue,
|
|
274
281
|
...props
|
|
275
282
|
}) {
|
|
276
|
-
const ref =
|
|
283
|
+
const ref = useRef3(null);
|
|
277
284
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
278
285
|
...props,
|
|
279
286
|
getter,
|
package/dist/use_form_store.js
CHANGED
|
@@ -25,29 +25,25 @@ __export(use_form_store_exports, {
|
|
|
25
25
|
module.exports = __toCommonJS(use_form_store_exports);
|
|
26
26
|
|
|
27
27
|
// src/use_selector.tsx
|
|
28
|
-
var import_react2 = require("react");
|
|
29
|
-
|
|
30
|
-
// src/use_subscribe.tsx
|
|
31
28
|
var import_react = require("react");
|
|
32
|
-
function
|
|
29
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
30
|
+
const [state, setState] = (0, import_react.useState)(selector(store.state));
|
|
31
|
+
const stateRef = (0, import_react.useRef)(state);
|
|
33
32
|
(0, import_react.useEffect)(() => {
|
|
34
|
-
|
|
33
|
+
stateRef.current = state;
|
|
34
|
+
}, [state]);
|
|
35
|
+
(0, import_react.useEffect)(() => {
|
|
36
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
37
|
+
const result = selector(newState);
|
|
38
|
+
if (compare(stateRef.current, result)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setState(result);
|
|
42
|
+
});
|
|
35
43
|
return () => {
|
|
36
44
|
unsubscribe();
|
|
37
45
|
};
|
|
38
|
-
}, [
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// src/use_selector.tsx
|
|
42
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
43
|
-
const [state, setState] = (0, import_react2.useState)(selector(store.state));
|
|
44
|
-
useSubscribe(store, (newState) => {
|
|
45
|
-
const result = selector(newState);
|
|
46
|
-
if (compare(state, result)) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
setState(result);
|
|
50
|
-
});
|
|
46
|
+
}, []);
|
|
51
47
|
return state;
|
|
52
48
|
}
|
|
53
49
|
|
|
@@ -65,11 +61,11 @@ function createRenderWithStore(store) {
|
|
|
65
61
|
}
|
|
66
62
|
|
|
67
63
|
// src/use_store.tsx
|
|
68
|
-
var
|
|
64
|
+
var import_react2 = require("react");
|
|
69
65
|
var import_immer = require("immer");
|
|
70
66
|
function useStore(initialState) {
|
|
71
|
-
const stateRef = (0,
|
|
72
|
-
const subscribers = (0,
|
|
67
|
+
const stateRef = (0, import_react2.useRef)(initialState);
|
|
68
|
+
const subscribers = (0, import_react2.useRef)([]);
|
|
73
69
|
const dispatch = (recipe, options = {}) => {
|
|
74
70
|
if (typeof recipe === "function") {
|
|
75
71
|
stateRef.current = (0, import_immer.produce)(stateRef.current, recipe);
|
|
@@ -116,6 +112,19 @@ var import_date_fns = require("date-fns");
|
|
|
116
112
|
|
|
117
113
|
// src/use_store_controller.tsx
|
|
118
114
|
var import_react4 = require("react");
|
|
115
|
+
|
|
116
|
+
// src/use_subscribe.tsx
|
|
117
|
+
var import_react3 = require("react");
|
|
118
|
+
function useSubscribe(store, subscriber) {
|
|
119
|
+
(0, import_react3.useEffect)(() => {
|
|
120
|
+
const unsubscribe = store.subscribe(subscriber);
|
|
121
|
+
return () => {
|
|
122
|
+
unsubscribe();
|
|
123
|
+
};
|
|
124
|
+
}, []);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/use_store_controller.tsx
|
|
119
128
|
function useStoreController(store, props) {
|
|
120
129
|
const dispatchKey = (0, import_react4.useId)();
|
|
121
130
|
useSubscribe(store, (state, key) => {
|
package/dist/use_form_store.mjs
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
// src/use_selector.tsx
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function useSubscribe(store, subscriber) {
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
4
|
+
const [state, setState] = useState(selector(store.state));
|
|
5
|
+
const stateRef = useRef(state);
|
|
7
6
|
useEffect(() => {
|
|
8
|
-
|
|
7
|
+
stateRef.current = state;
|
|
8
|
+
}, [state]);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
11
|
+
const result = selector(newState);
|
|
12
|
+
if (compare(stateRef.current, result)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setState(result);
|
|
16
|
+
});
|
|
9
17
|
return () => {
|
|
10
18
|
unsubscribe();
|
|
11
19
|
};
|
|
12
|
-
}, [
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/use_selector.tsx
|
|
16
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
17
|
-
const [state, setState] = useState(selector(store.state));
|
|
18
|
-
useSubscribe(store, (newState) => {
|
|
19
|
-
const result = selector(newState);
|
|
20
|
-
if (compare(state, result)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
setState(result);
|
|
24
|
-
});
|
|
20
|
+
}, []);
|
|
25
21
|
return state;
|
|
26
22
|
}
|
|
27
23
|
|
|
@@ -39,11 +35,11 @@ function createRenderWithStore(store) {
|
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
// src/use_store.tsx
|
|
42
|
-
import { useRef } from "react";
|
|
38
|
+
import { useRef as useRef2 } from "react";
|
|
43
39
|
import { produce } from "immer";
|
|
44
40
|
function useStore(initialState) {
|
|
45
|
-
const stateRef =
|
|
46
|
-
const subscribers =
|
|
41
|
+
const stateRef = useRef2(initialState);
|
|
42
|
+
const subscribers = useRef2([]);
|
|
47
43
|
const dispatch = (recipe, options = {}) => {
|
|
48
44
|
if (typeof recipe === "function") {
|
|
49
45
|
stateRef.current = produce(stateRef.current, recipe);
|
|
@@ -83,13 +79,26 @@ function useStore(initialState) {
|
|
|
83
79
|
}
|
|
84
80
|
|
|
85
81
|
// src/use_store_component.tsx
|
|
86
|
-
import { useCallback, useRef as
|
|
82
|
+
import { useCallback, useRef as useRef3 } from "react";
|
|
87
83
|
|
|
88
84
|
// src/use_store_input.tsx
|
|
89
85
|
import { format } from "date-fns";
|
|
90
86
|
|
|
91
87
|
// src/use_store_controller.tsx
|
|
92
88
|
import { useId } from "react";
|
|
89
|
+
|
|
90
|
+
// src/use_subscribe.tsx
|
|
91
|
+
import { useEffect as useEffect2 } from "react";
|
|
92
|
+
function useSubscribe(store, subscriber) {
|
|
93
|
+
useEffect2(() => {
|
|
94
|
+
const unsubscribe = store.subscribe(subscriber);
|
|
95
|
+
return () => {
|
|
96
|
+
unsubscribe();
|
|
97
|
+
};
|
|
98
|
+
}, []);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/use_store_controller.tsx
|
|
93
102
|
function useStoreController(store, props) {
|
|
94
103
|
const dispatchKey = useId();
|
|
95
104
|
useSubscribe(store, (state, key) => {
|
|
@@ -254,7 +263,7 @@ function Input({
|
|
|
254
263
|
toStateValue,
|
|
255
264
|
...props
|
|
256
265
|
}) {
|
|
257
|
-
const ref =
|
|
266
|
+
const ref = useRef3(null);
|
|
258
267
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
259
268
|
...props,
|
|
260
269
|
getter,
|
|
@@ -272,7 +281,7 @@ function Select({
|
|
|
272
281
|
toStateValue,
|
|
273
282
|
...props
|
|
274
283
|
}) {
|
|
275
|
-
const ref =
|
|
284
|
+
const ref = useRef3(null);
|
|
276
285
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
277
286
|
...props,
|
|
278
287
|
getter,
|
|
@@ -290,7 +299,7 @@ function Textarea({
|
|
|
290
299
|
toStateValue,
|
|
291
300
|
...props
|
|
292
301
|
}) {
|
|
293
|
-
const ref =
|
|
302
|
+
const ref = useRef3(null);
|
|
294
303
|
const storeProps = useStoreInputWithName(ref, store, {
|
|
295
304
|
...props,
|
|
296
305
|
getter,
|
package/dist/use_selector.js
CHANGED
|
@@ -23,29 +23,25 @@ __export(use_selector_exports, {
|
|
|
23
23
|
useSelector: () => useSelector
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(use_selector_exports);
|
|
26
|
-
var import_react2 = require("react");
|
|
27
|
-
|
|
28
|
-
// src/use_subscribe.tsx
|
|
29
26
|
var import_react = require("react");
|
|
30
|
-
function
|
|
27
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
28
|
+
const [state, setState] = (0, import_react.useState)(selector(store.state));
|
|
29
|
+
const stateRef = (0, import_react.useRef)(state);
|
|
31
30
|
(0, import_react.useEffect)(() => {
|
|
32
|
-
|
|
31
|
+
stateRef.current = state;
|
|
32
|
+
}, [state]);
|
|
33
|
+
(0, import_react.useEffect)(() => {
|
|
34
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
35
|
+
const result = selector(newState);
|
|
36
|
+
if (compare(stateRef.current, result)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
setState(result);
|
|
40
|
+
});
|
|
33
41
|
return () => {
|
|
34
42
|
unsubscribe();
|
|
35
43
|
};
|
|
36
|
-
}, [
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// src/use_selector.tsx
|
|
40
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
41
|
-
const [state, setState] = (0, import_react2.useState)(selector(store.state));
|
|
42
|
-
useSubscribe(store, (newState) => {
|
|
43
|
-
const result = selector(newState);
|
|
44
|
-
if (compare(state, result)) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
setState(result);
|
|
48
|
-
});
|
|
44
|
+
}, []);
|
|
49
45
|
return state;
|
|
50
46
|
}
|
|
51
47
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/use_selector.mjs
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
// src/use_selector.tsx
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function useSubscribe(store, subscriber) {
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
4
|
+
const [state, setState] = useState(selector(store.state));
|
|
5
|
+
const stateRef = useRef(state);
|
|
7
6
|
useEffect(() => {
|
|
8
|
-
|
|
7
|
+
stateRef.current = state;
|
|
8
|
+
}, [state]);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
const unsubscribe = store.subscribe((newState) => {
|
|
11
|
+
const result = selector(newState);
|
|
12
|
+
if (compare(stateRef.current, result)) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
setState(result);
|
|
16
|
+
});
|
|
9
17
|
return () => {
|
|
10
18
|
unsubscribe();
|
|
11
19
|
};
|
|
12
|
-
}, [
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// src/use_selector.tsx
|
|
16
|
-
function useSelector(store, selector, compare = (a, b) => a === b) {
|
|
17
|
-
const [state, setState] = useState(selector(store.state));
|
|
18
|
-
useSubscribe(store, (newState) => {
|
|
19
|
-
const result = selector(newState);
|
|
20
|
-
if (compare(state, result)) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
setState(result);
|
|
24
|
-
});
|
|
20
|
+
}, []);
|
|
25
21
|
return state;
|
|
26
22
|
}
|
|
27
23
|
export {
|
package/dist/use_store_input.js
CHANGED
package/dist/use_store_input.mjs
CHANGED
|
@@ -11,7 +11,7 @@ declare function useStoreInputWithName<TInputElement extends HTMLInputElement |
|
|
|
11
11
|
name: string | undefined;
|
|
12
12
|
defaultValue: string | number | readonly string[] | undefined;
|
|
13
13
|
defaultChecked: boolean | undefined;
|
|
14
|
-
onChange: (event: react.ChangeEvent<TInputElement>) => void;
|
|
14
|
+
onChange: (event: react.ChangeEvent<TInputElement, Element>) => void;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export { type InferNameFromProps, type StoreInputWithNameProps, useStoreInputWithName };
|
|
@@ -11,7 +11,7 @@ declare function useStoreInputWithName<TInputElement extends HTMLInputElement |
|
|
|
11
11
|
name: string | undefined;
|
|
12
12
|
defaultValue: string | number | readonly string[] | undefined;
|
|
13
13
|
defaultChecked: boolean | undefined;
|
|
14
|
-
onChange: (event: react.ChangeEvent<TInputElement>) => void;
|
|
14
|
+
onChange: (event: react.ChangeEvent<TInputElement, Element>) => void;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export { type InferNameFromProps, type StoreInputWithNameProps, useStoreInputWithName };
|
package/dist/use_subscribe.js
CHANGED
package/dist/use_subscribe.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-store-input",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"types": "./dist/index.d.ts",
|
|
5
5
|
"main": "./dist/index.mjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"description": "",
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^24.10.1",
|
|
32
|
-
"@types/react": "^18.3.1",
|
|
33
|
-
"@types/react-dom": "^18.3.1",
|
|
32
|
+
"@types/react": "^18.3.1 || ^19.2.1",
|
|
33
|
+
"@types/react-dom": "^18.3.1 || ^19.2.1",
|
|
34
34
|
"tsup": "^8.5.1",
|
|
35
35
|
"typescript": "^5.7.3"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"react": "^18.3.1",
|
|
39
|
-
"react-dom": "^18.3.1"
|
|
38
|
+
"react": "^18.3.1 || ^19.2.1",
|
|
39
|
+
"react-dom": "^18.3.1 || ^19.2.1"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"date-fns": "^4.1.0",
|