@tanstack/react-store 0.3.1 → 0.4.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.
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -16
- package/src/index.ts +1 -1
- package/src/tests/index.test.tsx +3 -3
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'\nimport type { AnyUpdater, Store } from '@tanstack/store'\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":["store","useSyncExternalStoreWithSelector"],"mappings":";;;;AAOO,SAAS,SAKdA,QACA,WAAkD,CAAC,MAAM,GACzD;AACA,QAAM,QAAQC,gBAAA;AAAA,IACZD,OAAM;AAAA,IACN,MAAMA,OAAM;AAAA,IACZ,MAAMA,OAAM;AAAA,IACZ;AAAA,IACA;AAAA,EAAA;AAGK,SAAA;AACT;AAEgB,SAAA,QAAW,MAAS,MAAS;AAC3C,MAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AAClB,WAAA;AAAA,EACT;AAGE,MAAA,OAAO,SAAS,YAChB,SAAS,QACT,OAAO,SAAS,YAChB,SAAS,MACT;AACO,WAAA;AAAA,EACT;AAEM,QAAA,QAAQ,OAAO,KAAK,IAAI;AAC9B,MAAI,MAAM,WAAW,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAA;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAEnC,QAAA,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,MAAM,CAAC,CAAW,KAC9D,CAAC,OAAO,GAAG,KAAK,MAAM,CAAC,CAAY,GAAG,KAAK,MAAM,CAAC,CAAY,CAAC,GAC/D;AACO,aAAA;AAAA,IACT;AAAA,EACF;AACO,SAAA;AACT;;;;;;;;;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AnyUpdater, Store } from '@tanstack/store';
|
|
2
|
+
|
|
2
3
|
export * from '@tanstack/store';
|
|
3
4
|
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
4
5
|
export declare function useStore<TState, TSelected = NoInfer<TState>, TUpdater extends AnyUpdater = AnyUpdater>(store: Store<TState, TUpdater>, selector?: (state: NoInfer<TState>) => TSelected): TSelected;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AnyUpdater, Store } from '@tanstack/store';
|
|
2
|
+
|
|
2
3
|
export * from '@tanstack/store';
|
|
3
4
|
export type NoInfer<T> = [T][T extends any ? 0 : never];
|
|
4
5
|
export declare function useStore<TState, TSelected = NoInfer<TState>, TUpdater extends AnyUpdater = AnyUpdater>(store: Store<TState, TUpdater>, selector?: (state: NoInfer<TState>) => TSelected): TSelected;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js'\nimport type { AnyUpdater, Store } from '@tanstack/store'\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":[],"mappings":";;AAOO,SAAS,SAKd,OACA,WAAkD,CAAC,MAAM,GACzD;AACA,QAAM,QAAQ;AAAA,IACZ,MAAM;AAAA,IACN,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ;AAAA,IACA;AAAA,EAAA;AAGK,SAAA;AACT;AAEgB,SAAA,QAAW,MAAS,MAAS;AAC3C,MAAI,OAAO,GAAG,MAAM,IAAI,GAAG;AAClB,WAAA;AAAA,EACT;AAGE,MAAA,OAAO,SAAS,YAChB,SAAS,QACT,OAAO,SAAS,YAChB,SAAS,MACT;AACO,WAAA;AAAA,EACT;AAEM,QAAA,QAAQ,OAAO,KAAK,IAAI;AAC9B,MAAI,MAAM,WAAW,OAAO,KAAK,IAAI,EAAE,QAAQ;AACtC,WAAA;AAAA,EACT;AAEA,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AAEnC,QAAA,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,MAAM,CAAC,CAAW,KAC9D,CAAC,OAAO,GAAG,KAAK,MAAM,CAAC,CAAY,GAAG,KAAK,MAAM,CAAC,CAAY,CAAC,GAC/D;AACO,aAAA;AAAA,IACT;AAAA,EACF;AACO,SAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-store",
|
|
3
3
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"repository": "tanstack/
|
|
6
|
+
"repository": "tanstack/store",
|
|
7
7
|
"homepage": "https://tanstack.com/",
|
|
8
8
|
"description": "",
|
|
9
9
|
"publishConfig": {
|
|
@@ -46,23 +46,11 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"use-sync-external-store": "^1.2.0",
|
|
49
|
-
"@tanstack/store": "0.
|
|
49
|
+
"@tanstack/store": "0.4.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/use-sync-external-store": "^0.0.3",
|
|
53
53
|
"@vitejs/plugin-react": "^4.2.1"
|
|
54
54
|
},
|
|
55
|
-
"scripts": {
|
|
56
|
-
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
57
|
-
"test:eslint": "eslint --ext .ts,.tsx ./src",
|
|
58
|
-
"test:types:versions49": "node ../../node_modules/typescript49/lib/tsc.js --project tsconfig.legacy.json",
|
|
59
|
-
"test:types:versions50": "node ../../node_modules/typescript50/lib/tsc.js",
|
|
60
|
-
"test:types:versions51": "node ../../node_modules/typescript51/lib/tsc.js",
|
|
61
|
-
"test:types:versions52": "tsc",
|
|
62
|
-
"test:types": "pnpm run \"/^test:types:versions.*/\"",
|
|
63
|
-
"test:lib": "vitest",
|
|
64
|
-
"test:lib:dev": "pnpm run test:lib --watch",
|
|
65
|
-
"test:build": "publint --strict",
|
|
66
|
-
"build": "vite build"
|
|
67
|
-
}
|
|
55
|
+
"scripts": {}
|
|
68
56
|
}
|
package/src/index.ts
CHANGED
package/src/tests/index.test.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { describe, expect, it, test, vi } from 'vitest'
|
|
1
2
|
import { render, waitFor } from '@testing-library/react'
|
|
2
|
-
import '@testing-library/jest-dom'
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { Store } from '@tanstack/store'
|
|
5
|
-
import { useStore, shallow } from '../index'
|
|
6
5
|
import { useState } from 'react'
|
|
7
|
-
import userEvent from '@testing-library/user-event'
|
|
6
|
+
import { userEvent } from '@testing-library/user-event'
|
|
7
|
+
import { shallow, useStore } from '../index'
|
|
8
8
|
|
|
9
9
|
const user = userEvent.setup()
|
|
10
10
|
|