chrono-state-z 2.1.0 → 2.2.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/README.md +113 -18
- package/build/core/asyncAtom.d.ts +9 -8
- package/build/core/asyncComputed.d.ts +4 -2
- package/build/core/asyncResource.d.ts +28 -0
- package/build/core/atom.d.ts +6 -6
- package/build/core/createAtomFactory.d.ts +7 -0
- package/build/core/createBaseAtom.d.ts +6 -0
- package/build/core/createStore.d.ts +1 -1
- package/build/core/factoryAtom.d.ts +7 -1
- package/build/core/index.d.ts +9 -7
- package/build/core/watch.d.ts +6 -1
- package/build/index.cjs.js +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.esm.js +1 -1
- package/build/react/useComputed.d.ts +2 -1
- package/build/react/useWatch.d.ts +2 -1
- package/package.json +11 -25
- package/build/core/computed.d.ts +0 -1
- package/build/core/effect.d.ts +0 -2
- package/build/core/effectContext.d.ts +0 -3
- package/build/core/graph.d.ts +0 -22
- /package/build/core/{store.d.ts → types.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -6,18 +6,15 @@
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
-
**chrono-state-z** is a
|
|
9
|
+
**chrono-state-z** is a reactive state runtime that keeps business logic outside React.
|
|
10
|
+
It provides **atoms, computed values, async state, effects, scheduling**, with a **headless core** and **thin React bindings**.
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
> **React renders state. Logic lives elsewhere.**
|
|
12
|
+
> **React renders. Logic lives elsewhere.**
|
|
14
13
|
|
|
15
14
|
---
|
|
16
15
|
|
|
17
16
|
## ✨ Why chrono-state-z?
|
|
18
17
|
|
|
19
|
-
Use chrono-state-z when you need:
|
|
20
|
-
|
|
21
18
|
- Predictable state & side-effects
|
|
22
19
|
- Complex async flows (fetch → invalidate → retry)
|
|
23
20
|
- Logic reusable outside React (tests, workers, backend)
|
|
@@ -41,10 +38,48 @@ Use chrono-state-z when you need:
|
|
|
41
38
|
## 📦 Installation
|
|
42
39
|
|
|
43
40
|
```bash
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
npm install chrono-state-z
|
|
42
|
+
# If using React:
|
|
43
|
+
npm install react
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## ⚡ Quick Start
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { atom, computed, asyncAtom } from "chrono-state-z";
|
|
52
|
+
|
|
53
|
+
const count = atom(0);
|
|
54
|
+
const double = computed(() => count() * 2);
|
|
55
|
+
|
|
56
|
+
const user = asyncAtom(async () =>
|
|
57
|
+
fetch("https://jsonplaceholder.typicode.com/todos/1")
|
|
58
|
+
.then(r => r.json())
|
|
59
|
+
);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { useAtom, useComputed } from "chrono-state-z";
|
|
64
|
+
|
|
65
|
+
function App() {
|
|
66
|
+
const value = useAtom(count);
|
|
67
|
+
const doubled = useComputed(double);
|
|
68
|
+
const username = useComputed(() => user()?.title);
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<button onClick={() => count.set(c => c + 1)}>
|
|
72
|
+
{value}
|
|
73
|
+
</button>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
46
77
|
```
|
|
47
78
|
|
|
79
|
+
✨ Fine-grained updates.
|
|
80
|
+
✨ Suspense-ready async.
|
|
81
|
+
✨ No reducers. No boilerplate.
|
|
82
|
+
|
|
48
83
|
---
|
|
49
84
|
|
|
50
85
|
## 🔹 Core Usage
|
|
@@ -269,6 +304,8 @@ function SavingBadge({ store }) {
|
|
|
269
304
|
```ts
|
|
270
305
|
import { useWatch } from 'chrono-state-z'
|
|
271
306
|
|
|
307
|
+
const user = atom<{ role?: string } | null>(null)
|
|
308
|
+
|
|
272
309
|
function AuthGuard() {
|
|
273
310
|
useWatch(
|
|
274
311
|
() => user(),
|
|
@@ -317,7 +354,7 @@ export function createUserLogic() {
|
|
|
317
354
|
```tsx
|
|
318
355
|
function UserView({ logic }) {
|
|
319
356
|
const user = useAtom(logic.user)
|
|
320
|
-
const name = useComputed(
|
|
357
|
+
const name = useComputed(logic.name)
|
|
321
358
|
|
|
322
359
|
return (
|
|
323
360
|
<>
|
|
@@ -331,16 +368,74 @@ function UserView({ logic }) {
|
|
|
331
368
|
|
|
332
369
|
---
|
|
333
370
|
|
|
334
|
-
##
|
|
371
|
+
## 🔍 Comparison
|
|
372
|
+
|
|
373
|
+
<b>This is not about “better” — it's about architectural.</b>
|
|
374
|
+
|
|
375
|
+
| Feature | chrono-state-z | Redux Toolkit | Zustand | Jotai | MobX |
|
|
376
|
+
| --------------------------- | -------------- | ------------- | -------- | ----- | ---- |
|
|
377
|
+
| Fine-grained reactivity | ✅ | ❌ | ⚠️ | ✅ | ✅ |
|
|
378
|
+
| Built-in async primitives | ✅ | ⚠️ | ❌ | ⚠️ | ❌ |
|
|
379
|
+
| Scheduler / priority system | ✅ | ❌ | ❌ | ❌ | ❌ |
|
|
380
|
+
| Headless (non-React) core | ✅ | ✅ | ⚠️ | ⚠️ | ✅ |
|
|
381
|
+
| Boilerplate level | ✅ | ❌ | ✅ | ✅ | ⚠️ |
|
|
382
|
+
| Devtools maturity | ⚠️ | ✅ | ✅ | ⚠️ | ✅ |
|
|
383
|
+
| Learning curve | ⚠️ | ⚠️ | ✅ | ✅ | ⚠️ |
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
<br />
|
|
387
|
+
|
|
388
|
+
<b>📝 Notes</b>
|
|
389
|
+
|
|
390
|
+
⚠️ Fine-grained in Zustand: achieved via selectors, but not dependency-tracked graph-level.
|
|
391
|
+
|
|
392
|
+
⚠️ Async in Redux / Jotai / Recoil: supported via patterns (thunks, query libs, async selectors), not core-first primitives.
|
|
393
|
+
|
|
394
|
+
⚠️ Headless in Zustand/Jotai: possible, but primarily designed for React usage.
|
|
395
|
+
|
|
396
|
+
⚠️ Devtools: Redux and MobX have mature ecosystems; newer libs are still evolving.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## ⚖️ Strengths Compared to Others
|
|
401
|
+
|
|
402
|
+
<b>vs Redux Toolkit</b>
|
|
403
|
+
|
|
404
|
+
- More fine-grained updates
|
|
405
|
+
- Less reducer boilerplate
|
|
406
|
+
- Built-in reactive primitives
|
|
407
|
+
- Redux has stronger ecosystem & devtools
|
|
408
|
+
|
|
409
|
+
<b>vs Zustand</b>
|
|
410
|
+
|
|
411
|
+
- More structured async handling
|
|
412
|
+
- Explicit intent layer
|
|
413
|
+
- Built-in scheduler support
|
|
414
|
+
- Zustand is simpler & lighter for small apps
|
|
415
|
+
|
|
416
|
+
<b>vs Jotai</b>
|
|
417
|
+
|
|
418
|
+
- More explicit effect + scheduler control
|
|
419
|
+
- Async-first primitives
|
|
420
|
+
- Jotai is more minimal and React-native
|
|
421
|
+
|
|
422
|
+
<b>vs MobX</b>
|
|
423
|
+
|
|
424
|
+
- More explicit dependency graph (no proxy magic)
|
|
425
|
+
- Better control over update priority
|
|
426
|
+
- MobX is more ergonomic for mutable patterns
|
|
427
|
+
|
|
428
|
+
<b>vs Recoil</b>
|
|
429
|
+
|
|
430
|
+
- Headless core (not React-bound)
|
|
431
|
+
- Explicit effect system
|
|
432
|
+
- Recoil has better React DevTools integration
|
|
433
|
+
|
|
434
|
+
<b>vs Solid signals</b>
|
|
335
435
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
| Async primitives | ✅ | ⚠️ | ❌ | ⚠️ |
|
|
340
|
-
| Intent / effect layer | ✅ | ⚠️ | ❌ | ❌ |
|
|
341
|
-
| Scheduler / priority | ✅ | ❌ | ❌ | ❌ |
|
|
342
|
-
| Headless (non-React) core | ✅ | ❌ | ⚠️ | ❌ |
|
|
343
|
-
| Testability | ✅ | ⚠️ | ⚠️ | ❌ |
|
|
436
|
+
- Similar fine-grained reactive model
|
|
437
|
+
- Designed for React ecosystem
|
|
438
|
+
- Solid is framework-native and extremely optimized
|
|
344
439
|
|
|
345
440
|
---
|
|
346
441
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonResource } from "./asyncResource";
|
|
2
2
|
export type AsyncAtom<T> = {
|
|
3
|
-
(): T;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,6 +1,8 @@
|
|
|
1
1
|
import type { Priority } from "intentx-core-z";
|
|
2
2
|
export type AsyncComputed<T> = {
|
|
3
|
-
(): T;
|
|
4
|
-
invalidate(
|
|
3
|
+
(): T | undefined;
|
|
4
|
+
invalidate(priority?: Priority): void;
|
|
5
|
+
status(): string;
|
|
6
|
+
error(): any;
|
|
5
7
|
};
|
|
6
8
|
export declare function asyncComputed<T>(getter: (signal?: AbortSignal) => Promise<T>, priority?: Priority): AsyncComputed<T>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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>;
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,6 @@
|
|
|
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
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./atom";
|
|
2
|
+
export * from "./asyncComputed";
|
|
3
|
+
export * from "./createAtomFactory";
|
|
3
4
|
export { asyncAtom } from "./asyncAtom";
|
|
4
|
-
export {
|
|
5
|
-
export { effect } from "
|
|
6
|
-
export
|
|
5
|
+
export { computed } from "intentx-core-z";
|
|
6
|
+
export { effect } from "intentx-core-z";
|
|
7
|
+
export * from "./watch";
|
|
7
8
|
export { createStore } from "./createStore";
|
|
8
|
-
export
|
|
9
|
-
export type { Store, Subscriber } from "./
|
|
9
|
+
export * from "./selector";
|
|
10
|
+
export type { Store, Subscriber } from "./types";
|
|
10
11
|
export { factoryAtom } from "./factoryAtom";
|
|
12
|
+
export { transaction } from "./transaction";
|
package/build/core/watch.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import type { Priority } from "intentx-core-z";
|
|
2
|
-
export
|
|
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;
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var e=require("intentx-core-z"),t=require("react");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(t);function o(e){return function(t,r){const n=e(t),o=n.set;return n.set=(e,t="normal")=>{const s=n(),c=r?r(e,s):e;o(c,t)},n.update=(e,t="normal")=>{n.set(e(n()),t)},n}}function s(e){const t=o(e);return function(e,r){var n;const o=null!==(n=null==r?void 0:r.equals)&&void 0!==n?n:Object.is;return t(e,(e,t)=>o(e,t)?t:e)}}function c(e){const t=o(e);return function(e,r){return t(e,r)}}const u=s(e.signal),a=c(e.signal);function i(t,r){var n,o;const s=null!==(n=null==r?void 0:r.suspense)&&void 0!==n&&n,c=null!==(o=null==r?void 0:r.priority)&&void 0!==o?o:"normal",a=u({status:"idle"});let i=null;const l=()=>{const e=a();if("loading"===e.status)return e.promise;null==i||i.abort(),i=new AbortController;const r=t(i.signal).then(e=>(a.set({status:"success",data:e},c),e)).catch(e=>{if("AbortError"===(null==e?void 0:e.name))return Promise.resolve(void 0);throw a.set({status:"error",error:e}),e});return a.set({status:"loading",promise:r},c),r},f=()=>{null==i||i.abort()};return{read:()=>{const e=a();switch(e.status){case"success":return e.data;case"error":if(s)throw e.error;return;case"loading":if(s)throw e.promise;return;case"idle":const t=l();if(s)throw t;return}},load:l,cancel:f,invalidate:(t=c)=>{f(),a.set({status:"idle"},t),e.schedule(l,t)},status:()=>a().status,error:()=>"error"===a().status?a().error:void 0,setSuccess:(e,t=c)=>{a.set({status:"success",data:e},t)}}}function l(t,r,n){const{immediate:o=!1,equals:s=Object.is,priority:c="normal"}=null!=n?n:{};let u,a,i=!1;const l=e.effect(()=>{const e=t();if(!i)return i=!0,o&&f(e,u),void(u=e);s(e,u)||(f(e,u),u=e)},c);function f(e,t){const n=a;a=void 0,null==n||n(),r(e,t,e=>{a=e})}return()=>{null==a||a(),l()}}function f(e,t=Object.is){let r,n=!1;return o=>{const s=e(o);return n&&t(r,s)?r:(n=!0,r=s,s)}}function d(e,t,r,n,o=Object.is){const s=f(r,o);let c=!1;const u=()=>{c||n(s(e()))};u();const a=t(u);return()=>{c=!0,a()}}const p=e.createScope("default");function m(t){return n.useSyncExternalStore(r=>e.effect(()=>{t(),r()}),t,t)}Object.defineProperty(exports,"computed",{enumerable:!0,get:function(){return e.computed}}),Object.defineProperty(exports,"createScope",{enumerable:!0,get:function(){return e.createScope}}),Object.defineProperty(exports,"effect",{enumerable:!0,get:function(){return e.effect}}),Object.defineProperty(exports,"transaction",{enumerable:!0,get:function(){return e.batch}}),exports.asyncAtom=function(e,t){const r=i(e,t),n=()=>r.read();return n.load=r.load,n.cancel=r.cancel,n.invalidate=r.invalidate,n.status=r.status,n.error=r.error,n.setSuccess=e=>r.setSuccess(e),n},exports.asyncComputed=function(e,t="normal"){const r=i(e,{suspense:!0,priority:t}),n=()=>r.read();return n.invalidate=r.invalidate,n.status=r.status,n.error=r.error,n},exports.atom=u,exports.atomMiddleware=a,exports.createAtomFactory=s,exports.createAtomWithMiddlewareFactory=c,exports.createSelector=f,exports.createStore=function(t,r=p){let n=t;const o=new Set,s=e.createIntentBus((e,t)=>{const r=new AbortController;return{payload:e,scope:t,state:n,signal:r.signal,setState(e){e(n),o.forEach(e=>e())},emit:(e,r)=>s.emit(e,r,t)}});return{scope:r,state:()=>n,setState(e){e(n),o.forEach(e=>e())},subscribe:e=>(o.add(e),()=>o.delete(e)),emit:(e,t)=>s.emit(e,t,r),on:(e,t)=>s.on(e,t,r),watch:(e,t,r)=>d(()=>n,e=>(o.add(e),()=>o.delete(e)),e,t,r)}},exports.factoryAtom=function(e,t){var r;const n=null!==(r=null==t?void 0:t.weak)&&void 0!==r&&r,o=n?new WeakMap:new Map,s=t=>{const r=o.get(t);if(void 0!==r)return r;const n=e(t);return o.set(t,n),n};return s.delete=e=>{n||o.delete(e)},s.clear=()=>{n||o.clear()},s},exports.readonlyAtom=function(e){return()=>e()},exports.scheduleReactJob=function(e,r="normal"){"low"===r?t.startTransition(e):e()},exports.selectAtom=function(t,r,n,o){var s;const c=null!==(s=null==o?void 0:o.isEqual)&&void 0!==s?s:Object.is;let u;return e.effect(()=>{const e=r(t());void 0!==u&&c(u,e)||(u=e,((null==o?void 0:o.immediate)||void 0!==u)&&n(e))})},exports.useAtom=m,exports.useAtomSelector=function(r,n,o=Object.is){const s=t.useRef(f(n,o)),c=()=>s.current(r());return t.useSyncExternalStore(t=>e.effect(()=>{r(),t()}),c,c)},exports.useBatch=function(){return e.batch},exports.useComputed=function(t,r=[]){return m(n.useMemo(()=>e.computed(t),r))},exports.useEffectReact=function(t,r="normal"){const o=n.useRef(t);o.current=t,n.useEffect(()=>{const t=e.effect(()=>{o.current()},r);return()=>t()},[r])},exports.useFactoryAtom=function(e,t){const r=n.useRef(e);r.current=e;const o=n.useRef(null),s=n.useRef(null);return null!==o.current&&s.current===t||(o.current=r.current(t),s.current=t),m(o.current)},exports.useStore=function(e){return t.useSyncExternalStore(e.subscribe,e.state,e.state)},exports.useStoreSelector=function(e,t,r=Object.is){const o=n.useRef(t);o.current=t;const s=n.useRef(f(e=>o.current(e),r)),c=n.useCallback(()=>s.current(e.state()),[e]);return n.useSyncExternalStore(e.subscribe,c,c)},exports.useWatch=function(e,t,r){const o=n.useRef(t);o.current=t;const s=n.useRef(r);s.current=r,n.useEffect(()=>{const t=l(e,e=>{o.current(e)},s.current);return()=>null==t?void 0:t()},[e])},exports.watch=l,exports.watchSelector=d;
|
package/build/index.d.ts
CHANGED
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{signal as t,schedule as e,effect as n,createScope as r,createIntentBus as s,batch as o,computed as u}from"intentx-core-z";export{computed,createScope,effect,batch as transaction}from"intentx-core-z";import*as c from"react";import i,{startTransition as a}from"react";function l(t){return function(e,n){const r=t(e),s=r.set;return r.set=(t,e="normal")=>{const o=r(),u=n?n(t,o):t;s(u,e)},r.update=(t,e="normal")=>{r.set(t(r()),e)},r}}function f(t){const e=l(t);return function(t,n){var r;const s=null!==(r=null==n?void 0:n.equals)&&void 0!==r?r:Object.is;return e(t,(t,e)=>s(t,e)?e:t)}}function d(t){const e=l(t);return function(t,n){return e(t,n)}}const v=f(t),m=d(t);function p(t){return()=>t()}function b(t,n){var r,s;const o=null!==(r=null==n?void 0:n.suspense)&&void 0!==r&&r,u=null!==(s=null==n?void 0:n.priority)&&void 0!==s?s:"normal",c=v({status:"idle"});let i=null;const a=()=>{const e=c();if("loading"===e.status)return e.promise;null==i||i.abort(),i=new AbortController;const n=t(i.signal).then(t=>(c.set({status:"success",data:t},u),t)).catch(t=>{if("AbortError"===(null==t?void 0:t.name))return Promise.resolve(void 0);throw c.set({status:"error",error:t}),t});return c.set({status:"loading",promise:n},u),n},l=()=>{null==i||i.abort()};return{read:()=>{const t=c();switch(t.status){case"success":return t.data;case"error":if(o)throw t.error;return;case"loading":if(o)throw t.promise;return;case"idle":const e=a();if(o)throw e;return}},load:a,cancel:l,invalidate:(t=u)=>{l(),c.set({status:"idle"},t),e(a,t)},status:()=>c().status,error:()=>"error"===c().status?c().error:void 0,setSuccess:(t,e=u)=>{c.set({status:"success",data:t},e)}}}function S(t,e="normal"){const n=b(t,{suspense:!0,priority:e}),r=()=>n.read();return r.invalidate=n.invalidate,r.status=n.status,r.error=n.error,r}function w(t,e){const n=b(t,e),r=()=>n.read();return r.load=n.load,r.cancel=n.cancel,r.invalidate=n.invalidate,r.status=n.status,r.error=n.error,r.setSuccess=t=>n.setSuccess(t),r}function h(t,e,r){const{immediate:s=!1,equals:o=Object.is,priority:u="normal"}=null!=r?r:{};let c,i,a=!1;const l=n(()=>{const e=t();if(!a)return a=!0,s&&f(e,c),void(c=e);o(e,c)||(f(e,c),c=e)},u);function f(t,n){const r=i;i=void 0,null==r||r(),e(t,n,t=>{i=t})}return()=>{null==i||i(),l()}}function E(t,e=Object.is){let n,r=!1;return s=>{const o=t(s);return r&&e(n,o)?n:(r=!0,n=o,o)}}function R(t,e,r,s){var o;const u=null!==(o=null==s?void 0:s.isEqual)&&void 0!==o?o:Object.is;let c;return n(()=>{const n=e(t());void 0!==c&&u(c,n)||(c=n,((null==s?void 0:s.immediate)||void 0!==c)&&r(n))})}function x(t,e,n,r,s=Object.is){const o=E(n,s);let u=!1;const c=()=>{u||r(o(t()))};c();const i=e(c);return()=>{u=!0,i()}}const y=r("default");function g(t,e=y){let n=t;const r=new Set,o=s((t,e)=>{const s=new AbortController;return{payload:t,scope:e,state:n,signal:s.signal,setState(t){t(n),r.forEach(t=>t())},emit:(t,n)=>o.emit(t,n,e)}});return{scope:e,state:()=>n,setState(t){t(n),r.forEach(t=>t())},subscribe:t=>(r.add(t),()=>r.delete(t)),emit:(t,n)=>o.emit(t,n,e),on:(t,n)=>o.on(t,n,e),watch:(t,e,s)=>x(()=>n,t=>(r.add(t),()=>r.delete(t)),t,e,s)}}function j(t,e){var n;const r=null!==(n=null==e?void 0:e.weak)&&void 0!==n&&n,s=r?new WeakMap:new Map,o=e=>{const n=s.get(e);if(void 0!==n)return n;const r=t(e);return s.set(e,r),r};return o.delete=t=>{r||s.delete(t)},o.clear=()=>{r||s.clear()},o}function O(t){return c.useSyncExternalStore(e=>n(()=>{t(),e()}),t,t)}function k(t,e,r=Object.is){const s=i.useRef(E(e,r)),o=()=>s.current(t());return i.useSyncExternalStore(e=>n(()=>{t(),e()}),o,o)}function q(){return o}function A(t,e=[]){return O(c.useMemo(()=>u(t),e))}function C(t,e="normal"){const r=c.useRef(t);r.current=t,c.useEffect(()=>{const t=n(()=>{r.current()},e);return()=>t()},[e])}function M(t,e){const n=c.useRef(t);n.current=t;const r=c.useRef(null),s=c.useRef(null);return null!==r.current&&s.current===e||(r.current=n.current(e),s.current=e),O(r.current)}function z(t){return i.useSyncExternalStore(t.subscribe,t.state,t.state)}function P(t,e,n=Object.is){const r=c.useRef(e);r.current=e;const s=c.useRef(E(t=>r.current(t),n)),o=c.useCallback(()=>s.current(t.state()),[t]);return c.useSyncExternalStore(t.subscribe,o,o)}function W(t,e,n){const r=c.useRef(e);r.current=e;const s=c.useRef(n);s.current=n,c.useEffect(()=>{const e=h(t,t=>{r.current(t)},s.current);return()=>null==e?void 0:e()},[t])}function B(t,e="normal"){"low"===e?a(t):t()}export{w as asyncAtom,S as asyncComputed,v as atom,m as atomMiddleware,f as createAtomFactory,d as createAtomWithMiddlewareFactory,E as createSelector,g as createStore,j as factoryAtom,p as readonlyAtom,B as scheduleReactJob,R as selectAtom,O as useAtom,k as useAtomSelector,q as useBatch,A as useComputed,C as useEffectReact,M as useFactoryAtom,z as useStore,P as useStoreSelector,W as useWatch,h as watch,x as watchSelector};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function useComputed<T>(fn: () => T, deps?: React.DependencyList): T;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { WatchOptions } from "../core/watch";
|
|
2
|
+
export declare function useWatch<T>(getter: () => T, fn: (val: T) => void, options?: WatchOptions<T>): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrono-state-z",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.2.0",
|
|
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,
|
|
@@ -9,25 +9,13 @@
|
|
|
9
9
|
"main": "build/index.cjs.js",
|
|
10
10
|
"module": "build/index.esm.js",
|
|
11
11
|
"types": "build/index.d.ts",
|
|
12
|
-
|
|
13
12
|
"exports": {
|
|
14
13
|
".": {
|
|
15
14
|
"types": "./build/index.d.ts",
|
|
16
15
|
"import": "./build/index.esm.js",
|
|
17
16
|
"require": "./build/index.cjs.js"
|
|
18
|
-
},
|
|
19
|
-
"./react": {
|
|
20
|
-
"types": "./build/react/index.d.ts",
|
|
21
|
-
"import": "./build/react/index.esm.js",
|
|
22
|
-
"require": "./build/react/index.cjs.js"
|
|
23
|
-
},
|
|
24
|
-
"./devtools": {
|
|
25
|
-
"types": "./build/devtools/index.d.ts",
|
|
26
|
-
"import": "./build/devtools/index.esm.js",
|
|
27
|
-
"require": "./build/devtools/index.cjs.js"
|
|
28
17
|
}
|
|
29
18
|
},
|
|
30
|
-
|
|
31
19
|
"files": [
|
|
32
20
|
"build"
|
|
33
21
|
],
|
|
@@ -43,35 +31,33 @@
|
|
|
43
31
|
"type": "git",
|
|
44
32
|
"url": "https://github.com/delpikye-v/chrono-state.git"
|
|
45
33
|
},
|
|
46
|
-
|
|
47
34
|
"homepage": "https://github.com/delpikye-v/chrono-state",
|
|
48
|
-
|
|
49
35
|
"bugs": {
|
|
50
36
|
"url": "https://github.com/delpikye-v/chrono-state/issues"
|
|
51
37
|
},
|
|
52
|
-
|
|
53
38
|
"keywords": [
|
|
54
39
|
"state-management",
|
|
40
|
+
"react-state",
|
|
55
41
|
"reactive",
|
|
42
|
+
"fine-grained",
|
|
43
|
+
"signals",
|
|
56
44
|
"atom",
|
|
57
45
|
"computed",
|
|
58
46
|
"async-state",
|
|
47
|
+
"scheduler",
|
|
48
|
+
"deterministic",
|
|
59
49
|
"intent",
|
|
60
|
-
"intent-first",
|
|
61
50
|
"logic-first",
|
|
62
|
-
"effects",
|
|
63
|
-
"scheduler",
|
|
64
51
|
"headless",
|
|
65
|
-
"react",
|
|
66
52
|
"react-hooks",
|
|
67
53
|
"react-18"
|
|
68
54
|
],
|
|
69
|
-
|
|
70
55
|
"peerDependencies": {
|
|
71
|
-
"react": "
|
|
72
|
-
|
|
56
|
+
"react": ">=18"
|
|
57
|
+
},
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"intentx-core-z": "^2.2.1"
|
|
73
60
|
},
|
|
74
|
-
|
|
75
61
|
"devDependencies": {
|
|
76
62
|
"@rollup/plugin-commonjs": "^25.0.0",
|
|
77
63
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
package/build/core/computed.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function computed<T>(getter: () => T): () => T;
|
package/build/core/effect.d.ts
DELETED
package/build/core/graph.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type NodeType = 'atom' | 'computed' | 'effect';
|
|
2
|
-
export type GraphNode = {
|
|
3
|
-
id: number;
|
|
4
|
-
name?: string;
|
|
5
|
-
type: NodeType;
|
|
6
|
-
value?: any;
|
|
7
|
-
deps: Set<number>;
|
|
8
|
-
highlighted?: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type GraphSnapshotNode = {
|
|
11
|
-
id: number;
|
|
12
|
-
name?: string;
|
|
13
|
-
type: NodeType;
|
|
14
|
-
value?: any;
|
|
15
|
-
deps: number[];
|
|
16
|
-
highlighted?: boolean;
|
|
17
|
-
};
|
|
18
|
-
export declare function trackNode(type: NodeType, name?: string, value?: any): GraphNode;
|
|
19
|
-
export declare function linkNodes(from: GraphNode, to: GraphNode): void;
|
|
20
|
-
export declare function getGraphSnapshot(): GraphSnapshotNode[];
|
|
21
|
-
export declare function highlightNode(id: number): void;
|
|
22
|
-
export declare function clearHighlights(): void;
|
|
File without changes
|