@createstore/createstore 0.0.0-stage → 0.0.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gaurav Asawa
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.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @createstore/createstore
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Global state that works like `useState`, shared by every component. No provider, no reducers, no action types.
4
+
5
+ ```sh
6
+ npm install @createstore/createstore
7
+ ```
8
+
9
+ Requires React 19 or newer. Works in the browser, in Node, and with Next.js Server Components.
10
+
11
+ ## Quick start
12
+
13
+ ```tsx
14
+ import { createStore } from '@createstore/createstore';
15
+
16
+ const store = createStore({ count: 0 });
17
+
18
+ function Counter() {
19
+ const [count, setCount] = store.useGlobalState('count');
20
+ return <button onClick={() => setCount((c) => c + 1)}>{count}</button>;
21
+ }
22
+ ```
23
+
24
+ Every component that reads `'count'` re-renders when any of them changes it. Outside React, use
25
+ `store.getState('count')` and `store.setState('count', 2)`.
26
+
27
+ Everything else stays off until you use it: computed values, server data with `query()`, persistence, offline
28
+ support, undo/redo, tab sync, events and server rendering.
29
+
30
+ ## Package
31
+
32
+ - ESM and CommonJS builds with TypeScript types, `"sideEffects": false`, so unused code is tree-shaken.
33
+ - Published with [npm provenance](https://docs.npmjs.com/generating-provenance-statements).
34
+ - Versioned with [semantic versioning](https://semver.org); see [CHANGELOG.md](./CHANGELOG.md) once a release exists.
35
+
36
+ ## License
37
+
38
+ [MIT](./LICENSE)
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ "use client";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var client_root_exports = {};
21
+ __export(client_root_exports, {
22
+ ClientRoot: () => ClientRoot
23
+ });
24
+ module.exports = __toCommonJS(client_root_exports);
25
+ var import_react = require("react");
26
+ var import_createStore = require("./createStore.cjs");
27
+ function ClientRoot({ name, snapshot, children }) {
28
+ const parent = (0, import_react.useContext)(import_createStore.__SnapshotContext);
29
+ const value = (0, import_react.useMemo)(() => ({ ...parent ?? {}, [name]: { snapshot } }), [parent, name, snapshot]);
30
+ (0, import_react.useLayoutEffect)(() => {
31
+ (0, import_createStore.__mergeSnapshot)(name, snapshot);
32
+ }, [name, snapshot]);
33
+ return (0, import_react.createElement)(import_createStore.__SnapshotContext.Provider, { value }, children);
34
+ }
35
+ // Annotate the CommonJS export names for ESM import in node:
36
+ 0 && (module.exports = {
37
+ ClientRoot
38
+ });
39
+ //# sourceMappingURL=client-root.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/client-root.tsx"],"sourcesContent":["'use client';\n// What <Store.Root> in a Server Component renders: it hands the request's snapshot down by store name.\n// The store's first hook below picks it up; later snapshots (client-side navigation) are merged in a\n// layout effect, before components subscribe, so a new page's data isn't fetched again.\nimport { createElement, useContext, useLayoutEffect, useMemo, type ReactNode } from 'react';\nimport { __SnapshotContext, __mergeSnapshot } from './createStore';\n\nexport function ClientRoot({ name, snapshot, children }: { name: string; snapshot: unknown; children?: ReactNode }) {\n const parent = useContext(__SnapshotContext);\n const value = useMemo(() => ({ ...(parent ?? {}), [name]: { snapshot } }), [parent, name, snapshot]);\n useLayoutEffect(() => {\n __mergeSnapshot(name, snapshot);\n }, [name, snapshot]);\n return createElement(__SnapshotContext.Provider, { value }, children);\n}"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,mBAAoF;AACpF,yBAAmD;AAE5C,SAAS,WAAW,EAAE,MAAM,UAAU,SAAS,GAA8D;AAClH,QAAM,aAAS,yBAAW,oCAAiB;AAC3C,QAAM,YAAQ,sBAAQ,OAAO,EAAE,GAAI,UAAU,CAAC,GAAI,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,QAAQ,MAAM,QAAQ,CAAC;AACnG,oCAAgB,MAAM;AACpB,4CAAgB,MAAM,QAAQ;AAAA,EAChC,GAAG,CAAC,MAAM,QAAQ,CAAC;AACnB,aAAO,4BAAc,qCAAkB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACtE;","names":[]}