@tanstack/solid-store 0.5.2 → 0.5.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/{esm/index.d.ts → index.d.ts} +2 -3
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/package.json +28 -27
- package/dist/cjs/index.cjs +0 -26
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -6
- package/dist/esm/index.js +0 -20
- package/dist/esm/index.js.map +0 -1
- package/src/tests/index.test.tsx +0 -45
|
@@ -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,54 +1,55 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-store",
|
|
3
|
+
"version": "0.5.4",
|
|
4
|
+
"description": "Framework agnostic type-safe store w/ reactive framework adapters",
|
|
3
5
|
"author": "Tanner Linsley",
|
|
4
|
-
"version": "0.5.2",
|
|
5
6
|
"license": "MIT",
|
|
6
|
-
"repository":
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"registry": "https://registry.npmjs.org/"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/TanStack/store.git",
|
|
10
|
+
"directory": "packages/solid-store"
|
|
11
11
|
},
|
|
12
|
-
"
|
|
13
|
-
"store",
|
|
14
|
-
"solid",
|
|
15
|
-
"typescript"
|
|
16
|
-
],
|
|
12
|
+
"homepage": "https://tanstack.com/store",
|
|
17
13
|
"funding": {
|
|
18
14
|
"type": "github",
|
|
19
15
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
20
16
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
17
|
+
"keywords": [
|
|
18
|
+
"store",
|
|
19
|
+
"solid",
|
|
20
|
+
"typescript"
|
|
24
21
|
],
|
|
25
22
|
"type": "module",
|
|
26
|
-
"types": "dist/
|
|
27
|
-
"main": "dist/
|
|
28
|
-
"module": "dist/
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.js",
|
|
29
26
|
"exports": {
|
|
30
27
|
".": {
|
|
31
|
-
"
|
|
32
|
-
"types": "./dist/
|
|
33
|
-
"default": "./dist/
|
|
28
|
+
"solid": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"default": "./dist/index.js"
|
|
34
31
|
},
|
|
35
|
-
"
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"default": "./dist/
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
38
35
|
}
|
|
39
36
|
},
|
|
40
37
|
"./package.json": "./package.json"
|
|
41
38
|
},
|
|
42
39
|
"sideEffects": false,
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
40
|
+
"files": [
|
|
41
|
+
"dist",
|
|
42
|
+
"src"
|
|
43
|
+
],
|
|
46
44
|
"dependencies": {
|
|
47
|
-
"@tanstack/store": "0.5.
|
|
45
|
+
"@tanstack/store": "0.5.4"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
48
|
"solid-js": "^1.7.8",
|
|
51
49
|
"vite-plugin-solid": "^2.10.2"
|
|
52
50
|
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"solid-js": "^1.6.0"
|
|
53
|
+
},
|
|
53
54
|
"scripts": {}
|
|
54
55
|
}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -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
|
package/dist/cjs/index.cjs.map
DELETED
|
@@ -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;;;;;;;;"}
|
package/dist/cjs/index.d.cts
DELETED
|
@@ -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
|
package/dist/esm/index.js.map
DELETED
|
@@ -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;"}
|
package/src/tests/index.test.tsx
DELETED
|
@@ -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
|
-
})
|