@tanstack/react-store 0.0.1-beta.121 → 0.0.1-beta.147
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/build/cjs/index.js +0 -43
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +0 -43
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +19 -33
- package/build/umd/index.development.js +20 -49
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +0 -44
package/build/cjs/index.js
CHANGED
|
@@ -12,54 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
require('react');
|
|
16
15
|
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
17
16
|
var store = require('@tanstack/store');
|
|
18
17
|
|
|
19
18
|
function useStore(store, selector = d => d) {
|
|
20
|
-
// const isMountedRef = React.useRef(false)
|
|
21
|
-
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
|
|
22
|
-
// ref: selector(store.state),
|
|
23
|
-
// }))
|
|
24
|
-
|
|
25
|
-
// if (!shallow(selector(store.state), state.ref)) {
|
|
26
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// useLayoutEffect(() => {
|
|
30
|
-
// console.log('effect')
|
|
31
|
-
|
|
32
|
-
// const cb = () => {
|
|
33
|
-
// const next = selector(store.state)
|
|
34
|
-
// console.log('onsub')
|
|
35
|
-
// if (!shallow(next, state.ref)) {
|
|
36
|
-
// console.log('set')
|
|
37
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
38
|
-
// }
|
|
39
|
-
// }
|
|
40
|
-
|
|
41
|
-
// return store.subscribe(cb)
|
|
42
|
-
// }, [])
|
|
43
|
-
|
|
44
19
|
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
|
|
45
|
-
|
|
46
|
-
// if (!isMountedRef.current) {
|
|
47
|
-
// state.ref = slice
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// if (!shallow(slice, state.ref)) {
|
|
51
|
-
// setState({ ref: slice })
|
|
52
|
-
// }
|
|
53
|
-
|
|
54
|
-
// React.useEffect(() => {
|
|
55
|
-
// isMountedRef.current = true
|
|
56
|
-
// return () => {
|
|
57
|
-
// isMountedRef.current = false
|
|
58
|
-
// }
|
|
59
|
-
// }, [])
|
|
60
|
-
|
|
61
|
-
// return state.ref
|
|
62
|
-
|
|
63
20
|
return slice;
|
|
64
21
|
}
|
|
65
22
|
function shallow(objA, objB) {
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":["useStore","store","selector","d","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;;;;;AAQO,SAASA,QAAQA,CAKtBC,KAA8B,EAC9BC,QAA+C,GAAIC,CAAC,IAAKA,CAAQ,EACjE;EACA,MAAMC,KAAK,GAAGC,6CAAgC,CAC5CJ,KAAK,CAACK,SAAS,EACf,MAAML,KAAK,CAACM,KAAK,EACjB,MAAMN,KAAK,CAACM,KAAK,EACjBL,QAAQ,EACRM,OACF,CAAC,CAAA;AAED,EAAA,OAAOJ,KAAK,CAAA;AACd,CAAA;AAEO,SAASI,OAAOA,CAAIC,IAAO,EAAEC,IAAO,EAAE;EAC3C,IAAIC,MAAM,CAACC,EAAE,CAACH,IAAI,EAAEC,IAAI,CAAC,EAAE;AACzB,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AAEA,EAAA,IACE,OAAOD,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,IACb,OAAOC,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;AACA,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,MAAMG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAACL,IAAI,CAAC,CAAA;AAC/B,EAAA,IAAII,KAAK,CAACE,MAAM,KAAKJ,MAAM,CAACG,IAAI,CAACJ,IAAI,CAAC,CAACK,MAAM,EAAE;AAC7C,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACE,MAAM,EAAEC,CAAC,EAAE,EAAE;AACrC,IAAA,IACE,CAACL,MAAM,CAACM,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,IAAI,EAAEG,KAAK,CAACG,CAAC,CAAW,CAAC,IAC/D,CAACL,MAAM,CAACC,EAAE,CAACH,IAAI,CAACI,KAAK,CAACG,CAAC,CAAC,CAAY,EAAEN,IAAI,CAACG,KAAK,CAACG,CAAC,CAAC,CAAY,CAAC,EAChE;AACA,MAAA,OAAO,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,OAAO,IAAI,CAAA;AACb;;;;;;;;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -8,54 +8,11 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import 'react';
|
|
12
11
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
13
12
|
export * from '@tanstack/store';
|
|
14
13
|
|
|
15
14
|
function useStore(store, selector = d => d) {
|
|
16
|
-
// const isMountedRef = React.useRef(false)
|
|
17
|
-
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
|
|
18
|
-
// ref: selector(store.state),
|
|
19
|
-
// }))
|
|
20
|
-
|
|
21
|
-
// if (!shallow(selector(store.state), state.ref)) {
|
|
22
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
// useLayoutEffect(() => {
|
|
26
|
-
// console.log('effect')
|
|
27
|
-
|
|
28
|
-
// const cb = () => {
|
|
29
|
-
// const next = selector(store.state)
|
|
30
|
-
// console.log('onsub')
|
|
31
|
-
// if (!shallow(next, state.ref)) {
|
|
32
|
-
// console.log('set')
|
|
33
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
34
|
-
// }
|
|
35
|
-
// }
|
|
36
|
-
|
|
37
|
-
// return store.subscribe(cb)
|
|
38
|
-
// }, [])
|
|
39
|
-
|
|
40
15
|
const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
|
|
41
|
-
|
|
42
|
-
// if (!isMountedRef.current) {
|
|
43
|
-
// state.ref = slice
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// if (!shallow(slice, state.ref)) {
|
|
47
|
-
// setState({ ref: slice })
|
|
48
|
-
// }
|
|
49
|
-
|
|
50
|
-
// React.useEffect(() => {
|
|
51
|
-
// isMountedRef.current = true
|
|
52
|
-
// return () => {
|
|
53
|
-
// isMountedRef.current = false
|
|
54
|
-
// }
|
|
55
|
-
// }, [])
|
|
56
|
-
|
|
57
|
-
// return state.ref
|
|
58
|
-
|
|
59
16
|
return slice;
|
|
60
17
|
}
|
|
61
18
|
function shallow(objA, objB) {
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":["useStore","store","selector","d","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call"],"mappings":";;;;;;;;;;;;;AAQO,SAASA,QAAQA,CAKtBC,KAA8B,EAC9BC,QAA+C,GAAIC,CAAC,IAAKA,CAAQ,EACjE;EACA,MAAMC,KAAK,GAAGC,gCAAgC,CAC5CJ,KAAK,CAACK,SAAS,EACf,MAAML,KAAK,CAACM,KAAK,EACjB,MAAMN,KAAK,CAACM,KAAK,EACjBL,QAAQ,EACRM,OACF,CAAC,CAAA;AAED,EAAA,OAAOJ,KAAK,CAAA;AACd,CAAA;AAEO,SAASI,OAAOA,CAAIC,IAAO,EAAEC,IAAO,EAAE;EAC3C,IAAIC,MAAM,CAACC,EAAE,CAACH,IAAI,EAAEC,IAAI,CAAC,EAAE;AACzB,IAAA,OAAO,IAAI,CAAA;AACb,GAAA;AAEA,EAAA,IACE,OAAOD,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,IACb,OAAOC,IAAI,KAAK,QAAQ,IACxBA,IAAI,KAAK,IAAI,EACb;AACA,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,MAAMG,KAAK,GAAGF,MAAM,CAACG,IAAI,CAACL,IAAI,CAAC,CAAA;AAC/B,EAAA,IAAII,KAAK,CAACE,MAAM,KAAKJ,MAAM,CAACG,IAAI,CAACJ,IAAI,CAAC,CAACK,MAAM,EAAE;AAC7C,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;AAEA,EAAA,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,KAAK,CAACE,MAAM,EAAEC,CAAC,EAAE,EAAE;AACrC,IAAA,IACE,CAACL,MAAM,CAACM,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,IAAI,EAAEG,KAAK,CAACG,CAAC,CAAW,CAAC,IAC/D,CAACL,MAAM,CAACC,EAAE,CAACH,IAAI,CAACI,KAAK,CAACG,CAAC,CAAC,CAAY,EAAEN,IAAI,CAACG,KAAK,CAACG,CAAC,CAAC,CAAY,CAAC,EAChE;AACA,MAAA,OAAO,KAAK,CAAA;AACd,KAAA;AACF,GAAA;AACA,EAAA,OAAO,IAAI,CAAA;AACb;;;;"}
|
package/build/stats-html.html
CHANGED
|
@@ -4024,7 +4024,7 @@ var drawChart = (function (exports) {
|
|
|
4024
4024
|
</script>
|
|
4025
4025
|
<script>
|
|
4026
4026
|
/*<!--*/
|
|
4027
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"store/build/esm/index.js","uid":"
|
|
4027
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages","children":[{"name":"store/build/esm/index.js","uid":"c288-5"},{"name":"react-store/src/index.tsx","uid":"c288-7"}]}]}],"isRoot":true},"nodeParts":{"c288-5":{"renderedLength":1843,"gzipLength":644,"brotliLength":0,"mainUid":"c288-4"},"c288-7":{"renderedLength":754,"gzipLength":343,"brotliLength":0,"mainUid":"c288-6"}},"nodeMetas":{"c288-4":{"id":"/packages/store/build/esm/index.js","moduleParts":{"index.production.js":"c288-5"},"imported":[],"importedBy":[{"uid":"c288-6"}]},"c288-6":{"id":"/packages/react-store/src/index.tsx","moduleParts":{"index.production.js":"c288-7"},"imported":[{"uid":"c288-8"},{"uid":"c288-4"}],"importedBy":[],"isEntry":true},"c288-8":{"id":"use-sync-external-store/shim/with-selector","moduleParts":{},"imported":[],"importedBy":[{"uid":"c288-6"}],"isExternal":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
4028
4028
|
|
|
4029
4029
|
const run = () => {
|
|
4030
4030
|
const width = window.innerWidth;
|
package/build/stats-react.json
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"children": [
|
|
12
12
|
{
|
|
13
13
|
"name": "store/build/esm/index.js",
|
|
14
|
-
"uid": "
|
|
14
|
+
"uid": "c288-10"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
17
|
"name": "react-store/src/index.tsx",
|
|
18
|
-
"uid": "
|
|
18
|
+
"uid": "c288-12"
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
21
|
}
|
|
@@ -25,69 +25,55 @@
|
|
|
25
25
|
"isRoot": true
|
|
26
26
|
},
|
|
27
27
|
"nodeParts": {
|
|
28
|
-
"
|
|
29
|
-
"renderedLength":
|
|
30
|
-
"gzipLength":
|
|
28
|
+
"c288-10": {
|
|
29
|
+
"renderedLength": 1843,
|
|
30
|
+
"gzipLength": 644,
|
|
31
31
|
"brotliLength": 0,
|
|
32
|
-
"mainUid": "
|
|
32
|
+
"mainUid": "c288-9"
|
|
33
33
|
},
|
|
34
|
-
"
|
|
35
|
-
"renderedLength":
|
|
36
|
-
"gzipLength":
|
|
34
|
+
"c288-12": {
|
|
35
|
+
"renderedLength": 754,
|
|
36
|
+
"gzipLength": 343,
|
|
37
37
|
"brotliLength": 0,
|
|
38
|
-
"mainUid": "
|
|
38
|
+
"mainUid": "c288-11"
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
41
|
"nodeMetas": {
|
|
42
|
-
"
|
|
42
|
+
"c288-9": {
|
|
43
43
|
"id": "/packages/store/build/esm/index.js",
|
|
44
44
|
"moduleParts": {
|
|
45
|
-
"index.production.js": "
|
|
45
|
+
"index.production.js": "c288-10"
|
|
46
46
|
},
|
|
47
47
|
"imported": [],
|
|
48
48
|
"importedBy": [
|
|
49
49
|
{
|
|
50
|
-
"uid": "
|
|
50
|
+
"uid": "c288-11"
|
|
51
51
|
}
|
|
52
52
|
]
|
|
53
53
|
},
|
|
54
|
-
"
|
|
54
|
+
"c288-11": {
|
|
55
55
|
"id": "/packages/react-store/src/index.tsx",
|
|
56
56
|
"moduleParts": {
|
|
57
|
-
"index.production.js": "
|
|
57
|
+
"index.production.js": "c288-12"
|
|
58
58
|
},
|
|
59
59
|
"imported": [
|
|
60
60
|
{
|
|
61
|
-
"uid": "
|
|
61
|
+
"uid": "c288-13"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
|
-
"uid": "
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
"uid": "0fb9-10"
|
|
64
|
+
"uid": "c288-9"
|
|
68
65
|
}
|
|
69
66
|
],
|
|
70
67
|
"importedBy": [],
|
|
71
68
|
"isEntry": true
|
|
72
69
|
},
|
|
73
|
-
"
|
|
74
|
-
"id": "react",
|
|
75
|
-
"moduleParts": {},
|
|
76
|
-
"imported": [],
|
|
77
|
-
"importedBy": [
|
|
78
|
-
{
|
|
79
|
-
"uid": "0fb9-12"
|
|
80
|
-
}
|
|
81
|
-
],
|
|
82
|
-
"isExternal": true
|
|
83
|
-
},
|
|
84
|
-
"0fb9-15": {
|
|
70
|
+
"c288-13": {
|
|
85
71
|
"id": "use-sync-external-store/shim/with-selector",
|
|
86
72
|
"moduleParts": {},
|
|
87
73
|
"imported": [],
|
|
88
74
|
"importedBy": [
|
|
89
75
|
{
|
|
90
|
-
"uid": "
|
|
76
|
+
"uid": "c288-11"
|
|
91
77
|
}
|
|
92
78
|
],
|
|
93
79
|
"isExternal": true
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
(function (global, factory) {
|
|
12
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('
|
|
13
|
-
typeof define === 'function' && define.amd ? define(['exports', '
|
|
14
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.
|
|
15
|
-
})(this, (function (exports,
|
|
12
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('use-sync-external-store/shim/with-selector')) :
|
|
13
|
+
typeof define === 'function' && define.amd ? define(['exports', 'use-sync-external-store/shim/with-selector'], factory) :
|
|
14
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.withSelector));
|
|
15
|
+
})(this, (function (exports, withSelector) { 'use strict';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @tanstack/store/src/index.ts
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
listeners = new Set();
|
|
29
29
|
_batching = false;
|
|
30
30
|
_flushing = 0;
|
|
31
|
+
_nextPriority = null;
|
|
31
32
|
constructor(initialState, options) {
|
|
32
33
|
this.state = initialState;
|
|
33
34
|
this.options = options;
|
|
@@ -40,12 +41,22 @@
|
|
|
40
41
|
unsub?.();
|
|
41
42
|
};
|
|
42
43
|
};
|
|
43
|
-
setState = updater => {
|
|
44
|
+
setState = (updater, opts) => {
|
|
44
45
|
const previous = this.state;
|
|
45
46
|
this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);
|
|
47
|
+
const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';
|
|
48
|
+
if (this._nextPriority === null) {
|
|
49
|
+
this._nextPriority = priority;
|
|
50
|
+
} else if (this._nextPriority === 'high') {
|
|
51
|
+
this._nextPriority = priority;
|
|
52
|
+
} else {
|
|
53
|
+
this._nextPriority = this.options?.defaultPriority ?? 'high';
|
|
54
|
+
}
|
|
46
55
|
|
|
47
56
|
// Always run onUpdate, regardless of batching
|
|
48
|
-
this.options?.onUpdate?.(
|
|
57
|
+
this.options?.onUpdate?.({
|
|
58
|
+
priority: this._nextPriority
|
|
59
|
+
});
|
|
49
60
|
|
|
50
61
|
// Attempt to flush
|
|
51
62
|
this._flush();
|
|
@@ -55,7 +66,9 @@
|
|
|
55
66
|
const flushId = ++this._flushing;
|
|
56
67
|
this.listeners.forEach(listener => {
|
|
57
68
|
if (this._flushing !== flushId) return;
|
|
58
|
-
listener(
|
|
69
|
+
listener({
|
|
70
|
+
priority: this._nextPriority ?? 'high'
|
|
71
|
+
});
|
|
59
72
|
});
|
|
60
73
|
};
|
|
61
74
|
batch = cb => {
|
|
@@ -68,49 +81,7 @@
|
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
function useStore(store, selector = d => d) {
|
|
71
|
-
// const isMountedRef = React.useRef(false)
|
|
72
|
-
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
|
|
73
|
-
// ref: selector(store.state),
|
|
74
|
-
// }))
|
|
75
|
-
|
|
76
|
-
// if (!shallow(selector(store.state), state.ref)) {
|
|
77
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
78
|
-
// }
|
|
79
|
-
|
|
80
|
-
// useLayoutEffect(() => {
|
|
81
|
-
// console.log('effect')
|
|
82
|
-
|
|
83
|
-
// const cb = () => {
|
|
84
|
-
// const next = selector(store.state)
|
|
85
|
-
// console.log('onsub')
|
|
86
|
-
// if (!shallow(next, state.ref)) {
|
|
87
|
-
// console.log('set')
|
|
88
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
89
|
-
// }
|
|
90
|
-
// }
|
|
91
|
-
|
|
92
|
-
// return store.subscribe(cb)
|
|
93
|
-
// }, [])
|
|
94
|
-
|
|
95
84
|
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
|
|
96
|
-
|
|
97
|
-
// if (!isMountedRef.current) {
|
|
98
|
-
// state.ref = slice
|
|
99
|
-
// }
|
|
100
|
-
|
|
101
|
-
// if (!shallow(slice, state.ref)) {
|
|
102
|
-
// setState({ ref: slice })
|
|
103
|
-
// }
|
|
104
|
-
|
|
105
|
-
// React.useEffect(() => {
|
|
106
|
-
// isMountedRef.current = true
|
|
107
|
-
// return () => {
|
|
108
|
-
// isMountedRef.current = false
|
|
109
|
-
// }
|
|
110
|
-
// }, [])
|
|
111
|
-
|
|
112
|
-
// return state.ref
|
|
113
|
-
|
|
114
85
|
return slice;
|
|
115
86
|
}
|
|
116
87
|
function shallow(objA, objB) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../../store/build/esm/index.js","../../src/index.tsx"],"sourcesContent":["/**\n * @tanstack/store/src/index.ts\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n _batching = false;\n _flushing = 0;\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = updater => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.();\n\n // Attempt to flush\n this._flush();\n };\n _flush = () => {\n if (this._batching) return;\n const flushId = ++this._flushing;\n this.listeners.forEach(listener => {\n if (this._flushing !== flushId) return;\n listener();\n });\n };\n batch = cb => {\n if (this._batching) return cb();\n this._batching = true;\n cb();\n this._batching = false;\n this._flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n","import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../../store/build/esm/index.js","../../src/index.tsx"],"sourcesContent":["/**\n * @tanstack/store/src/index.ts\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n _batching = false;\n _flushing = 0;\n _nextPriority = null;\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = (updater, opts) => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';\n if (this._nextPriority === null) {\n this._nextPriority = priority;\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority;\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high';\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority\n });\n\n // Attempt to flush\n this._flush();\n };\n _flush = () => {\n if (this._batching) return;\n const flushId = ++this._flushing;\n this.listeners.forEach(listener => {\n if (this._flushing !== flushId) return;\n listener({\n priority: this._nextPriority ?? 'high'\n });\n });\n };\n batch = cb => {\n if (this._batching) return cb();\n this._batching = true;\n cb();\n this._batching = false;\n this._flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n","import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n"],"names":["useStore","store","selector","d","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call"],"mappings":"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"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("
|
|
11
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactLoaders={},t.withSelector)}(this,(function(t,e){"use strict";
|
|
12
12
|
/**
|
|
13
13
|
* @tanstack/store/src/index.ts
|
|
14
14
|
*
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
* LICENSE.md file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
20
|
* @license MIT
|
|
21
|
-
*/function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const
|
|
21
|
+
*/function i(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const i=Object.keys(t);if(i.length!==Object.keys(e).length)return!1;for(let s=0;s<i.length;s++)if(!Object.prototype.hasOwnProperty.call(e,i[s])||!Object.is(t[i[s]],e[i[s]]))return!1;return!0}t.Store=class{listeners=new Set;_batching=!1;_flushing=0;_nextPriority=null;constructor(t,e){this.state=t,this.options=e}subscribe=t=>{this.listeners.add(t);const e=this.options?.onSubscribe?.(t,this);return()=>{this.listeners.delete(t),e?.()}};setState=(t,e)=>{const i=this.state;this.state=this.options?.updateFn?this.options.updateFn(i)(t):t(i);const s=e?.priority??this.options?.defaultPriority??"high";null===this._nextPriority||"high"===this._nextPriority?this._nextPriority=s:this._nextPriority=this.options?.defaultPriority??"high",this.options?.onUpdate?.({priority:this._nextPriority}),this._flush()};_flush=()=>{if(this._batching)return;const t=++this._flushing;this.listeners.forEach((e=>{this._flushing===t&&e({priority:this._nextPriority??"high"})}))};batch=t=>{if(this._batching)return t();this._batching=!0,t(),this._batching=!1,this._flush()}},t.shallow=i,t.useStore=function(t,s=(t=>t)){return e.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),s,i)},Object.defineProperty(t,"__esModule",{value:!0})}));
|
|
22
22
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/index.tsx","../../../store/build/esm/index.js"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/index.tsx","../../../store/build/esm/index.js"],"sourcesContent":["import * as React from 'react'\nimport { AnyUpdater, Store } from '@tanstack/store'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport * from '@tanstack/store'\n\nexport type NoInfer<T> = [T][T extends any ? 0 : never]\n\nexport function useStore<\n TState,\n TSelected = NoInfer<TState>,\n TUpdater extends AnyUpdater = AnyUpdater,\n>(\n store: Store<TState, TUpdater>,\n selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n shallow,\n )\n\n return slice\n}\n\nexport function shallow<T>(objA: T, objB: T) {\n if (Object.is(objA, objB)) {\n return true\n }\n\n if (\n typeof objA !== 'object' ||\n objA === null ||\n typeof objB !== 'object' ||\n objB === null\n ) {\n return false\n }\n\n const keysA = Object.keys(objA)\n if (keysA.length !== Object.keys(objB).length) {\n return false\n }\n\n for (let i = 0; i < keysA.length; i++) {\n if (\n !Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||\n !Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])\n ) {\n return false\n }\n }\n return true\n}\n","/**\n * @tanstack/store/src/index.ts\n *\n * Copyright (c) TanStack\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE.md file in the root directory of this source tree.\n *\n * @license MIT\n */\nclass Store {\n listeners = new Set();\n _batching = false;\n _flushing = 0;\n _nextPriority = null;\n constructor(initialState, options) {\n this.state = initialState;\n this.options = options;\n }\n subscribe = listener => {\n this.listeners.add(listener);\n const unsub = this.options?.onSubscribe?.(listener, this);\n return () => {\n this.listeners.delete(listener);\n unsub?.();\n };\n };\n setState = (updater, opts) => {\n const previous = this.state;\n this.state = this.options?.updateFn ? this.options.updateFn(previous)(updater) : updater(previous);\n const priority = opts?.priority ?? this.options?.defaultPriority ?? 'high';\n if (this._nextPriority === null) {\n this._nextPriority = priority;\n } else if (this._nextPriority === 'high') {\n this._nextPriority = priority;\n } else {\n this._nextPriority = this.options?.defaultPriority ?? 'high';\n }\n\n // Always run onUpdate, regardless of batching\n this.options?.onUpdate?.({\n priority: this._nextPriority\n });\n\n // Attempt to flush\n this._flush();\n };\n _flush = () => {\n if (this._batching) return;\n const flushId = ++this._flushing;\n this.listeners.forEach(listener => {\n if (this._flushing !== flushId) return;\n listener({\n priority: this._nextPriority ?? 'high'\n });\n });\n };\n batch = cb => {\n if (this._batching) return cb();\n this._batching = true;\n cb();\n this._batching = false;\n this._flush();\n };\n}\n\nexport { Store };\n//# sourceMappingURL=index.js.map\n"],"names":["shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call","listeners","Set","_batching","_flushing","_nextPriority","constructor","initialState","options","this","state","subscribe","listener","add","unsub","onSubscribe","delete","setState","updater","opts","previous","updateFn","priority","defaultPriority","onUpdate","_flush","flushId","forEach","batch","cb","store","selector","d","useSyncExternalStoreWithSelector"],"mappings":";;;;;;;;;;;;;;;;;;;;KA2BO,SAASA,EAAWC,EAASC,GAClC,GAAIC,OAAOC,GAAGH,EAAMC,GAClB,OAAO,EAGT,GACkB,iBAATD,GACE,OAATA,GACgB,iBAATC,GACE,OAATA,EAEA,OAAO,EAGT,MAAMG,EAAQF,OAAOG,KAAKL,GAC1B,GAAII,EAAME,SAAWJ,OAAOG,KAAKJ,GAAMK,OACrC,OAAO,EAGT,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAME,OAAQC,IAChC,IACGL,OAAOM,UAAUC,eAAeC,KAAKT,EAAMG,EAAMG,MACjDL,OAAOC,GAAGH,EAAKI,EAAMG,IAAgBN,EAAKG,EAAMG,KAEjD,OAAO,EAGX,OAAO,CACT,SC7CA,MACEI,UAAY,IAAIC,IAChBC,WAAY,EACZC,UAAY,EACZC,cAAgB,KAChBC,YAAYC,EAAcC,GACxBC,KAAKC,MAAQH,EACbE,KAAKD,QAAUA,CAChB,CACDG,UAAYC,IACVH,KAAKR,UAAUY,IAAID,GACnB,MAAME,EAAQL,KAAKD,SAASO,cAAcH,EAAUH,MACpD,MAAO,KACLA,KAAKR,UAAUe,OAAOJ,GACtBE,KAAS,CACV,EAEHG,SAAW,CAACC,EAASC,KACnB,MAAMC,EAAWX,KAAKC,MACtBD,KAAKC,MAAQD,KAAKD,SAASa,SAAWZ,KAAKD,QAAQa,SAASD,EAAtBX,CAAgCS,GAAWA,EAAQE,GACzF,MAAME,EAAWH,GAAMG,UAAYb,KAAKD,SAASe,iBAAmB,OACzC,OAAvBd,KAAKJ,eAEyB,SAAvBI,KAAKJ,cADdI,KAAKJ,cAAgBiB,EAIrBb,KAAKJ,cAAgBI,KAAKD,SAASe,iBAAmB,OAIxDd,KAAKD,SAASgB,WAAW,CACvBF,SAAUb,KAAKJ,gBAIjBI,KAAKgB,QAAQ,EAEfA,OAAS,KACP,GAAIhB,KAAKN,UAAW,OACpB,MAAMuB,IAAYjB,KAAKL,UACvBK,KAAKR,UAAU0B,SAAQf,IACjBH,KAAKL,YAAcsB,GACvBd,EAAS,CACPU,SAAUb,KAAKJ,eAAiB,QAChC,GACF,EAEJuB,MAAQC,IACN,GAAIpB,KAAKN,UAAW,OAAO0B,IAC3BpB,KAAKN,WAAY,EACjB0B,IACApB,KAAKN,WAAY,EACjBM,KAAKgB,QAAQ,0BDtDV,SAKLK,EACAC,EAAmDC,IAAMA,IAUzD,OARcC,EAAAA,iCACZH,EAAMnB,WACN,IAAMmB,EAAMpB,QACZ,IAAMoB,EAAMpB,OACZqB,EACA1C,EAIJ"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-store",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.0.1-beta.
|
|
4
|
+
"version": "0.0.1-beta.147",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "tanstack/react-store",
|
|
7
7
|
"homepage": "https://tanstack.com/",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"use-sync-external-store": "^1.2.0",
|
|
39
|
-
"@tanstack/store": "0.0.1-beta.
|
|
39
|
+
"@tanstack/store": "0.0.1-beta.147"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/use-sync-external-store": "^0.0.3"
|
package/src/index.tsx
CHANGED
|
@@ -6,9 +6,6 @@ export * from '@tanstack/store'
|
|
|
6
6
|
|
|
7
7
|
export type NoInfer<T> = [T][T extends any ? 0 : never]
|
|
8
8
|
|
|
9
|
-
const useLayoutEffect =
|
|
10
|
-
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect
|
|
11
|
-
|
|
12
9
|
export function useStore<
|
|
13
10
|
TState,
|
|
14
11
|
TSelected = NoInfer<TState>,
|
|
@@ -17,30 +14,6 @@ export function useStore<
|
|
|
17
14
|
store: Store<TState, TUpdater>,
|
|
18
15
|
selector: (state: NoInfer<TState>) => TSelected = (d) => d as any,
|
|
19
16
|
) {
|
|
20
|
-
// const isMountedRef = React.useRef(false)
|
|
21
|
-
// const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
|
|
22
|
-
// ref: selector(store.state),
|
|
23
|
-
// }))
|
|
24
|
-
|
|
25
|
-
// if (!shallow(selector(store.state), state.ref)) {
|
|
26
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// useLayoutEffect(() => {
|
|
30
|
-
// console.log('effect')
|
|
31
|
-
|
|
32
|
-
// const cb = () => {
|
|
33
|
-
// const next = selector(store.state)
|
|
34
|
-
// console.log('onsub')
|
|
35
|
-
// if (!shallow(next, state.ref)) {
|
|
36
|
-
// console.log('set')
|
|
37
|
-
// setState(() => ({ ref: selector(store.state) }))
|
|
38
|
-
// }
|
|
39
|
-
// }
|
|
40
|
-
|
|
41
|
-
// return store.subscribe(cb)
|
|
42
|
-
// }, [])
|
|
43
|
-
|
|
44
17
|
const slice = useSyncExternalStoreWithSelector(
|
|
45
18
|
store.subscribe,
|
|
46
19
|
() => store.state,
|
|
@@ -49,23 +22,6 @@ export function useStore<
|
|
|
49
22
|
shallow,
|
|
50
23
|
)
|
|
51
24
|
|
|
52
|
-
// if (!isMountedRef.current) {
|
|
53
|
-
// state.ref = slice
|
|
54
|
-
// }
|
|
55
|
-
|
|
56
|
-
// if (!shallow(slice, state.ref)) {
|
|
57
|
-
// setState({ ref: slice })
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// React.useEffect(() => {
|
|
61
|
-
// isMountedRef.current = true
|
|
62
|
-
// return () => {
|
|
63
|
-
// isMountedRef.current = false
|
|
64
|
-
// }
|
|
65
|
-
// }, [])
|
|
66
|
-
|
|
67
|
-
// return state.ref
|
|
68
|
-
|
|
69
25
|
return slice
|
|
70
26
|
}
|
|
71
27
|
|