chrono-state-z 2.1.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 CHANGED
@@ -6,18 +6,15 @@
6
6
 
7
7
  ---
8
8
 
9
- **chrono-state-z** is a **reactive, intent-first state runtime** designed to keep **business logic outside React**.
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
- It provides **atoms, computed values, async state, effects, scheduling**, with a **headless core** and **thin React bindings**.
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)
@@ -28,23 +25,61 @@ Use chrono-state-z when you need:
28
25
 
29
26
  ## 🧠 Mental Model
30
27
 
31
- - Atom small reactive state unit
32
- - Computed derived value, cached and reactive
33
- - AsyncAtom async state with suspense-style read
34
- - Effect reactive side-effect runner
35
- - Scheduler priority-based execution control
36
- - Store / Intent intent-driven state orchestration
37
- - React hooks thin bindings over the headless core
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
38
35
 
39
36
  ---
40
37
 
41
38
  ## 📦 Installation
42
39
 
43
40
  ```bash
44
- # npm install react ## for react
45
- npm install intentx-core-z chrono-state-z
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
@@ -246,16 +281,11 @@ function StoreView({ store }: { store: Store<any> }) {
246
281
 
247
282
  ```tsx
248
283
  // Only re-renders when saving changes, not the whole store.
249
- import { useStoreSelector } from 'chrono-state-z'
284
+ import { useStoreSelector } from "chrono-state-z"
250
285
 
251
286
  function SavingBadge({ store }) {
252
287
  const saving = useStoreSelector(store, s => s.saving)
253
- // const saving = useStoreSelector(
254
- // store,
255
- // s => s.meta,
256
- // shallowEqual
257
- // )
258
- return saving ? 'Saving...' : 'Idle'
288
+ return saving ? "Saving..." : "Idle"
259
289
  }
260
290
 
261
291
  ```
@@ -269,6 +299,8 @@ function SavingBadge({ store }) {
269
299
  ```ts
270
300
  import { useWatch } from 'chrono-state-z'
271
301
 
302
+ const user = atom<{ role?: string } | null>(null)
303
+
272
304
  function AuthGuard() {
273
305
  useWatch(
274
306
  () => user(),
@@ -317,7 +349,7 @@ export function createUserLogic() {
317
349
  ```tsx
318
350
  function UserView({ logic }) {
319
351
  const user = useAtom(logic.user)
320
- const name = useComputed(() => logic.name())
352
+ const name = useComputed(logic.name)
321
353
 
322
354
  return (
323
355
  <>
@@ -331,16 +363,74 @@ function UserView({ logic }) {
331
363
 
332
364
  ---
333
365
 
334
- ## 📊 Comparison with Other Libraries
366
+ ## 🔍 Comparison
367
+
368
+ <b>This is not about “better” — it's about architectural.</b>
369
+
370
+ | Feature | chrono-state-z | Redux Toolkit | Zustand | Jotai | MobX |
371
+ | --------------------------- | -------------- | ------------- | -------- | ----- | ---- |
372
+ | Fine-grained reactivity | ✅ | ❌ | ⚠️ | ✅ | ✅ |
373
+ | Built-in async primitives | ✅ | ⚠️ | ❌ | ⚠️ | ❌ |
374
+ | Scheduler / priority system | ✅ | ❌ | ❌ | ❌ | ❌ |
375
+ | Headless (non-React) core | ✅ | ✅ | ⚠️ | ⚠️ | ✅ |
376
+ | Boilerplate level | ✅ | ❌ | ✅ | ✅ | ⚠️ |
377
+ | Devtools maturity | ⚠️ | ✅ | ✅ | ⚠️ | ✅ |
378
+ | Learning curve | ⚠️ | ⚠️ | ✅ | ✅ | ⚠️ |
379
+
380
+
381
+ <br />
382
+
383
+ <b>📝 Notes</b>
384
+
385
+ ⚠️ Fine-grained in Zustand: achieved via selectors, but not dependency-tracked graph-level.
386
+
387
+ ⚠️ Async in Redux / Jotai / Recoil: supported via patterns (thunks, query libs, async selectors), not core-first primitives.
388
+
389
+ ⚠️ Headless in Zustand/Jotai: possible, but primarily designed for React usage.
390
+
391
+ ⚠️ Devtools: Redux and MobX have mature ecosystems; newer libs are still evolving.
392
+
393
+ ---
394
+
395
+ ## ⚖️ Strengths Compared to Others
396
+
397
+ <b>vs Redux Toolkit</b>
398
+
399
+ - More fine-grained updates
400
+ - Less reducer boilerplate
401
+ - Built-in reactive primitives
402
+ - Redux has stronger ecosystem & devtools
403
+
404
+ <b>vs Zustand</b>
405
+
406
+ - More structured async handling
407
+ - Explicit intent layer
408
+ - Built-in scheduler support
409
+ - Zustand is simpler & lighter for small apps
410
+
411
+ <b>vs Jotai</b>
412
+
413
+ - More explicit effect + scheduler control
414
+ - Async-first primitives
415
+ - Jotai is more minimal and React-native
416
+
417
+ <b>vs MobX</b>
418
+
419
+ - More explicit dependency graph (no proxy magic)
420
+ - Better control over update priority
421
+ - MobX is more ergonomic for mutable patterns
422
+
423
+ <b>vs Recoil</b>
424
+
425
+ - Headless core (not React-bound)
426
+ - Explicit effect system
427
+ - Recoil has better React DevTools integration
428
+
429
+ <b>vs Solid signals</b>
335
430
 
336
- | Feature | chrono-state-z | Redux | Zustand | Jotai |
337
- |---------------------------|---------------- |-------|--------- |------- |
338
- | Fine-grained reactivity | ✅ | ❌ | ⚠️ | ✅ |
339
- | Async primitives | ✅ | ⚠️ | ❌ | ⚠️ |
340
- | Intent / effect layer | ✅ | ⚠️ | ❌ | ❌ |
341
- | Scheduler / priority | ✅ | ❌ | ❌ | ❌ |
342
- | Headless (non-React) core | ✅ | ❌ | ⚠️ | ❌ |
343
- | Testability | ✅ | ⚠️ | ⚠️ | ❌ |
431
+ - Similar fine-grained reactive model
432
+ - Designed for React ecosystem
433
+ - Solid is framework-native and extremely optimized
344
434
 
345
435
  ---
346
436
 
@@ -1 +1 @@
1
- "use strict";var t=require("intentx-core-z"),e=require("react");function n(t){var e=Object.create(null);return t&&Object.keys(t).forEach(function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}}),e.default=t,Object.freeze(e)}var r=n(e);const o={activeEffect:null};function c(e){let n=e;const r=new Set,c=new Set,u=()=>(o.activeEffect&&c.add(o.activeEffect),n);return u.set=(e,o="normal")=>{Object.is(e,n)||(n=e,c.forEach(e=>t.schedule(e,o)),r.forEach(e=>t.schedule(e,o)))},u.subscribe=t=>(r.add(t),()=>r.delete(t)),u}function u(e){let n,r=!0;const c=new Set,u=()=>{r||(r=!0,c.forEach(e=>t.schedule(e)))};return()=>{if(o.activeEffect&&c.add(o.activeEffect),r){const t=o.activeEffect;o.activeEffect=u,n=e(),r=!1,o.activeEffect=t}return n}}function l(e,n="normal"){let r=null,c=!1;const u=()=>{if(!c){null==r||r();try{o.activeEffect=u;const t=e();"function"==typeof t&&(r=t)}finally{o.activeEffect=null}}};return t.schedule(u,n),()=>{c=!0,null==r||r(),r=null}}function s(t,e,n="normal"){return l(()=>{e(t())},n)}function a(t,e=Object.is){let n,r=!1;return o=>{const c=t(o);return r&&e(n,c)?n:(r=!0,n=c,c)}}const i=t.createScope("default");function f(t){return r.useSyncExternalStore(e=>{let n=t();return l(()=>{const r=t();Object.is(n,r)||(n=r,e())})},t,t)}Object.defineProperty(exports,"createScope",{enumerable:!0,get:function(){return t.createScope}}),exports.asyncAtom=function(e){const n=c(null);let r=null,o=null;const u=()=>(r||(o=new AbortController,r=e(o.signal).then(t=>((null==o?void 0:o.signal.aborted)||n.set(t),t)).finally(()=>{r=null})),r),l=()=>{null==o||o.abort(),o=null,r=null},s=()=>{const t=n();if(null===t)throw u();return t};return s.set=n.set,s.load=u,s.cancel=l,s.invalidate=(e="normal")=>{l(),t.schedule(()=>{try{u()}catch{}},e)},s},exports.asyncComputed=function(e,n="normal"){const r=c(void 0);let o=null,u=null,l=null;const s=()=>(o||(u=new AbortController,l=null,o=e(u.signal).then(t=>((null==u?void 0:u.signal.aborted)||r.set(t,n),t)).catch(t=>{throw(null==u?void 0:u.signal.aborted)||(l=t),t}).finally(()=>{o=null})),o),a=()=>{const t=r();if(l)throw l;if(void 0===t)throw s();return t};return a.invalidate=(e=n)=>{null==u||u.abort(),u=null,o=null,t.schedule(()=>{try{s()}catch{}},e)},a},exports.atom=c,exports.computed=u,exports.createSelector=a,exports.createStore=function(e,n=i){let r=e;const o=new Set,c=t.createIntentBus((t,e)=>{const n=new AbortController;return{payload:t,scope:e,state:r,signal:n.signal,setState(t){t(r),o.forEach(t=>t())},emit:(t,n)=>c.emit(t,n,e)}});return{scope:n,state:()=>r,setState(t){t(r),o.forEach(t=>t())},subscribe:t=>(o.add(t),()=>o.delete(t)),emit:(t,e)=>c.emit(t,e,n),on:(t,e)=>c.on(t,e,n),watch:(t,e,n)=>function(t,e,n,r,o=Object.is){const c=a(n,o);let u=!1;const l=()=>{u||r(c(t()))};l();const s=e(l);return()=>{u=!0,s()}}(()=>r,t=>(o.add(t),()=>o.delete(t)),t,e,n)}},exports.effect=l,exports.factoryAtom=function(t){const e=new Map;return n=>{let r=e.get(n);return r||(r=t(n),e.set(n,r)),r}},exports.scheduleReactJob=function(t,n="normal"){"low"===n?e.startTransition(t):t()},exports.selectAtom=function(t,e,n,r){var o;const c=null!==(o=null==r?void 0:r.isEqual)&&void 0!==o?o:Object.is;let u;return l(()=>{const o=e(t());void 0!==u&&c(u,o)||(u=o,((null==r?void 0:r.immediate)||void 0!==u)&&n(o))})},exports.useAtom=f,exports.useAtomSelector=function(t,e,n=Object.is){const o=r.useRef(null),c=()=>{const r=e(t()),c=o.current;return null!==c&&n(c,r)?c:(o.current=r,r)};return r.useSyncExternalStore(e=>l(()=>{t(),e()}),c,c)},exports.useBatch=function(){return t.batch},exports.useComputed=function(t){return f(r.useMemo(()=>u(t),[t]))},exports.useEffectReact=function(t,e="normal"){r.useEffect(()=>{const n=l(t,e);return()=>n()},[t,e])},exports.useFactoryAtom=function(t,e){return f(t(e))},exports.useStore=function(t){return e.useSyncExternalStore(t.subscribe,t.state,t.state)},exports.useStoreSelector=function(t,e,n=Object.is){const o=r.useMemo(()=>a(e,n),[e,n]),c=r.useCallback(()=>o(t.state()),[t,o]);return r.useSyncExternalStore(t.subscribe,c,c)},exports.useWatch=function(t,e){r.useEffect(()=>{const n=s(t,e);return()=>null==n?void 0:n()},[t,e])},exports.watch=s;
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,3 +1,9 @@
1
- export { createScope, Scope } from "intentx-core-z";
2
- export * from './core';
3
- export * from './react';
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";
@@ -1 +1 @@
1
- import{schedule as t,createScope as n,createIntentBus as e,batch as r}from"intentx-core-z";export{createScope}from"intentx-core-z";import*as o from"react";import l,{startTransition as c}from"react";const u={activeEffect:null};function i(n){let e=n;const r=new Set,o=new Set,l=()=>(u.activeEffect&&o.add(u.activeEffect),e);return l.set=(n,l="normal")=>{Object.is(n,e)||(e=n,o.forEach(n=>t(n,l)),r.forEach(n=>t(n,l)))},l.subscribe=t=>(r.add(t),()=>r.delete(t)),l}function s(n){let e,r=!0;const o=new Set,l=()=>{r||(r=!0,o.forEach(n=>t(n)))};return()=>{if(u.activeEffect&&o.add(u.activeEffect),r){const t=u.activeEffect;u.activeEffect=l,e=n(),r=!1,u.activeEffect=t}return e}}function a(n){const e=i(null);let r=null,o=null;const l=()=>(r||(o=new AbortController,r=n(o.signal).then(t=>((null==o?void 0:o.signal.aborted)||e.set(t),t)).finally(()=>{r=null})),r),c=()=>{null==o||o.abort(),o=null,r=null},u=()=>{const t=e();if(null===t)throw l();return t};return u.set=e.set,u.load=l,u.cancel=c,u.invalidate=(n="normal")=>{c(),t(()=>{try{l()}catch{}},n)},u}function f(n,e="normal"){const r=i(void 0);let o=null,l=null,c=null;const u=()=>(o||(l=new AbortController,c=null,o=n(l.signal).then(t=>((null==l?void 0:l.signal.aborted)||r.set(t,e),t)).catch(t=>{throw(null==l?void 0:l.signal.aborted)||(c=t),t}).finally(()=>{o=null})),o),s=()=>{const t=r();if(c)throw c;if(void 0===t)throw u();return t};return s.invalidate=(n=e)=>{null==l||l.abort(),l=null,o=null,t(()=>{try{u()}catch{}},n)},s}function d(n,e="normal"){let r=null,o=!1;const l=()=>{if(!o){null==r||r();try{u.activeEffect=l;const t=n();"function"==typeof t&&(r=t)}finally{u.activeEffect=null}}};return t(l,e),()=>{o=!0,null==r||r(),r=null}}function b(t,n,e="normal"){return d(()=>{n(t())},e)}function v(t,n=Object.is){let e,r=!1;return o=>{const l=t(o);return r&&n(e,l)?e:(r=!0,e=l,l)}}function m(t,n,e,r){var o;const l=null!==(o=null==r?void 0:r.isEqual)&&void 0!==o?o:Object.is;let c;return d(()=>{const o=n(t());void 0!==c&&l(c,o)||(c=o,((null==r?void 0:r.immediate)||void 0!==c)&&e(o))})}const E=n("default");function h(t,n=E){let r=t;const o=new Set,l=e((t,n)=>{const e=new AbortController;return{payload:t,scope:n,state:r,signal:e.signal,setState(t){t(r),o.forEach(t=>t())},emit:(t,e)=>l.emit(t,e,n)}});return{scope:n,state:()=>r,setState(t){t(r),o.forEach(t=>t())},subscribe:t=>(o.add(t),()=>o.delete(t)),emit:(t,e)=>l.emit(t,e,n),on:(t,e)=>l.on(t,e,n),watch:(t,n,e)=>function(t,n,e,r,o=Object.is){const l=v(e,o);let c=!1;const u=()=>{c||r(l(t()))};u();const i=n(u);return()=>{c=!0,i()}}(()=>r,t=>(o.add(t),()=>o.delete(t)),t,n,e)}}function S(t){const n=new Map;return e=>{let r=n.get(e);return r||(r=t(e),n.set(e,r)),r}}function w(t){return o.useSyncExternalStore(n=>{let e=t();return d(()=>{const r=t();Object.is(e,r)||(e=r,n())})},t,t)}function y(t,n,e=Object.is){const r=o.useRef(null),l=()=>{const o=n(t()),l=r.current;return null!==l&&e(l,o)?l:(r.current=o,o)};return o.useSyncExternalStore(n=>d(()=>{t(),n()}),l,l)}function p(){return r}function g(t){return w(o.useMemo(()=>s(t),[t]))}function x(t,n="normal"){o.useEffect(()=>{const e=d(t,n);return()=>e()},[t,n])}function j(t,n){return w(t(n))}function O(t){return l.useSyncExternalStore(t.subscribe,t.state,t.state)}function C(t,n,e=Object.is){const r=o.useMemo(()=>v(n,e),[n,e]),l=o.useCallback(()=>r(t.state()),[t,r]);return o.useSyncExternalStore(t.subscribe,l,l)}function A(t,n){o.useEffect(()=>{const e=b(t,n);return()=>null==e?void 0:e()},[t,n])}function M(t,n="normal"){"low"===n?c(t):t()}export{a as asyncAtom,f as asyncComputed,i as atom,s as computed,v as createSelector,h as createStore,d as effect,S as factoryAtom,M as scheduleReactJob,m as selectAtom,w as useAtom,y as useAtomSelector,p as useBatch,g as useComputed,x as useEffectReact,j as useFactoryAtom,O as useStore,C as useStoreSelector,A as useWatch,b as watch};
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-core-z';
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-core-z';
1
+ import { batch } from 'intentx-state-z';
2
2
  export declare function useBatch(): typeof batch;
@@ -1 +1,2 @@
1
- export declare function useComputed<T>(fn: () => T): T;
1
+ import * as React from 'react';
2
+ export declare function useComputed<T>(fn: () => T, deps?: React.DependencyList): T;
@@ -1,2 +1,2 @@
1
- import { Priority } from 'intentx-core-z';
1
+ import { Priority } from 'intentx-state-z';
2
2
  export declare function useEffectReact(fn: () => void, priority?: Priority): void;
@@ -1 +1,2 @@
1
- export declare function useWatch<T>(getter: () => T, fn: (val: T) => void): void;
1
+ import type { WatchOptions } from "intentx-state-z";
2
+ export declare function useWatch<T>(getter: () => T, fn: (val: T) => void, options?: WatchOptions<T>): void;
package/package.json CHANGED
@@ -1,77 +1,60 @@
1
1
  {
2
2
  "name": "chrono-state-z",
3
- "version": "2.1.0",
4
- "description": "Intent-first, logic-centric reactive state runtime with atoms, computed, async state, effects, and deterministic scheduling. React-agnostic core.",
3
+ "version": "2.2.1-iz",
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",
12
-
13
11
  "exports": {
14
12
  ".": {
15
13
  "types": "./build/index.d.ts",
16
14
  "import": "./build/index.esm.js",
17
15
  "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
16
  }
29
17
  },
30
-
31
18
  "files": [
32
19
  "build"
33
20
  ],
34
-
35
21
  "scripts": {
36
22
  "clean": "rimraf build",
37
23
  "build": "rollup -c",
38
24
  "cb": "npm run clean && npm run build",
39
25
  "prepublishOnly": "npm run cb"
40
26
  },
41
-
42
27
  "repository": {
43
28
  "type": "git",
44
29
  "url": "https://github.com/delpikye-v/chrono-state.git"
45
30
  },
46
-
47
31
  "homepage": "https://github.com/delpikye-v/chrono-state",
48
-
49
32
  "bugs": {
50
33
  "url": "https://github.com/delpikye-v/chrono-state/issues"
51
34
  },
52
-
53
35
  "keywords": [
54
36
  "state-management",
37
+ "react-state",
55
38
  "reactive",
39
+ "fine-grained",
40
+ "signals",
56
41
  "atom",
57
42
  "computed",
58
43
  "async-state",
44
+ "scheduler",
45
+ "deterministic",
59
46
  "intent",
60
- "intent-first",
61
47
  "logic-first",
62
- "effects",
63
- "scheduler",
64
48
  "headless",
65
- "react",
66
49
  "react-hooks",
67
50
  "react-18"
68
51
  ],
69
-
70
52
  "peerDependencies": {
71
- "react": "^18.0.0",
72
- "intentx-core-z": "^2.1.0"
53
+ "react": ">=18"
54
+ },
55
+ "dependencies": {
56
+ "intentx-state-z": "^0.1.1"
73
57
  },
74
-
75
58
  "devDependencies": {
76
59
  "@rollup/plugin-commonjs": "^25.0.0",
77
60
  "@rollup/plugin-node-resolve": "^15.2.3",
@@ -1,9 +0,0 @@
1
- import { Priority } from "intentx-core-z";
2
- export type AsyncAtom<T> = {
3
- (): T;
4
- set(v: T, p?: Priority): void;
5
- load(): Promise<T>;
6
- cancel(): void;
7
- invalidate(p?: Priority): void;
8
- };
9
- export declare function asyncAtom<T>(fetcher: (signal?: AbortSignal) => Promise<T>): AsyncAtom<T>;
@@ -1,6 +0,0 @@
1
- import type { Priority } from "intentx-core-z";
2
- export type AsyncComputed<T> = {
3
- (): T;
4
- invalidate(p?: Priority): void;
5
- };
6
- export declare function asyncComputed<T>(getter: (signal?: AbortSignal) => Promise<T>, priority?: Priority): AsyncComputed<T>;
@@ -1,6 +0,0 @@
1
- import { Priority } from "intentx-core-z";
2
- export type Atom<T> = (() => T) & {
3
- set(v: T, p?: Priority): void;
4
- subscribe(fn: () => void): () => void;
5
- };
6
- export declare function atom<T>(initial: T): Atom<T>;
@@ -1 +0,0 @@
1
- export declare function computed<T>(getter: () => T): () => T;
@@ -1,3 +0,0 @@
1
- import type { Scope } from "intentx-core-z";
2
- import { Store } from "./store";
3
- export declare function createStore<S extends object>(initial: S, scope?: Scope): Store<S>;
@@ -1,2 +0,0 @@
1
- import { Priority } from "intentx-core-z";
2
- export declare function effect(fn: () => void | (() => void), priority?: Priority): () => void;
@@ -1,3 +0,0 @@
1
- export declare const effectContext: {
2
- activeEffect: (() => void) | null;
3
- };
@@ -1 +0,0 @@
1
- export declare function factoryAtom<K, A>(factory: (key: K) => A): (key: K) => A;
@@ -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;
@@ -1,10 +0,0 @@
1
- export { atom } from "./atom";
2
- export { computed } from "./computed";
3
- export { asyncAtom } from "./asyncAtom";
4
- export { asyncComputed } from "./asyncComputed";
5
- export { effect } from "./effect";
6
- export { watch } from "./watch";
7
- export { createStore } from "./createStore";
8
- export { selectAtom, createSelector } from "./selector";
9
- export type { Store, Subscriber } from "./store";
10
- export { factoryAtom } from "./factoryAtom";
@@ -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,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
- };
@@ -1 +0,0 @@
1
- export { batch as transaction } from "intentx-core-z";
@@ -1,2 +0,0 @@
1
- import type { Priority } from "intentx-core-z";
2
- export declare function watch<T>(getter: () => T, fn: (value: T) => void, priority?: Priority): () => void;