chrono-state-z 2.2.0 → 2.2.1-iz
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/README.md +9 -14
- package/build/index.cjs.js +1 -1
- package/build/index.d.ts +9 -4
- package/build/index.esm.js +1 -1
- package/build/react/schedule.d.ts +1 -1
- package/build/react/useBatch.d.ts +1 -1
- package/build/react/useEffectReact.d.ts +1 -1
- package/build/react/useWatch.d.ts +1 -1
- package/package.json +2 -5
- package/build/core/asyncAtom.d.ts +0 -10
- package/build/core/asyncComputed.d.ts +0 -8
- package/build/core/asyncResource.d.ts +0 -28
- package/build/core/atom.d.ts +0 -6
- package/build/core/createAtomFactory.d.ts +0 -7
- package/build/core/createBaseAtom.d.ts +0 -6
- package/build/core/createStore.d.ts +0 -3
- package/build/core/factoryAtom.d.ts +0 -7
- package/build/core/index.d.ts +0 -12
- package/build/core/selector.d.ts +0 -7
- package/build/core/transaction.d.ts +0 -1
- package/build/core/types.d.ts +0 -12
- package/build/core/watch.d.ts +0 -7
package/README.md
CHANGED
|
@@ -25,13 +25,13 @@ It provides **atoms, computed values, async state, effects, scheduling**, with a
|
|
|
25
25
|
|
|
26
26
|
## 🧠 Mental Model
|
|
27
27
|
|
|
28
|
-
- Atom
|
|
29
|
-
- Computed
|
|
30
|
-
- AsyncAtom
|
|
31
|
-
- Effect
|
|
32
|
-
-
|
|
33
|
-
- Store / Intent
|
|
34
|
-
- React hooks
|
|
28
|
+
- **Atom** → small reactive state unit
|
|
29
|
+
- **Computed** → derived, cached reactive value
|
|
30
|
+
- **AsyncAtom** → async resource with invalidate + priority
|
|
31
|
+
- **Effect** → reactive side-effect runner
|
|
32
|
+
- **Transaction** → batch updates
|
|
33
|
+
- **Store / Intent** → event-driven orchestration
|
|
34
|
+
- **React hooks** → thin bindings over the headless core
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
@@ -281,16 +281,11 @@ function StoreView({ store }: { store: Store<any> }) {
|
|
|
281
281
|
|
|
282
282
|
```tsx
|
|
283
283
|
// Only re-renders when saving changes, not the whole store.
|
|
284
|
-
import { useStoreSelector } from
|
|
284
|
+
import { useStoreSelector } from "chrono-state-z"
|
|
285
285
|
|
|
286
286
|
function SavingBadge({ store }) {
|
|
287
287
|
const saving = useStoreSelector(store, s => s.saving)
|
|
288
|
-
|
|
289
|
-
// store,
|
|
290
|
-
// s => s.meta,
|
|
291
|
-
// shallowEqual
|
|
292
|
-
// )
|
|
293
|
-
return saving ? 'Saving...' : 'Idle'
|
|
288
|
+
return saving ? "Saving..." : "Idle"
|
|
294
289
|
}
|
|
295
290
|
|
|
296
291
|
```
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("react"),t=require("intentx-state-z");function r(e){var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,Object.freeze(t)}var n=r(e);function c(e){return n.useSyncExternalStore(r=>t.effect(()=>{e(),r()}),e,e)}Object.defineProperty(exports,"asyncAtom",{enumerable:!0,get:function(){return t.asyncAtom}}),Object.defineProperty(exports,"asyncAtomFamily",{enumerable:!0,get:function(){return t.asyncAtomFamily}}),Object.defineProperty(exports,"asyncComputed",{enumerable:!0,get:function(){return t.asyncComputed}}),Object.defineProperty(exports,"atom",{enumerable:!0,get:function(){return t.atom}}),Object.defineProperty(exports,"atomMiddleware",{enumerable:!0,get:function(){return t.atomMiddleware}}),Object.defineProperty(exports,"batch",{enumerable:!0,get:function(){return t.batch}}),Object.defineProperty(exports,"computed",{enumerable:!0,get:function(){return t.computed}}),Object.defineProperty(exports,"createAppScope",{enumerable:!0,get:function(){return t.createAppScope}}),Object.defineProperty(exports,"createSelector",{enumerable:!0,get:function(){return t.createSelector}}),Object.defineProperty(exports,"createSharedIntentBus",{enumerable:!0,get:function(){return t.createSharedIntentBus}}),Object.defineProperty(exports,"createStore",{enumerable:!0,get:function(){return t.createStore}}),Object.defineProperty(exports,"effect",{enumerable:!0,get:function(){return t.effect}}),Object.defineProperty(exports,"factoryAtom",{enumerable:!0,get:function(){return t.factoryAtom}}),Object.defineProperty(exports,"readonlyAtom",{enumerable:!0,get:function(){return t.readonlyAtom}}),Object.defineProperty(exports,"selectAtom",{enumerable:!0,get:function(){return t.selectAtom}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return t.transaction}}),Object.defineProperty(exports,"watch",{enumerable:!0,get:function(){return t.watch}}),Object.defineProperty(exports,"watchSelector",{enumerable:!0,get:function(){return t.watchSelector}}),exports.scheduleReactJob=function(t,r="normal"){"low"===r?e.startTransition(t):t()},exports.useAtom=c,exports.useAtomSelector=function(r,n,c=Object.is){const o=e.useRef(t.createSelector(n,c)),u=()=>o.current(r());return e.useSyncExternalStore(e=>t.effect(()=>{r(),e()}),u,u)},exports.useBatch=function(){return t.batch},exports.useComputed=function(e,r=[]){return c(n.useMemo(()=>t.computed(e),r))},exports.useEffectReact=function(e,r="normal"){const c=n.useRef(e);c.current=e,n.useEffect(()=>{const e=t.effect(()=>{c.current()},r);return()=>e()},[r])},exports.useFactoryAtom=function(e,t){const r=n.useRef(e);r.current=e;const o=n.useRef(null),u=n.useRef(null);return null!==o.current&&u.current===t||(o.current=r.current(t),u.current=t),c(o.current)},exports.useStore=function(t){return e.useSyncExternalStore(t.subscribe,t.state,t.state)},exports.useStoreSelector=function(e,r,c=Object.is){const o=n.useRef(r);o.current=r;const u=n.useRef(t.createSelector(e=>o.current(e),c)),s=n.useCallback(()=>u.current(e.state()),[e]);return n.useSyncExternalStore(e.subscribe,s,s)},exports.useWatch=function(e,r,c){const o=n.useRef(r);o.current=r;const u=n.useRef(c);u.current=c,n.useEffect(()=>{const r=t.watch(e,e=>{o.current(e)},u.current);return()=>null==r?void 0:r()},[e])};
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
export * from "./react";
|
|
2
|
+
export { atom, readonlyAtom, atomMiddleware, } from "intentx-state-z";
|
|
3
|
+
export { asyncAtom, asyncAtomFamily, } from "intentx-state-z";
|
|
4
|
+
export { asyncComputed } from "intentx-state-z";
|
|
5
|
+
export { computed, effect, batch, transaction, } from "intentx-state-z";
|
|
6
|
+
export { createStore, createAppScope, createSharedIntentBus } from "intentx-state-z";
|
|
7
|
+
export type { Atom, Priority, Store, Subscriber } from "intentx-state-z";
|
|
8
|
+
export { createSelector, selectAtom, watchSelector, watch } from "intentx-state-z";
|
|
9
|
+
export { factoryAtom } from "intentx-state-z";
|
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import*as t from"react";import e,{startTransition as r}from"react";import{effect as n,createSelector as c,batch as u,computed as o,watch as s}from"intentx-state-z";export{asyncAtom,asyncAtomFamily,asyncComputed,atom,atomMiddleware,batch,computed,createAppScope,createSelector,createSharedIntentBus,createStore,effect,factoryAtom,readonlyAtom,selectAtom,transaction,watch,watchSelector}from"intentx-state-z";function a(e){return t.useSyncExternalStore(t=>n(()=>{e(),t()}),e,e)}function f(t,r,u=Object.is){const o=e.useRef(c(r,u)),s=()=>o.current(t());return e.useSyncExternalStore(e=>n(()=>{t(),e()}),s,s)}function i(){return u}function l(e,r=[]){return a(t.useMemo(()=>o(e),r))}function m(e,r="normal"){const c=t.useRef(e);c.current=e,t.useEffect(()=>{const t=n(()=>{c.current()},r);return()=>t()},[r])}function S(e,r){const n=t.useRef(e);n.current=e;const c=t.useRef(null),u=t.useRef(null);return null!==c.current&&u.current===r||(c.current=n.current(r),u.current=r),a(c.current)}function p(t){return e.useSyncExternalStore(t.subscribe,t.state,t.state)}function y(e,r,n=Object.is){const u=t.useRef(r);u.current=r;const o=t.useRef(c(t=>u.current(t),n)),s=t.useCallback(()=>o.current(e.state()),[e]);return t.useSyncExternalStore(e.subscribe,s,s)}function R(e,r,n){const c=t.useRef(r);c.current=r;const u=t.useRef(n);u.current=n,t.useEffect(()=>{const t=s(e,t=>{c.current(t)},u.current);return()=>null==t?void 0:t()},[e])}function b(t,e="normal"){"low"===e?r(t):t()}export{b as scheduleReactJob,a as useAtom,f as useAtomSelector,i as useBatch,l as useComputed,m as useEffectReact,S as useFactoryAtom,p as useStore,y as useStoreSelector,R as useWatch};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Priority } from 'intentx-
|
|
1
|
+
import type { Priority } from 'intentx-state-z';
|
|
2
2
|
export declare function scheduleReactJob(job: () => void, priority?: Priority): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { batch } from 'intentx-
|
|
1
|
+
import { batch } from 'intentx-state-z';
|
|
2
2
|
export declare function useBatch(): typeof batch;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Priority } from 'intentx-
|
|
1
|
+
import { Priority } from 'intentx-state-z';
|
|
2
2
|
export declare function useEffectReact(fn: () => void, priority?: Priority): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { WatchOptions } from "
|
|
1
|
+
import type { WatchOptions } from "intentx-state-z";
|
|
2
2
|
export declare function useWatch<T>(getter: () => T, fn: (val: T) => void, options?: WatchOptions<T>): void;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrono-state-z",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.1-iz",
|
|
4
4
|
"description": "A fine-grained, intent-driven reactive state runtime for building complex React logic outside components.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Delpi.Kye",
|
|
7
7
|
"sideEffects": false,
|
|
8
|
-
|
|
9
8
|
"main": "build/index.cjs.js",
|
|
10
9
|
"module": "build/index.esm.js",
|
|
11
10
|
"types": "build/index.d.ts",
|
|
@@ -19,14 +18,12 @@
|
|
|
19
18
|
"files": [
|
|
20
19
|
"build"
|
|
21
20
|
],
|
|
22
|
-
|
|
23
21
|
"scripts": {
|
|
24
22
|
"clean": "rimraf build",
|
|
25
23
|
"build": "rollup -c",
|
|
26
24
|
"cb": "npm run clean && npm run build",
|
|
27
25
|
"prepublishOnly": "npm run cb"
|
|
28
26
|
},
|
|
29
|
-
|
|
30
27
|
"repository": {
|
|
31
28
|
"type": "git",
|
|
32
29
|
"url": "https://github.com/delpikye-v/chrono-state.git"
|
|
@@ -56,7 +53,7 @@
|
|
|
56
53
|
"react": ">=18"
|
|
57
54
|
},
|
|
58
55
|
"dependencies": {
|
|
59
|
-
"intentx-
|
|
56
|
+
"intentx-state-z": "^0.1.1"
|
|
60
57
|
},
|
|
61
58
|
"devDependencies": {
|
|
62
59
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { CommonResource } from "./asyncResource";
|
|
2
|
-
export type AsyncAtom<T> = {
|
|
3
|
-
(): T | undefined;
|
|
4
|
-
} & CommonResource<T>;
|
|
5
|
-
export declare function asyncAtom<T>(fetcher: (signal?: AbortSignal) => Promise<T>, options?: {
|
|
6
|
-
suspense?: boolean;
|
|
7
|
-
}): AsyncAtom<T>;
|
|
8
|
-
export declare function asyncAtomFamily<K, T>(factory: (key: K) => (signal?: AbortSignal) => Promise<T>, options?: {
|
|
9
|
-
suspense?: boolean;
|
|
10
|
-
}): (key: K) => AsyncAtom<T>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Priority } from "intentx-core-z";
|
|
2
|
-
export type AsyncComputed<T> = {
|
|
3
|
-
(): T | undefined;
|
|
4
|
-
invalidate(priority?: Priority): void;
|
|
5
|
-
status(): string;
|
|
6
|
-
error(): any;
|
|
7
|
-
};
|
|
8
|
-
export declare function asyncComputed<T>(getter: (signal?: AbortSignal) => Promise<T>, priority?: Priority): AsyncComputed<T>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Priority } from "intentx-core-z";
|
|
2
|
-
export type CommonResource<T> = {
|
|
3
|
-
load(): Promise<T>;
|
|
4
|
-
cancel(): void;
|
|
5
|
-
invalidate(priority?: Priority): void;
|
|
6
|
-
status(): AsyncState<T>["status"];
|
|
7
|
-
error(): any;
|
|
8
|
-
setSuccess(value: T, priority?: Priority): void;
|
|
9
|
-
};
|
|
10
|
-
export type AsyncState<T> = {
|
|
11
|
-
status: "idle";
|
|
12
|
-
} | {
|
|
13
|
-
status: "loading";
|
|
14
|
-
promise: Promise<T>;
|
|
15
|
-
} | {
|
|
16
|
-
status: "success";
|
|
17
|
-
data: T;
|
|
18
|
-
} | {
|
|
19
|
-
status: "error";
|
|
20
|
-
error: any;
|
|
21
|
-
};
|
|
22
|
-
export type AsyncResource<T> = {
|
|
23
|
-
read(): T | undefined;
|
|
24
|
-
} & CommonResource<T>;
|
|
25
|
-
export declare function createAsyncResource<T>(fetcher: (signal?: AbortSignal) => Promise<T>, options?: {
|
|
26
|
-
suspense?: boolean;
|
|
27
|
-
priority?: Priority;
|
|
28
|
-
}): AsyncResource<T>;
|
package/build/core/atom.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export type ReadonlyAtom<T> = () => T;
|
|
2
|
-
export declare const atom: <T>(initial: T, options?: import("./createAtomFactory").AtomOptions<T>) => import("./createBaseAtom").Atom<T>;
|
|
3
|
-
export declare const atomMiddleware: <T>(initial: T, middleware?: import("./createAtomFactory").AtomMiddleware<T>) => import("./createBaseAtom").Atom<T>;
|
|
4
|
-
export declare function readonlyAtom<T>(atom: {
|
|
5
|
-
(): T;
|
|
6
|
-
}): ReadonlyAtom<T>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Signal } from "intentx-core-z";
|
|
2
|
-
export type AtomOptions<T> = {
|
|
3
|
-
equals?: (a: T, b: T) => boolean;
|
|
4
|
-
};
|
|
5
|
-
export type AtomMiddleware<T> = (next: T, prev: T) => T;
|
|
6
|
-
export declare function createAtomFactory(signal: <T>(v: T) => Signal<T>): <T>(initial: T, options?: AtomOptions<T>) => import("./createBaseAtom").Atom<T>;
|
|
7
|
-
export declare function createAtomWithMiddlewareFactory(signal: <T>(v: T) => Signal<T>): <T>(initial: T, middleware?: AtomMiddleware<T>) => import("./createBaseAtom").Atom<T>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Priority, Signal } from "intentx-core-z";
|
|
2
|
-
export type Atom<T> = Signal<T> & {
|
|
3
|
-
update(fn: (prev: T) => T, priority?: Priority): void;
|
|
4
|
-
};
|
|
5
|
-
export type AtomTransform<T> = (next: T, prev: T) => T;
|
|
6
|
-
export declare function createBaseAtomFactory(signal: <T>(v: T) => Signal<T>): <T>(initial: T, transform?: AtomTransform<T>) => Atom<T>;
|
package/build/core/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from "./atom";
|
|
2
|
-
export * from "./asyncComputed";
|
|
3
|
-
export * from "./createAtomFactory";
|
|
4
|
-
export { asyncAtom } from "./asyncAtom";
|
|
5
|
-
export { computed } from "intentx-core-z";
|
|
6
|
-
export { effect } from "intentx-core-z";
|
|
7
|
-
export * from "./watch";
|
|
8
|
-
export { createStore } from "./createStore";
|
|
9
|
-
export * from "./selector";
|
|
10
|
-
export type { Store, Subscriber } from "./types";
|
|
11
|
-
export { factoryAtom } from "./factoryAtom";
|
|
12
|
-
export { transaction } from "./transaction";
|
package/build/core/selector.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type EqualityFn<T> = (a: T, b: T) => boolean;
|
|
2
|
-
export declare function createSelector<S, R>(select: (state: S) => R, isEqual?: EqualityFn<R>): (state: S) => R;
|
|
3
|
-
export declare function selectAtom<T, R>(atom: () => T, selector: (value: T) => R, onChange: (value: R) => void, options?: {
|
|
4
|
-
isEqual?: (a: R, b: R) => boolean;
|
|
5
|
-
immediate?: boolean;
|
|
6
|
-
}): () => void;
|
|
7
|
-
export declare function watchSelector<S, R>(getState: () => S, subscribe: (fn: () => void) => () => void, selector: (state: S) => R, onChange: (value: R) => void, isEqual?: EqualityFn<R>): () => void;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { batch as transaction } from "intentx-core-z";
|
package/build/core/types.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { IntentHandler, Scope } from "intentx-core-z";
|
|
2
|
-
import { EqualityFn } from "./selector";
|
|
3
|
-
export type Subscriber = () => void;
|
|
4
|
-
export type Store<S extends object> = {
|
|
5
|
-
scope: Scope;
|
|
6
|
-
state(): S;
|
|
7
|
-
setState(fn: (s: S) => void): void;
|
|
8
|
-
subscribe(fn: Subscriber): () => void;
|
|
9
|
-
emit(type: string, payload?: any): Promise<void>;
|
|
10
|
-
on(type: string, handler: IntentHandler<S>): () => void;
|
|
11
|
-
watch<R>(selector: (state: S) => R, onChange: (value: R) => void, isEqual?: EqualityFn<R>): () => void;
|
|
12
|
-
};
|
package/build/core/watch.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Priority } from "intentx-core-z";
|
|
2
|
-
export type WatchOptions<T> = {
|
|
3
|
-
immediate?: boolean;
|
|
4
|
-
equals?: (a: T, b: T) => boolean;
|
|
5
|
-
priority?: Priority;
|
|
6
|
-
};
|
|
7
|
-
export declare function watch<T>(getter: () => T, fn: (value: T, prev: T | undefined, onCleanup: (callback: () => void) => void) => void, options?: WatchOptions<T>): () => void;
|