@tanstack/react-store 0.0.1-beta.62 → 0.0.1-beta.81
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 +3 -43
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +1 -41
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +41 -11
- package/build/umd/index.development.js +15 -4
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +11 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +1 -52
package/build/cjs/index.js
CHANGED
|
@@ -12,53 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
+
var store = require('@tanstack/store');
|
|
15
16
|
var withSelector = require('use-sync-external-store/shim/with-selector');
|
|
16
17
|
|
|
17
|
-
function useStore(store, selector = d => d, compareShallow) {
|
|
18
|
-
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
|
|
18
|
+
function useStore(store$1, selector = d => d, compareShallow) {
|
|
19
|
+
const slice = withSelector.useSyncExternalStoreWithSelector(store$1.subscribe, () => store$1.state, () => store$1.state, selector, compareShallow ? store.shallow : undefined);
|
|
19
20
|
return slice;
|
|
20
21
|
}
|
|
21
|
-
function shallow(objA, objB) {
|
|
22
|
-
if (Object.is(objA, objB)) {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
25
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// if (objA instanceof Map && objB instanceof Map) {
|
|
30
|
-
// if (objA.size !== objB.size) return false
|
|
31
|
-
|
|
32
|
-
// for (const [key, value] of objA) {
|
|
33
|
-
// if (!Object.is(value, objB.get(key))) {
|
|
34
|
-
// return false
|
|
35
|
-
// }
|
|
36
|
-
// }
|
|
37
|
-
// return true
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// if (objA instanceof Set && objB instanceof Set) {
|
|
41
|
-
// if (objA.size !== objB.size) return false
|
|
42
|
-
|
|
43
|
-
// for (const value of objA) {
|
|
44
|
-
// if (!objB.has(value)) {
|
|
45
|
-
// return false
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
// return true
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
|
-
const keysA = Object.keys(objA);
|
|
52
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
56
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
22
|
|
|
63
23
|
exports.useStore = useStore;
|
|
64
24
|
//# sourceMappingURL=index.js.map
|
package/build/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import { Store, AnyUpdater } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import { Store, AnyUpdater, shallow } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\n"],"names":["useStore","store","selector","d","compareShallow","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","undefined"],"mappings":";;;;;;;;;;;;;;;;;AAMO,SAASA,QAAQ,CAKtBC,OAA8B,EAC9BC,QAA+C,GAAIC,CAAC,IAAKA,CAAQ,EACjEC,cAAwB,EACxB;EACA,MAAMC,KAAK,GAAGC,6CAAgC,CAC5CL,OAAK,CAACM,SAAS,EACf,MAAMN,OAAK,CAACO,KAAK,EACjB,MAAMP,OAAK,CAACO,KAAK,EACjBN,QAAQ,EACRE,cAAc,GAAGK,aAAO,GAAGC,SAAS,CACrC,CAAA;AAED,EAAA,OAAOL,KAAK,CAAA;AACd;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -8,53 +8,13 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
+
import { shallow } from '@tanstack/store';
|
|
11
12
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector';
|
|
12
13
|
|
|
13
14
|
function useStore(store, selector = d => d, compareShallow) {
|
|
14
15
|
const slice = useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
|
|
15
16
|
return slice;
|
|
16
17
|
}
|
|
17
|
-
function shallow(objA, objB) {
|
|
18
|
-
if (Object.is(objA, objB)) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// if (objA instanceof Map && objB instanceof Map) {
|
|
26
|
-
// if (objA.size !== objB.size) return false
|
|
27
|
-
|
|
28
|
-
// for (const [key, value] of objA) {
|
|
29
|
-
// if (!Object.is(value, objB.get(key))) {
|
|
30
|
-
// return false
|
|
31
|
-
// }
|
|
32
|
-
// }
|
|
33
|
-
// return true
|
|
34
|
-
// }
|
|
35
|
-
|
|
36
|
-
// if (objA instanceof Set && objB instanceof Set) {
|
|
37
|
-
// if (objA.size !== objB.size) return false
|
|
38
|
-
|
|
39
|
-
// for (const value of objA) {
|
|
40
|
-
// if (!objB.has(value)) {
|
|
41
|
-
// return false
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// return true
|
|
45
|
-
// }
|
|
46
|
-
|
|
47
|
-
const keysA = Object.keys(objA);
|
|
48
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
52
|
-
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
18
|
|
|
59
19
|
export { useStore };
|
|
60
20
|
//# sourceMappingURL=index.js.map
|
package/build/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import { Store, AnyUpdater } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.tsx"],"sourcesContent":["import { Store, AnyUpdater, shallow } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\n"],"names":["useStore","store","selector","d","compareShallow","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","undefined"],"mappings":";;;;;;;;;;;;;AAMO,SAASA,QAAQ,CAKtBC,KAA8B,EAC9BC,QAA+C,GAAIC,CAAC,IAAKA,CAAQ,EACjEC,cAAwB,EACxB;EACA,MAAMC,KAAK,GAAGC,gCAAgC,CAC5CL,KAAK,CAACM,SAAS,EACf,MAAMN,KAAK,CAACO,KAAK,EACjB,MAAMP,KAAK,CAACO,KAAK,EACjBN,QAAQ,EACRE,cAAc,GAAGK,OAAO,GAAGC,SAAS,CACrC,CAAA;AAED,EAAA,OAAOL,KAAK,CAAA;AACd;;;;"}
|
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/react-store/src/index.tsx","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":"298b-87"},{"name":"react-store/src/index.tsx","uid":"298b-89"}]}]}],"isRoot":true},"nodeParts":{"298b-87":{"renderedLength":1310,"gzipLength":488,"brotliLength":0,"mainUid":"298b-86"},"298b-89":{"renderedLength":253,"gzipLength":171,"brotliLength":0,"mainUid":"298b-88"}},"nodeMetas":{"298b-86":{"id":"/packages/store/build/esm/index.js","moduleParts":{"index.production.js":"298b-87"},"imported":[],"importedBy":[{"uid":"298b-88"}]},"298b-88":{"id":"/packages/react-store/src/index.tsx","moduleParts":{"index.production.js":"298b-89"},"imported":[{"uid":"298b-86"},{"uid":"298b-90"}],"importedBy":[],"isEntry":true},"298b-90":{"id":"use-sync-external-store/shim/with-selector","moduleParts":{},"imported":[],"importedBy":[{"uid":"298b-88"}],"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
|
@@ -7,8 +7,17 @@
|
|
|
7
7
|
"name": "index.production.js",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"name": "packages
|
|
11
|
-
"
|
|
10
|
+
"name": "packages",
|
|
11
|
+
"children": [
|
|
12
|
+
{
|
|
13
|
+
"name": "store/build/esm/index.js",
|
|
14
|
+
"uid": "298b-92"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "react-store/src/index.tsx",
|
|
18
|
+
"uid": "298b-94"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
12
21
|
}
|
|
13
22
|
]
|
|
14
23
|
}
|
|
@@ -16,34 +25,55 @@
|
|
|
16
25
|
"isRoot": true
|
|
17
26
|
},
|
|
18
27
|
"nodeParts": {
|
|
19
|
-
"
|
|
20
|
-
"renderedLength":
|
|
21
|
-
"gzipLength":
|
|
28
|
+
"298b-92": {
|
|
29
|
+
"renderedLength": 1310,
|
|
30
|
+
"gzipLength": 488,
|
|
22
31
|
"brotliLength": 0,
|
|
23
|
-
"mainUid": "
|
|
32
|
+
"mainUid": "298b-91"
|
|
33
|
+
},
|
|
34
|
+
"298b-94": {
|
|
35
|
+
"renderedLength": 253,
|
|
36
|
+
"gzipLength": 171,
|
|
37
|
+
"brotliLength": 0,
|
|
38
|
+
"mainUid": "298b-93"
|
|
24
39
|
}
|
|
25
40
|
},
|
|
26
41
|
"nodeMetas": {
|
|
27
|
-
"
|
|
42
|
+
"298b-91": {
|
|
43
|
+
"id": "/packages/store/build/esm/index.js",
|
|
44
|
+
"moduleParts": {
|
|
45
|
+
"index.production.js": "298b-92"
|
|
46
|
+
},
|
|
47
|
+
"imported": [],
|
|
48
|
+
"importedBy": [
|
|
49
|
+
{
|
|
50
|
+
"uid": "298b-93"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"298b-93": {
|
|
28
55
|
"id": "/packages/react-store/src/index.tsx",
|
|
29
56
|
"moduleParts": {
|
|
30
|
-
"index.production.js": "
|
|
57
|
+
"index.production.js": "298b-94"
|
|
31
58
|
},
|
|
32
59
|
"imported": [
|
|
33
60
|
{
|
|
34
|
-
"uid": "
|
|
61
|
+
"uid": "298b-91"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"uid": "298b-95"
|
|
35
65
|
}
|
|
36
66
|
],
|
|
37
67
|
"importedBy": [],
|
|
38
68
|
"isEntry": true
|
|
39
69
|
},
|
|
40
|
-
"
|
|
70
|
+
"298b-95": {
|
|
41
71
|
"id": "use-sync-external-store/shim/with-selector",
|
|
42
72
|
"moduleParts": {},
|
|
43
73
|
"imported": [],
|
|
44
74
|
"importedBy": [
|
|
45
75
|
{
|
|
46
|
-
"uid": "
|
|
76
|
+
"uid": "298b-93"
|
|
47
77
|
}
|
|
48
78
|
],
|
|
49
79
|
"isExternal": true
|
|
@@ -14,10 +14,16 @@
|
|
|
14
14
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactLoaders = {}, global.withSelector));
|
|
15
15
|
})(this, (function (exports, withSelector) { 'use strict';
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* store
|
|
19
|
+
*
|
|
20
|
+
* Copyright (c) TanStack
|
|
21
|
+
*
|
|
22
|
+
* This source code is licensed under the MIT license found in the
|
|
23
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
24
|
+
*
|
|
25
|
+
* @license MIT
|
|
26
|
+
*/
|
|
21
27
|
function shallow(objA, objB) {
|
|
22
28
|
if (Object.is(objA, objB)) {
|
|
23
29
|
return true;
|
|
@@ -60,6 +66,11 @@
|
|
|
60
66
|
return true;
|
|
61
67
|
}
|
|
62
68
|
|
|
69
|
+
function useStore(store, selector = d => d, compareShallow) {
|
|
70
|
+
const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, compareShallow ? shallow : undefined);
|
|
71
|
+
return slice;
|
|
72
|
+
}
|
|
73
|
+
|
|
63
74
|
exports.useStore = useStore;
|
|
64
75
|
|
|
65
76
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../src/index.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../../store/build/esm/index.js","../../src/index.tsx"],"sourcesContent":["/**\n * store\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 queue = [];\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 if (this.state === previous) return;\n this.options?.onUpdate?.(this.state, previous);\n this.queue.push(() => {\n this.listeners.forEach(listener => listener(this.state, previous));\n });\n this.#flush();\n };\n #flush = () => {\n if (this.batching) return;\n this.queue.forEach(cb => cb());\n this.queue = [];\n };\n batch = cb => {\n this.batching = true;\n cb();\n this.batching = false;\n this.#flush();\n };\n}\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n\n // if (objA instanceof Map && objB instanceof Map) {\n // if (objA.size !== objB.size) return false\n\n // for (const [key, value] of objA) {\n // if (!Object.is(value, objB.get(key))) {\n // return false\n // }\n // }\n // return true\n // }\n\n // if (objA instanceof Set && objB instanceof Set) {\n // if (objA.size !== objB.size) return false\n\n // for (const value of objA) {\n // if (!objB.has(value)) {\n // return false\n // }\n // }\n // return true\n // }\n\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n\nexport { Store, shallow };\n//# sourceMappingURL=index.js.map\n","import { Store, AnyUpdater, shallow } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\n"],"names":["useStore","store","selector","d","compareShallow","slice","useSyncExternalStoreWithSelector","subscribe","state","shallow","undefined"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EAuCA,SAAS,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE;EAC7B,EAAE,IAAI,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE;EAC7B,IAAI,OAAO,IAAI,CAAC;EAChB,GAAG;EACH,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,EAAE;EAC9F,IAAI,OAAO,KAAK,CAAC;EACjB,GAAG;AACH;EACA;EACA;AACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACA;EACA;EACA;AACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACA;EACA,EAAE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;EAClC,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;EACjD,IAAI,OAAO,KAAK,CAAC;EACjB,GAAG;EACH,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;EACzC,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;EAC7G,MAAM,OAAO,KAAK,CAAC;EACnB,KAAK;EACL,GAAG;EACH,EAAE,OAAO,IAAI,CAAC;EACd;;EClFO,SAASA,QAAQ,CAKtBC,KAA8B,EAC9BC,QAA+C,GAAIC,CAAC,IAAKA,CAAQ,EACjEC,cAAwB,EACxB;IACA,MAAMC,KAAK,GAAGC,6CAAgC,CAC5CL,KAAK,CAACM,SAAS,EACf,MAAMN,KAAK,CAACO,KAAK,EACjB,MAAMP,KAAK,CAACO,KAAK,EACjBN,QAAQ,EACRE,cAAc,GAAGK,OAAO,GAAGC,SAAS,CACrC,CAAA;EAED,EAAA,OAAOL,KAAK,CAAA;EACd;;;;;;;;;;"}
|
|
@@ -8,5 +8,15 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactLoaders={},e.withSelector)}(this,(function(e,t){"use strict";
|
|
11
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("use-sync-external-store/shim/with-selector")):"function"==typeof define&&define.amd?define(["exports","use-sync-external-store/shim/with-selector"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactLoaders={},e.withSelector)}(this,(function(e,t){"use strict";
|
|
12
|
+
/**
|
|
13
|
+
* store
|
|
14
|
+
*
|
|
15
|
+
* Copyright (c) TanStack
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
* @license MIT
|
|
21
|
+
*/function n(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(let o=0;o<n.length;o++)if(!Object.prototype.hasOwnProperty.call(t,n[o])||!Object.is(e[n[o]],t[n[o]]))return!1;return!0}e.useStore=function(e,o=(e=>e),r){return t.useSyncExternalStoreWithSelector(e.subscribe,(()=>e.state),(()=>e.state),o,r?n:void 0)},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
12
22
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/index.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../../store/build/esm/index.js","../../src/index.tsx"],"sourcesContent":["/**\n * store\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 queue = [];\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 if (this.state === previous) return;\n this.options?.onUpdate?.(this.state, previous);\n this.queue.push(() => {\n this.listeners.forEach(listener => listener(this.state, previous));\n });\n this.#flush();\n };\n #flush = () => {\n if (this.batching) return;\n this.queue.forEach(cb => cb());\n this.queue = [];\n };\n batch = cb => {\n this.batching = true;\n cb();\n this.batching = false;\n this.#flush();\n };\n}\nfunction shallow(objA, objB) {\n if (Object.is(objA, objB)) {\n return true;\n }\n if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n return false;\n }\n\n // if (objA instanceof Map && objB instanceof Map) {\n // if (objA.size !== objB.size) return false\n\n // for (const [key, value] of objA) {\n // if (!Object.is(value, objB.get(key))) {\n // return false\n // }\n // }\n // return true\n // }\n\n // if (objA instanceof Set && objB instanceof Set) {\n // if (objA.size !== objB.size) return false\n\n // for (const value of objA) {\n // if (!objB.has(value)) {\n // return false\n // }\n // }\n // return true\n // }\n\n const keysA = Object.keys(objA);\n if (keysA.length !== Object.keys(objB).length) {\n return false;\n }\n for (let i = 0; i < keysA.length; i++) {\n if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {\n return false;\n }\n }\n return true;\n}\n\nexport { Store, shallow };\n//# sourceMappingURL=index.js.map\n","import { Store, AnyUpdater, shallow } from '@tanstack/store'\n\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\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 compareShallow?: boolean,\n) {\n const slice = useSyncExternalStoreWithSelector(\n store.subscribe,\n () => store.state,\n () => store.state,\n selector,\n compareShallow ? shallow : undefined,\n )\n\n return slice\n}\n\n"],"names":["shallow","objA","objB","Object","is","keysA","keys","length","i","prototype","hasOwnProperty","call","store","selector","d","compareShallow","useSyncExternalStoreWithSelector","subscribe","state","undefined"],"mappings":";;;;;;;;;;;;;;;;;;;;KAgDA,SAASA,EAAQC,EAAMC,GACrB,GAAIC,OAAOC,GAAGH,EAAMC,GAClB,OAAO,EAET,GAAoB,iBAATD,GAA8B,OAATA,GAAiC,iBAATC,GAA8B,OAATA,EAC3E,OAAO,EAyBT,MAAMG,EAAQF,OAAOG,KAAKL,GAC1B,GAAII,EAAME,SAAWJ,OAAOG,KAAKJ,GAAMK,OACrC,OAAO,EAET,IAAK,IAAIC,EAAI,EAAGA,EAAIH,EAAME,OAAQC,IAChC,IAAKL,OAAOM,UAAUC,eAAeC,KAAKT,EAAMG,EAAMG,MAAQL,OAAOC,GAAGH,EAAKI,EAAMG,IAAKN,EAAKG,EAAMG,KACjG,OAAO,EAGX,OAAO,CACT,YClFO,SAKLI,EACAC,EAAmDC,IAAMA,GACzDC,GAUA,OARcC,EAAgCA,iCAC5CJ,EAAMK,WACN,IAAML,EAAMM,QACZ,IAAMN,EAAMM,OACZL,EACAE,EAAiBf,OAAUmB,EAI/B"}
|
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.81",
|
|
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.81"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/use-sync-external-store": "^0.0.3"
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Store, AnyUpdater } from '@tanstack/store'
|
|
1
|
+
import { Store, AnyUpdater, shallow } from '@tanstack/store'
|
|
2
2
|
|
|
3
3
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
|
|
4
4
|
|
|
@@ -24,54 +24,3 @@ export function useStore<
|
|
|
24
24
|
return slice
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
function shallow<T>(objA: T, objB: T) {
|
|
28
|
-
if (Object.is(objA, objB)) {
|
|
29
|
-
return true
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
typeof objA !== 'object' ||
|
|
34
|
-
objA === null ||
|
|
35
|
-
typeof objB !== 'object' ||
|
|
36
|
-
objB === null
|
|
37
|
-
) {
|
|
38
|
-
return false
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// if (objA instanceof Map && objB instanceof Map) {
|
|
42
|
-
// if (objA.size !== objB.size) return false
|
|
43
|
-
|
|
44
|
-
// for (const [key, value] of objA) {
|
|
45
|
-
// if (!Object.is(value, objB.get(key))) {
|
|
46
|
-
// return false
|
|
47
|
-
// }
|
|
48
|
-
// }
|
|
49
|
-
// return true
|
|
50
|
-
// }
|
|
51
|
-
|
|
52
|
-
// if (objA instanceof Set && objB instanceof Set) {
|
|
53
|
-
// if (objA.size !== objB.size) return false
|
|
54
|
-
|
|
55
|
-
// for (const value of objA) {
|
|
56
|
-
// if (!objB.has(value)) {
|
|
57
|
-
// return false
|
|
58
|
-
// }
|
|
59
|
-
// }
|
|
60
|
-
// return true
|
|
61
|
-
// }
|
|
62
|
-
|
|
63
|
-
const keysA = Object.keys(objA)
|
|
64
|
-
if (keysA.length !== Object.keys(objB).length) {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
for (let i = 0; i < keysA.length; i++) {
|
|
69
|
-
if (
|
|
70
|
-
!Object.prototype.hasOwnProperty.call(objB, keysA[i] as string) ||
|
|
71
|
-
!Object.is(objA[keysA[i] as keyof T], objB[keysA[i] as keyof T])
|
|
72
|
-
) {
|
|
73
|
-
return false
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return true
|
|
77
|
-
}
|