@tanstack/solid-store 0.5.0 → 0.5.3

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.
@@ -1,6 +1,5 @@
1
- import { AnyUpdater, Store } from '@tanstack/store';
2
- import { Accessor } from 'solid-js';
3
-
1
+ import type { AnyUpdater, Store } from '@tanstack/store';
2
+ import type { Accessor } from 'solid-js';
4
3
  export * from '@tanstack/store';
5
4
  export type NoInfer<T> = [T][T extends any ? 0 : never];
6
5
  export declare function useStore<TState, TSelected = NoInfer<TState>, TUpdater extends AnyUpdater = AnyUpdater>(store: Store<TState, TUpdater>, selector?: (state: NoInfer<TState>) => TSelected): Accessor<TSelected>;
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ import { onCleanup } from 'solid-js';
2
+ import { createStore, reconcile } from 'solid-js/store';
3
+ export * from '@tanstack/store';
4
+ export function useStore(store, selector = (d) => d) {
5
+ const [slice, setSlice] = createStore({
6
+ value: selector(store.state),
7
+ });
8
+ const unsub = store.subscribe(() => {
9
+ const newValue = selector(store.state);
10
+ setSlice('value', reconcile(newValue));
11
+ });
12
+ onCleanup(() => {
13
+ unsub();
14
+ });
15
+ return () => slice.value;
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAIvD,cAAc,iBAAiB,CAAA;AAI/B,MAAM,UAAU,QAAQ,CAKtB,KAA8B,EAC9B,WAAkD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAQ;IAEjE,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,WAAW,CAAC;QACpC,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;KAC7B,CAAC,CAAA;IAEF,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjC,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QACtC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAA;IACxC,CAAC,CAAC,CAAA;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,KAAK,EAAE,CAAA;IACT,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,EAAE,CAAC,KAAK,CAAC,KAAK,CAAA;AAC1B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/solid-store",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.5.0",
4
+ "version": "0.5.3",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/store",
7
7
  "homepage": "https://tanstack.com/",
@@ -23,18 +23,18 @@
23
23
  "src"
24
24
  ],
25
25
  "type": "module",
26
- "types": "dist/esm/index.d.ts",
27
- "main": "dist/cjs/index.cjs",
28
- "module": "dist/esm/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "main": "dist/index.js",
28
+ "module": "dist/index.js",
29
29
  "exports": {
30
30
  ".": {
31
- "import": {
32
- "types": "./dist/esm/index.d.ts",
33
- "default": "./dist/esm/index.js"
31
+ "solid": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
34
  },
35
- "require": {
36
- "types": "./dist/cjs/index.d.cts",
37
- "default": "./dist/cjs/index.cjs"
35
+ "import": {
36
+ "types": "./dist/index.d.ts",
37
+ "default": "./dist/index.js"
38
38
  }
39
39
  },
40
40
  "./package.json": "./package.json"
@@ -44,7 +44,7 @@
44
44
  "solid-js": "^1.6.0"
45
45
  },
46
46
  "dependencies": {
47
- "@tanstack/store": "0.5.0"
47
+ "@tanstack/store": "0.5.3"
48
48
  },
49
49
  "devDependencies": {
50
50
  "solid-js": "^1.7.8",
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const solidJs = require("solid-js");
4
- const store$1 = require("solid-js/store");
5
- const store = require("@tanstack/store");
6
- function useStore(store2, selector = (d) => d) {
7
- const [slice, setSlice] = store$1.createStore({
8
- value: selector(store2.state)
9
- });
10
- const unsub = store2.subscribe(() => {
11
- const newValue = selector(store2.state);
12
- setSlice("value", store$1.reconcile(newValue));
13
- });
14
- solidJs.onCleanup(() => {
15
- unsub();
16
- });
17
- return () => slice.value;
18
- }
19
- exports.useStore = useStore;
20
- Object.keys(store).forEach((k) => {
21
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
22
- enumerable: true,
23
- get: () => store[k]
24
- });
25
- });
26
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["import { onCleanup } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport type { AnyUpdater, Store } from '@tanstack/store'\nimport type { Accessor } from 'solid-js'\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): Accessor<TSelected> {\n const [slice, setSlice] = createStore({\n value: selector(store.state),\n })\n\n const unsub = store.subscribe(() => {\n const newValue = selector(store.state)\n setSlice('value', reconcile(newValue))\n })\n\n onCleanup(() => {\n unsub()\n })\n\n return () => slice.value\n}\n"],"names":["store","createStore","reconcile","onCleanup"],"mappings":";;;;;AASO,SAAS,SAKdA,QACA,WAAkD,CAAC,MAAM,GACpC;AACrB,QAAM,CAAC,OAAO,QAAQ,IAAIC,oBAAY;AAAA,IACpC,OAAO,SAASD,OAAM,KAAK;AAAA,EAAA,CAC5B;AAEK,QAAA,QAAQA,OAAM,UAAU,MAAM;AAC5B,UAAA,WAAW,SAASA,OAAM,KAAK;AAC5B,aAAA,SAASE,kBAAU,QAAQ,CAAC;AAAA,EAAA,CACtC;AAEDC,UAAAA,UAAU,MAAM;AACR;EAAA,CACP;AAED,SAAO,MAAM,MAAM;AACrB;;;;;;;;"}
@@ -1,6 +0,0 @@
1
- import { AnyUpdater, Store } from '@tanstack/store';
2
- import { Accessor } from 'solid-js';
3
-
4
- export * from '@tanstack/store';
5
- export type NoInfer<T> = [T][T extends any ? 0 : never];
6
- export declare function useStore<TState, TSelected = NoInfer<TState>, TUpdater extends AnyUpdater = AnyUpdater>(store: Store<TState, TUpdater>, selector?: (state: NoInfer<TState>) => TSelected): Accessor<TSelected>;
package/dist/esm/index.js DELETED
@@ -1,20 +0,0 @@
1
- import { onCleanup } from "solid-js";
2
- import { createStore, reconcile } from "solid-js/store";
3
- export * from "@tanstack/store";
4
- function useStore(store, selector = (d) => d) {
5
- const [slice, setSlice] = createStore({
6
- value: selector(store.state)
7
- });
8
- const unsub = store.subscribe(() => {
9
- const newValue = selector(store.state);
10
- setSlice("value", reconcile(newValue));
11
- });
12
- onCleanup(() => {
13
- unsub();
14
- });
15
- return () => slice.value;
16
- }
17
- export {
18
- useStore
19
- };
20
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { onCleanup } from 'solid-js'\nimport { createStore, reconcile } from 'solid-js/store'\nimport type { AnyUpdater, Store } from '@tanstack/store'\nimport type { Accessor } from 'solid-js'\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): Accessor<TSelected> {\n const [slice, setSlice] = createStore({\n value: selector(store.state),\n })\n\n const unsub = store.subscribe(() => {\n const newValue = selector(store.state)\n setSlice('value', reconcile(newValue))\n })\n\n onCleanup(() => {\n unsub()\n })\n\n return () => slice.value\n}\n"],"names":[],"mappings":";;;AASO,SAAS,SAKd,OACA,WAAkD,CAAC,MAAM,GACpC;AACrB,QAAM,CAAC,OAAO,QAAQ,IAAI,YAAY;AAAA,IACpC,OAAO,SAAS,MAAM,KAAK;AAAA,EAAA,CAC5B;AAEK,QAAA,QAAQ,MAAM,UAAU,MAAM;AAC5B,UAAA,WAAW,SAAS,MAAM,KAAK;AAC5B,aAAA,SAAS,UAAU,QAAQ,CAAC;AAAA,EAAA,CACtC;AAED,YAAU,MAAM;AACR;EAAA,CACP;AAED,SAAO,MAAM,MAAM;AACrB;"}
@@ -1,45 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { render, renderHook } from '@solidjs/testing-library'
3
- import { Store } from '@tanstack/store'
4
- import { useStore } from '../index'
5
-
6
- describe('useStore', () => {
7
- it.todo('allows us to select state using a selector', async () => {
8
- const store = new Store({
9
- select: 0,
10
- ignored: 1,
11
- })
12
-
13
- function Comp() {
14
- const storeVal = useStore(store, (state) => state.select)
15
-
16
- return <p>Store: {storeVal()}</p>
17
- }
18
-
19
- const { getByText } = render(() => <Comp />)
20
- expect(getByText('Store: 0')).toBeInTheDocument()
21
- })
22
-
23
- it('allows us to select state using a selector', () => {
24
- const store = new Store({
25
- select: 0,
26
- ignored: 1,
27
- })
28
-
29
- const { result } = renderHook(() =>
30
- useStore(store, (state) => state.select),
31
- )
32
-
33
- expect(result()).toBe(0)
34
- })
35
-
36
- it('updates accessor value when state is updated', () => {
37
- const store = new Store(0)
38
-
39
- const { result } = renderHook(() => useStore(store))
40
-
41
- store.setState((prev) => prev + 1)
42
-
43
- expect(result()).toBe(1)
44
- })
45
- })