@simplestack/store 0.5.1 → 0.6.0

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/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ben Holmes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # Simple Store
2
+
3
+ A simple, `select`-xcellent state management library with the power of Jotai and Zustand combined.
4
+
5
+ ```tsx
6
+ import { store } from "@simplestack/store";
7
+ import { useStoreValue } from "@simplestack/store/react";
8
+
9
+ // Define your store with an initial state
10
+ const documentStore = store({
11
+ title: "Untitled",
12
+ authors: ["Ada", "Ben"],
13
+ meta: {
14
+ pages: 3,
15
+ tags: ["draft", "internal"],
16
+ },
17
+ });
18
+
19
+ // Select parts of a store to listen to individually
20
+ const titleStore = documentStore.select("title");
21
+ const tagsStore = documentStore.select("meta").select("tags");
22
+
23
+ function Document() {
24
+ // Update your UI with the store's current state
25
+ const { title, tags } = useStoreValue(documentStore);
26
+ return (
27
+ <div>
28
+ {title} {tags.join(", ")}
29
+ </div>
30
+ );
31
+ }
32
+
33
+ function Title() {
34
+ // And scope updates with selected stores for fine-grained control
35
+ const title = useStoreValue(titleStore);
36
+ return (
37
+ <input value={title} onChange={(e) => titleStore.set(e.target.value)} />
38
+ );
39
+ }
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### store(initial)
45
+
46
+ Creates a store with `get`, `set`, `subscribe`, and (for objects and arrays) `select`.
47
+
48
+ - Parameters: `initial: number | string | boolean | null | undefined | object`
49
+ - Returns: `Store<T>` where `T` is inferred from `initial` or supplied via generics
50
+
51
+ ```ts
52
+ import { store } from "@simplestack/store";
53
+
54
+ const counter = store(0);
55
+ counter.set((n) => n + 1);
56
+ console.log(counter.get()); // 1
57
+
58
+ // Select parts of a store for objects and arrays
59
+ const doc = store({ title: "x" });
60
+ const title = doc.select("title");
61
+ ```
62
+
63
+ ### React
64
+
65
+ #### useStoreValue(store)
66
+
67
+ React hook to subscribe to a store and get its current value.
68
+
69
+ - Parameters: `store: Store<T> | undefined`
70
+ - Returns: `T | undefined`
71
+
72
+ ```tsx
73
+ import { store } from "@simplestack/store";
74
+ import { useStoreValue } from "@simplestack/store/react";
75
+
76
+ const counterStore = store(0);
77
+
78
+ function Counter() {
79
+ const counter = useStoreValue(counterStore);
80
+ return (
81
+ <button onClick={() => counterStore.set((n) => n + 1)}>{counter}</button>
82
+ );
83
+ }
84
+ ```
85
+
86
+ ## Type Reference
87
+
88
+ These types are exported for TypeScript users.
89
+
90
+ - StateObject: `Record<string | number | symbol, any>`
91
+ - StatePrimitive: `string | number | boolean | null | undefined`
92
+ - Setter<T>: `T | ((state: T) => T)`
93
+ - Store<T>:
94
+ - `get(): T`
95
+ - `set(setter: Setter<T>): void`
96
+ - `subscribe(callback: (state: T) => void): () => void`
97
+ - `select(key: K): Store<SelectValue<T, K>>`: present only when `T` is an object or array
98
+
99
+ ## Contributing
100
+
101
+ Contributions are welcome! Please feel free to submit an issue or pull request.
102
+
103
+ ## License
104
+
105
+ This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.
package/dist/index.d.ts CHANGED
@@ -1,14 +1,90 @@
1
1
  export type StateObject = Record<string | number | symbol, any>;
2
2
  export type StatePrimitive = string | number | boolean | null | undefined;
3
+ /**
4
+ * Setter for the store.
5
+ * Can be either a value or a function that receives the current state and returns the new state.
6
+ * @see {@link Store}
7
+ */
3
8
  export type Setter<T extends StateObject | StatePrimitive> = T | ((state: T) => T);
4
9
  export type SelectValue<S, K extends keyof S> = S extends readonly (infer U)[] ? U | undefined : string extends keyof S ? S[K] | undefined : number extends keyof S ? S[K] | undefined : S[K];
5
10
  export type SelectFn<T extends StateObject | StatePrimitive> = T extends StateObject ? <K extends keyof T>(key: K) => Store<SelectValue<T, K>> : undefined;
6
11
  export type Store<T extends StateObject | StatePrimitive> = {
12
+ /**
13
+ * Get the current state of the store.
14
+ * @example
15
+ * const state = store(0).get();
16
+ * console.log(state); // 0
17
+ */
7
18
  get: () => T;
19
+ /**
20
+ * Set the state of the store.
21
+ * Can pass either a value or a function that receives the current state and returns the new state.
22
+ *
23
+ * @example
24
+ * const countStore = store(0);
25
+ * const increment = () => countStore.set((count) => count + 1);
26
+ * const setToZero = () => countStore.set(0);
27
+ */
8
28
  set: (setter: Setter<T>) => void;
9
- listen: (callback: (state: T) => void) => () => void;
29
+ /**
30
+ * Subscribe to the state of the store.
31
+ * Returns a function to unsubscribe.
32
+ *
33
+ * @param callback - The callback to subscribe to.
34
+ * @returns A function to unsubscribe.
35
+ * @example
36
+ * const countStore = store(0);
37
+ * const unsubscribe = countStore.subscribe((count) => {
38
+ * console.log(count);
39
+ * });
40
+ *
41
+ * // On component unmount or other cleanup:
42
+ * unsubscribe();
43
+ *
44
+ */
45
+ subscribe: (callback: (state: T) => void) => () => void;
46
+ /**
47
+ * Select a key from the state of the store.
48
+ * This returns a new store with the selected key as the state.
49
+ * @example
50
+ * const documentStore = store({
51
+ * title: "Untitled",
52
+ * });
53
+ *
54
+ * const titleStore = documentStore.select("title");
55
+ * console.log(titleStore.get()); // "Untitled"
56
+ *
57
+ * titleStore.set("New Title");
58
+ * console.log(titleStore.get()); // "New Title"
59
+ * console.log(documentStore.get()); // { title: "New Title" }
60
+ */
10
61
  select: SelectFn<T>;
11
62
  };
63
+ /**
64
+ * Creates a store with properties for getting, setting, subscribing to, and selecting from the state.
65
+ *
66
+ * @param initial - The initial state of the store.
67
+ * @returns A store with the initial state applied.
68
+ * @example
69
+ * // Infer types from the initial state
70
+ * const documentStore = store({
71
+ * title: "Untitled",
72
+ * createdAt: new Date(),
73
+ * authors: [] as string[],
74
+ * });
75
+ *
76
+ * // Or manually specify the type
77
+ * type DocumentStore = {
78
+ * title: string;
79
+ * createdAt: Date;
80
+ * authors: string[];
81
+ * }
82
+ * const documentStore = store<DocumentStore>({
83
+ * title: "Untitled",
84
+ * createdAt: new Date(),
85
+ * authors: [],
86
+ * });
87
+ */
12
88
  export declare function store(initial: number): Store<number>;
13
89
  export declare function store(initial: string): Store<string>;
14
90
  export declare function store(initial: boolean): Store<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC;AAChE,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1E,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAInF,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAEx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;;;;;;;;;;;;;OAeG;IACH,SAAS,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACxD;;;;;;;;;;;;;;OAcG;IACH,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AACtD,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AACtD,wBAAgB,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AACxD,wBAAgB,KAAK,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAC3D,OAAO,EAAE,CAAC,GACR,KAAK,CAAC,CAAC,CAAC,CAAC;AAsFZ,wBAAgB,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,MAAM,IAAI,CAAC,cAmBjE"}
package/dist/index.js CHANGED
@@ -6,13 +6,13 @@ export function store(initial) {
6
6
  return createStoreApi(get, set);
7
7
  }
8
8
  const createStoreApi = (get, set) => {
9
- const listen = (callback) => {
9
+ const subscribe = (callback) => {
10
10
  return effect(() => {
11
11
  callback(get());
12
12
  });
13
13
  };
14
14
  if (isStatePrimitive(get())) {
15
- return { get, set, listen, select: undefined };
15
+ return { get, set, subscribe, select: undefined };
16
16
  }
17
17
  function select(key) {
18
18
  const getSelected = () => {
@@ -39,11 +39,15 @@ const createStoreApi = (get, set) => {
39
39
  };
40
40
  return createStoreApi(getSelected, setSelected);
41
41
  }
42
- return { get, set, listen, select: select };
42
+ return { get, set, subscribe, select: select };
43
43
  };
44
44
  const UNEXPECTED_SELECT_ERROR = "Internal: select() was unexpectedly called on a state value that wasn't an object.";
45
45
  function isStatePrimitive(state) {
46
- return typeof state === "string" || typeof state === "number" || typeof state === "boolean" || state === null || state === undefined;
46
+ return (typeof state === "string" ||
47
+ typeof state === "number" ||
48
+ typeof state === "boolean" ||
49
+ state === null ||
50
+ state === undefined);
47
51
  }
48
52
  let needsEnqueue = true;
49
53
  const w = new Signal.subtle.Watcher(() => {
@@ -76,8 +80,4 @@ export function effect(callback) {
76
80
  cleanup = undefined;
77
81
  };
78
82
  }
79
- const noteStore = store({
80
- notes: [],
81
- });
82
- const firstNoteTitle = noteStore.select("notes").select(0).select?.('title');
83
83
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAmCzC,MAAM,UAAU,KAAK,CAAyC,OAAU;IACpE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,KAAK,CAAI,OAAO,CAAC,CAAC;IAC3C,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;IAC9B,MAAM,GAAG,GAAG,CAAC,MAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC1G,OAAO,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,cAAc,GAAG,CACnB,GAAY,EACZ,GAAgC,EACxB,EAAE;IACV,MAAM,MAAM,GAAG,CAAC,QAA4B,EAAE,EAAE;QAC5C,OAAO,MAAM,CAAC,GAAG,EAAE;YACf,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC;QACpB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEF,IAAI,gBAAgB,CAAC,GAAG,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StatePrimitive, Store } from "./index.js";
2
+ /**
3
+ * Subscribe to the state of the store.
4
+ * @param store - The store to subscribe to.
5
+ * @returns The current state of the store.
6
+ * @example
7
+ * const countStore = store(0);
8
+ * const count = useStoreValue(countStore);
9
+ * console.log(count); // 0
10
+ */
2
11
  export declare function useStoreValue<T extends StateObject | StatePrimitive>(store: Store<T>): T;
3
12
  export declare function useStoreValue<T extends StateObject | StatePrimitive>(store: Store<T> | undefined): T | undefined;
4
- export declare function useStoreValue<T extends StateObject | StatePrimitive>(store: undefined): undefined;
13
+ export declare function useStoreValue(store: undefined): undefined;
5
14
  //# sourceMappingURL=react.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAErE,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAC1F,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAAC;AAClH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EAAE,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC"}
1
+ {"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EACnE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GACb,CAAC,CAAC;AACL,wBAAgB,aAAa,CAAC,CAAC,SAAS,WAAW,GAAG,cAAc,EACnE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,GACzB,CAAC,GAAG,SAAS,CAAC;AACjB,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC"}
package/dist/react.js CHANGED
@@ -1,8 +1,8 @@
1
- import { useState, useEffect } from "react";
1
+ import { useEffect, useState } from "react";
2
2
  export function useStoreValue(store) {
3
3
  const [state, setState] = useState(store?.get());
4
4
  useEffect(() => {
5
- return store?.listen(setState);
5
+ return store?.subscribe(setState);
6
6
  }, [store]);
7
7
  return state;
8
8
  }
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAM5C,MAAM,UAAU,aAAa,CAAyC,KAA2B;IAC7F,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAChE,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC;AACjB,CAAC"}
1
+ {"version":3,"file":"react.js","sourceRoot":"","sources":["../src/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAmB5C,MAAM,UAAU,aAAa,CAC5B,KAA2B;IAE3B,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAgB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAChE,SAAS,CAAC,GAAG,EAAE;QACd,OAAO,KAAK,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplestack/store",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "A simple storage solution for React",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,6 +24,7 @@
24
24
  "author": "bholmesdev",
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
+ "@biomejs/biome": "2.2.2",
27
28
  "@types/react": "^19.1.12",
28
29
  "react": "^19.0.0",
29
30
  "typescript": "^5.9.2"
@@ -54,6 +55,7 @@
54
55
  ],
55
56
  "scripts": {
56
57
  "build": "tsc",
57
- "dev": "tsc -w"
58
+ "dev": "tsc -w",
59
+ "check": "biome check"
58
60
  }
59
61
  }