react-intent-engine-z 2.0.0 → 2.1.1

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
@@ -5,21 +5,26 @@
5
5
 
6
6
  ---
7
7
 
8
- An **intent-first orchestration engine for React**.
9
- Decouples UI from async flows, side effects, and business logic.
8
+ **react-intent-engine-z** is a lightweight intent orchestration layer
9
+ + Not a state manager, not an event bus.
10
+ + An **intent-first orchestration engine for React**.
11
+ + Decouples UI from async flows, side effects, and business logic.
10
12
 
11
13
  [Live Example](https://codesandbox.io/p/sandbox/kjstrf)
12
14
 
13
15
  ---
14
16
 
15
- ### ✨ Why Use It
17
+ ### ✨ Why/When Use It
16
18
 
17
19
  - Separate business logic from UI
18
20
  - Handle async flows declaratively
19
21
  - Easy testing of intents
20
22
  - Supports multiple engines & scoped state
23
+ - Complex user flows (login → fetch → redirect → notify)
24
+ - Business logic should live outside components
25
+ - Logic must be testable without React
21
26
  - Works with React 17+, React Query, DDD-style architectures
22
-
27
+
23
28
  ---
24
29
 
25
30
  ### 📦 Installation
@@ -27,11 +32,12 @@ Decouples UI from async flows, side effects, and business logic.
27
32
  ```bash
28
33
  npm install react-intent-engine-z use-sync-external-store
29
34
  ```
30
- - use-sync-external-store is required for React 17 compatibility.
35
+ - `use-sync-external-store` is required for React 17 compatibility.
31
36
 
32
37
  ---
33
38
 
34
39
  ### 🧠 Mental Model
40
+
35
41
  ```bash
36
42
  UI Component
37
43
  └─ emits intent
@@ -47,8 +53,10 @@ Intent Engine
47
53
  ### 🚀 Basic Usage
48
54
 
49
55
  ##### 1️⃣ Create Engine
56
+
50
57
  ```ts
51
58
  import { createIntentEngine } from "react-intent-engine-z"
59
+ // import { navigate } from "react-router-dom" // React Router v6
52
60
 
53
61
  export const authEngine = createIntentEngine({
54
62
  initialState: { auth: { user: null, loading: false } },
@@ -64,24 +72,37 @@ export const authEngine = createIntentEngine({
64
72
  ```
65
73
 
66
74
  ##### 2️⃣ Register Handlers
75
+
67
76
  ```ts
68
77
  authEngine.on("auth.login.submit", async (intent, ctx) => {
69
- ctx.set("auth.loading", true)
70
- const user = await ctx.effects.auth.login(intent.payload)
71
- ctx.set("auth.user", user)
72
- ctx.set("auth.loading", false)
78
+ try {
79
+ ctx.set({ auth: { ...ctx.get().auth, loading: true, error: null } })
80
+
81
+ // ✅ Common pattern: call effect
82
+ const user = await ctx.effects.auth.login(intent.payload)
83
+
84
+ // Update store
85
+ ctx.set({ auth: { ...ctx.get().auth, user, loading: false } })
86
+
87
+ // Navigate after success
88
+ // navigate("/dashboard")
89
+ } catch (err: any) {
90
+ ctx.set({ auth: { ...ctx.get().auth, error: err.message, loading: false } })
91
+ }
73
92
  })
74
93
  ```
75
94
  ##### 3️⃣ Provide Engine to React
76
95
 
77
96
  ```ts
78
97
  import { IntentProvider } from "react-intent-engine-z"
98
+
79
99
  <IntentProvider engine={authEngine}>
80
- <LoginForm />
100
+ <LoginButton />
81
101
  </IntentProvider>
82
102
  ```
83
103
 
84
104
  ##### 4️⃣ Emit Intent from UI
105
+
85
106
  ```tsx
86
107
  import { useIntent, useIntentState } from "react-intent-engine-z"
87
108
 
@@ -155,6 +176,9 @@ await engine.emit({
155
176
 
156
177
  expect(engine.store.getState().auth.user).toBeDefined()
157
178
  ```
179
+
180
+ - separates business logic and side effects from UI, making intents fully testable without rendering React components.
181
+
158
182
  ---
159
183
 
160
184
  ### ⚡ Multiple Engines
@@ -168,13 +192,33 @@ import { IntentProvider } from "react-intent-engine-z"
168
192
  <IntentProvider engine={notifEngine}>
169
193
  <NotificationCenter />
170
194
  </IntentProvider>
171
-
172
195
  ```
173
- - Each engine is scoped
174
196
 
197
+ - Each engine is scoped
175
198
  - Supports role-based UI and multiple async flows
176
199
 
177
200
  ---
178
201
 
202
+ ### 🔍 Comparison: Intent Engine vs Redux vs Event Bus vs CQRS / Command Bus
203
+
204
+
205
+ | Criteria | **react-intent-engine-z** | **Redux** | **Event Bus** | **CQRS / Command Bus** |
206
+ | ----------------- | --------------------------------- | ------------------------ | -------------------- | ------------------------------ |
207
+ | Primary goal | Orchestrate **behavior** | Manage **state** | Broadcast events | Handle **commands & queries** |
208
+ | Core focus | **Intent → flow → side effects** | State → reducer → UI | Event → listeners | Command → handler |
209
+ | What UI calls | `emit(intent)` | `dispatch(action)` | `emit(event)` | `dispatch(command)` |
210
+ | Where logic lives | **Intent handlers** | Reducers / middleware | Scattered listeners | Command handlers |
211
+ | Execution order | Controlled | Controlled (middleware) | ❌ Not guaranteed | Controlled |
212
+ | Async flow | ✅ Built-in | Via thunk / saga | Ad-hoc | ✅ First-class |
213
+ | Side effects | First-class | Middleware | Ad-hoc | First-class |
214
+ | State required | ❌ Optional | ✅ Required | ❌ | ❌ |
215
+ | Type safety | ✅ Intent-based | Action-based | ❌ Weak | ✅ Strong |
216
+ | Testability | ✅ Easy (headless) | Medium | ❌ Hard | ✅ Easy |
217
+ | Coupling | Low | Medium | **High** | Low |
218
+ | Learning curve | Low → Medium | High | Low | High |
219
+ | Fit for React | ✅ Excellent | ✅ Excellent | ⚠️ Risky | ⚠️ Overkill |
220
+
221
+ ---
222
+
179
223
  ### 📜 License
180
224
  MIT
@@ -1,2 +1,5 @@
1
+ export { createContext } from "./context";
1
2
  export { createIntentEngine } from "./engine";
2
- export type { Intent, IntentStatus, IntentHandler, } from "./types";
3
+ export { composeMiddleware } from "./middleware";
4
+ export { createStore } from "./store";
5
+ export type { Intent, IntentStatus, IntentHandler, Guard, Middleware, EffectMap, IntentContext } from "./types";
package/build/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var i=t.createContext(null);function a(){var e=t.useContext(i);if(!e)throw new Error("Missing IntentProvider");return e}function c(t){var e={exports:{}};return t(e,e.exports),e.exports}var s="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},l=n.default.useState,f=n.default.useEffect,d=n.default.useLayoutEffect,p=n.default.useDebugValue;function v(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!s(t,n)}catch(t){return!0}}var S="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=l({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return d(function(){o.value=n,o.getSnapshot=e,v(o)&&u({inst:o})},[t,n,e]),f(function(){return v(o)&&u({inst:o}),t(function(){v(o)&&u({inst:o})})},[t]),p(n),n},y={useSyncExternalStore:void 0!==n.default.useSyncExternalStore?n.default.useSyncExternalStore:S},h=c(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=n.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,a=r.useLayoutEffect,c=r.useDebugValue,s=!1,l=!1,f="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var f=n();if(!l){var d=n();o(f,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}var p=(d=u({inst:{value:f,getSnapshot:n}}))[0].inst,v=d[1];return a(function(){p.value=f,p.getSnapshot=n,t(p)&&v({inst:p})},[e,f,n]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(f),f};e.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),_=c(function(t){"production"===process.env.NODE_ENV?t.exports=y:t.exports=h});exports.IntentProvider=function(t){var e=t.engine,r=t.children;return n.default.createElement(i.Provider,{value:e},r)},exports.createIntentEngine=function(t){var e,n,i,a,c,s,l=(i=t.initialState,a=structuredClone(i),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),f=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(a){switch(a.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(l,t,f),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:l,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},exports.useEngine=a,exports.useIntent=function(){var t=a();return function(e){return t.emit(e)}},exports.useIntentState=function(t){var e=a();return _.useSyncExternalStore(function(n){return e.store.subscribe(t,n)},function(){return e.store.getState(t)})},exports.useIntentStatus=function(t){return a().getStatus(t)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function r(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}function o(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){var e=structuredClone(t),n=new Set;return{getState:function(){return e},setState:function(t){e=t(e),n.forEach(function(t){return t()})},subscribe:function(t){return n.add(t),function(){return n.delete(t)}}}}function c(t){return function(e,n){var r=-1;return function i(a){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(a<=r)throw new Error("next() called twice");return r=a,(o=t[a])?[2,o(e,function(){return i(a+1)})]:[2,n()]})})}(0)}}"function"==typeof SuppressedError&&SuppressedError;var s=t.createContext(null);function f(){var e=t.useContext(s);if(!e)throw new Error("Missing IntentProvider");return e}function l(t){var e={exports:{}};return t(e,e.exports),e.exports}var d="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},p=n.default.useState,v=n.default.useEffect,S=n.default.useLayoutEffect,y=n.default.useDebugValue;function h(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!d(t,n)}catch(t){return!0}}var _="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=p({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return S(function(){o.value=n,o.getSnapshot=e,h(o)&&u({inst:o})},[t,n,e]),v(function(){return h(o)&&u({inst:o}),t(function(){h(o)&&u({inst:o})})},[t]),y(n),n},E={useSyncExternalStore:void 0!==n.default.useSyncExternalStore?n.default.useSyncExternalStore:_},O=l(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=n.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,a=r.useLayoutEffect,c=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=n,t(p)&&v({inst:p})},[e,l,n]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),g=l(function(t){"production"===process.env.NODE_ENV?t.exports=E:t.exports=O});exports.IntentProvider=function(t){var e=t.engine,r=t.children;return n.default.createElement(s.Provider,{value:e},r)},exports.composeMiddleware=c,exports.createContext=r,exports.createIntentEngine=function(t){var e,n,s=a(t.initialState),f=null!==(e=t.effects)&&void 0!==e?e:{},l=new Map,d=new Map,p=new Map,v=c(null!==(n=t.middleware)&&void 0!==n?n:[]);return{emit:function t(e){var n;return o(this,void 0,void 0,function(){var i,a=this;return u(this,function(c){switch(c.label){case 0:return i=r(s,t,f),(null===(n=d.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(i)}))?[2]:(p.set(e.type,"pending"),[4,v(e,function(){return o(a,void 0,void 0,function(){var t,n,r;return u(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=l.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,i)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return c.sent(),p.set(e.type,"success"),[2]}})})},on:function(t,e){var n;l.set(t,i(i([],null!==(n=l.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;d.set(t,i(i([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:s,getStatus:function(t){var e;return null!==(e=p.get(t))&&void 0!==e?e:"idle"}}},exports.createStore=a,exports.useEngine=f,exports.useIntent=function(){var t=f();return function(e){return t.emit(e)}},exports.useIntentState=function(e){var n=f(),r=t.useRef();return g.useSyncExternalStore(n.store.subscribe,function(){var t=e(n.store.getState());return Object.is(t,r.current)?r.current:(r.current=t,t)})},exports.useIntentStatus=function(t){var e=f();return g.useSyncExternalStore(function(n){return e.subscribeStatus(t,n)},function(){return e.getStatus(t)})};
@@ -1 +1 @@
1
- import t,{createContext as e,useContext as n}from"react";function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{a(r.next(t))}catch(t){u(t)}}function c(t){try{a(r.throw(t))}catch(t){u(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,c)}a((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function i(t){var e,n,i,c,a,s,l=(i=t.initialState,c=structuredClone(i),a=new Set,{getState:function(){return c},setState:function(t){c=t(c),a.forEach(function(t){return t()})},subscribe:function(t){return a.add(t),function(){return a.delete(t)}}}),f=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(c){switch(c.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,c=0;c<u.length-1;c++)i=i[r=u[c]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(l,t,f),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return c.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:l,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}}"function"==typeof SuppressedError&&SuppressedError;var c=e(null);function a(e){var n=e.engine,r=e.children;return t.createElement(c.Provider,{value:n},r)}function s(){var t=n(c);if(!t)throw new Error("Missing IntentProvider");return t}function l(){var t=s();return function(e){return t.emit(e)}}function f(t){var e={exports:{}};return t(e,e.exports),e.exports}var d="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},p=t.useState,v=t.useEffect,S=t.useLayoutEffect,h=t.useDebugValue;function y(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!d(t,n)}catch(t){return!0}}var _="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=p({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return S(function(){o.value=n,o.getSnapshot=e,y(o)&&u({inst:o})},[t,n,e]),v(function(){return y(o)&&u({inst:o}),t(function(){y(o)&&u({inst:o})})},[t]),h(n),n},E={useSyncExternalStore:void 0!==t.useSyncExternalStore?t.useSyncExternalStore:_},O=f(function(e,n){"production"!==process.env.NODE_ENV&&function(){function e(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=t,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,c=r.useLayoutEffect,a=r.useDebugValue,s=!1,l=!1,f="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var f=n();if(!l){var d=n();o(f,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}var p=(d=u({inst:{value:f,getSnapshot:n}}))[0].inst,v=d[1];return c(function(){p.value=f,p.getSnapshot=n,e(p)&&v({inst:p})},[t,f,n]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),a(f),f};n.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),g=f(function(t){"production"===process.env.NODE_ENV?t.exports=E:t.exports=O});function w(t){var e=s();return g.useSyncExternalStore(function(n){return e.store.subscribe(t,n)},function(){return e.store.getState(t)})}function b(t){return s().getStatus(t)}export{a as IntentProvider,i as createIntentEngine,s as useEngine,l as useIntent,w as useIntentState,b as useIntentStatus};
1
+ import t,{createContext as e,useContext as n,useRef as r}from"react";function o(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,c=0;c<u.length-1;c++)i=i[r=u[c]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}function u(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{a(r.next(t))}catch(t){u(t)}}function c(t){try{a(r.throw(t))}catch(t){u(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,c)}a((r=r.apply(t,e||[])).next())})}function i(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function c(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function a(t){var e=structuredClone(t),n=new Set;return{getState:function(){return e},setState:function(t){e=t(e),n.forEach(function(t){return t()})},subscribe:function(t){return n.add(t),function(){return n.delete(t)}}}}function s(t){return function(e,n){var r=-1;return function o(c){return u(this,void 0,void 0,function(){var u;return i(this,function(i){if(c<=r)throw new Error("next() called twice");return r=c,(u=t[c])?[2,u(e,function(){return o(c+1)})]:[2,n()]})})}(0)}}function f(t){var e,n,r=a(t.initialState),f=null!==(e=t.effects)&&void 0!==e?e:{},l=new Map,d=new Map,p=new Map,v=s(null!==(n=t.middleware)&&void 0!==n?n:[]);return{emit:function t(e){var n;return u(this,void 0,void 0,function(){var c,a=this;return i(this,function(s){switch(s.label){case 0:return c=o(r,t,f),(null===(n=d.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(c)}))?[2]:(p.set(e.type,"pending"),[4,v(e,function(){return u(a,void 0,void 0,function(){var t,n,r;return i(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=l.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,c)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return s.sent(),p.set(e.type,"success"),[2]}})})},on:function(t,e){var n;l.set(t,c(c([],null!==(n=l.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;d.set(t,c(c([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:r,getStatus:function(t){var e;return null!==(e=p.get(t))&&void 0!==e?e:"idle"}}}"function"==typeof SuppressedError&&SuppressedError;var l=e(null);function d(e){var n=e.engine,r=e.children;return t.createElement(l.Provider,{value:n},r)}function p(){var t=n(l);if(!t)throw new Error("Missing IntentProvider");return t}function v(){var t=p();return function(e){return t.emit(e)}}function S(t){var e={exports:{}};return t(e,e.exports),e.exports}var y="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},h=t.useState,_=t.useEffect,E=t.useLayoutEffect,O=t.useDebugValue;function g(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!y(t,n)}catch(t){return!0}}var w="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=h({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return E(function(){o.value=n,o.getSnapshot=e,g(o)&&u({inst:o})},[t,n,e]),_(function(){return g(o)&&u({inst:o}),t(function(){g(o)&&u({inst:o})})},[t]),O(n),n},b={useSyncExternalStore:void 0!==t.useSyncExternalStore?t.useSyncExternalStore:w},x=S(function(e,n){"production"!==process.env.NODE_ENV&&function(){function e(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=t,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,c=r.useLayoutEffect,a=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,n){s||void 0===r.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return c(function(){p.value=l,p.getSnapshot=n,e(p)&&v({inst:p})},[t,l,n]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),a(l),l};n.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),L=S(function(t){"production"===process.env.NODE_ENV?t.exports=b:t.exports=x});function m(t){var e=p(),n=r();return L.useSyncExternalStore(e.store.subscribe,function(){var r=t(e.store.getState());return Object.is(r,n.current)?n.current:(n.current=r,r)})}function T(t){var e=p();return L.useSyncExternalStore(function(n){return e.subscribeStatus(t,n)},function(){return e.getStatus(t)})}export{d as IntentProvider,s as composeMiddleware,o as createContext,f as createIntentEngine,a as createStore,p as useEngine,v as useIntent,m as useIntentState,T as useIntentStatus};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactIntentEngine={},e.React)}(this,function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t,n,r){return new(n||(n=Promise))(function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function a(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,a)}c((r=r.apply(e,t||[])).next())})}function u(e,t){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(e,t,n){if(n||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var a=t.createContext(null);function c(){var e=t.useContext(a);if(!e)throw new Error("Missing IntentProvider");return e}function s(e){var t={exports:{}};return e(t,t.exports),t.exports}var f="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},l=r.default.useState,d=r.default.useEffect,p=r.default.useLayoutEffect,v=r.default.useDebugValue;function y(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!f(e,n)}catch(e){return!0}}var h="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),r=l({inst:{value:n,getSnapshot:t}}),o=r[0].inst,u=r[1];return p(function(){o.value=n,o.getSnapshot=t,y(o)&&u({inst:o})},[e,n,t]),d(function(){return y(o)&&u({inst:o}),e(function(){y(o)&&u({inst:o})})},[e]),v(n),n},S={useSyncExternalStore:void 0!==r.default.useSyncExternalStore?r.default.useSyncExternalStore:h},_=s(function(e,t){"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!o(e,n)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=r.default,o="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},u=n.useState,i=n.useEffect,a=n.useLayoutEffect,c=n.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,r){s||void 0===n.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=r();if(!f){var d=r();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:r}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=r,e(p)&&v({inst:p})},[t,l,r]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),c(l),l};t.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),g=s(function(e){"production"===process.env.NODE_ENV?e.exports=S:e.exports=_});e.IntentProvider=function(e){var t=e.engine,n=e.children;return r.default.createElement(a.Provider,{value:t},n)},e.createIntentEngine=function(e){var t,n,r,a,c,s,f=(r=e.initialState,a=structuredClone(r),c=new Set,{getState:function(){return a},setState:function(e){a=e(a),c.forEach(function(e){return e()})},subscribe:function(e){return c.add(e),function(){return c.delete(e)}}}),l=null!==(t=e.effects)&&void 0!==t?t:{},d=new Map,p=new Map,v=new Map,y=(s=null!==(n=e.middleware)&&void 0!==n?n:[],function(e,t){var n=-1;return function r(i){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(i<=n)throw new Error("next() called twice");return n=i,(o=s[i])?[2,o(e,function(){return r(i+1)})]:[2,t()]})})}(0)});return{emit:function e(t){var n;return o(this,void 0,void 0,function(){var r,i=this;return u(this,function(a){switch(a.label){case 0:return r=function(e,t,n){return{get:function(t){return t.split(".").reduce(function(e,t){return null==e?void 0:e[t]},e.getState())},set:function(t,n){e.setState(function(e){for(var r,o=structuredClone(e),u=t.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:t,effects:n}}(f,e,l),(null===(n=p.get(t.type))||void 0===n?void 0:n.some(function(e){return!e(r)}))?[2]:(v.set(t.type,"pending"),[4,y(t,function(){return o(i,void 0,void 0,function(){var e,n,o;return u(this,function(u){switch(u.label){case 0:e=0,n=null!==(o=d.get(t.type))&&void 0!==o?o:[],u.label=1;case 1:return e<n.length?[4,(0,n[e])(t,r)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(t.type,"success"),[2]}})})},on:function(e,t){var n;d.set(e,i(i([],null!==(n=d.get(e))&&void 0!==n?n:[],!0),[t],!1))},guard:function(e,t){var n;p.set(e,i(i([],null!==(n=p.get(e))&&void 0!==n?n:[],!0),[t],!1))},store:f,getStatus:function(e){var t;return null!==(t=v.get(e))&&void 0!==t?t:"idle"}}},e.useEngine=c,e.useIntent=function(){var e=c();return function(t){return e.emit(t)}},e.useIntentState=function(e){var t=c();return g.useSyncExternalStore(function(n){return t.store.subscribe(e,n)},function(){return t.store.getState(e)})},e.useIntentStatus=function(e){return c().getStatus(e)},Object.defineProperty(e,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactIntentEngine={},e.React)}(this,function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t,n){return{get:function(t){return t.split(".").reduce(function(e,t){return null==e?void 0:e[t]},e.getState())},set:function(t,n){e.setState(function(e){for(var r,o=structuredClone(e),u=t.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:t,effects:n}}function u(e,t,n,r){return new(n||(n=Promise))(function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function a(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,a)}c((r=r.apply(e,t||[])).next())})}function i(e,t){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function a(e,t,n){if(n||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}function c(e){var t=structuredClone(e),n=new Set;return{getState:function(){return t},setState:function(e){t=e(t),n.forEach(function(e){return e()})},subscribe:function(e){return n.add(e),function(){return n.delete(e)}}}}function s(e){return function(t,n){var r=-1;return function o(a){return u(this,void 0,void 0,function(){var u;return i(this,function(i){if(a<=r)throw new Error("next() called twice");return r=a,(u=e[a])?[2,u(t,function(){return o(a+1)})]:[2,n()]})})}(0)}}"function"==typeof SuppressedError&&SuppressedError;var f=t.createContext(null);function l(){var e=t.useContext(f);if(!e)throw new Error("Missing IntentProvider");return e}function d(e){var t={exports:{}};return e(t,t.exports),t.exports}var p="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},v=r.default.useState,y=r.default.useEffect,S=r.default.useLayoutEffect,h=r.default.useDebugValue;function _(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!p(e,n)}catch(e){return!0}}var E="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),r=v({inst:{value:n,getSnapshot:t}}),o=r[0].inst,u=r[1];return S(function(){o.value=n,o.getSnapshot=t,_(o)&&u({inst:o})},[e,n,t]),y(function(){return _(o)&&u({inst:o}),e(function(){_(o)&&u({inst:o})})},[e]),h(n),n},g={useSyncExternalStore:void 0!==r.default.useSyncExternalStore?r.default.useSyncExternalStore:E},O=d(function(e,t){"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!o(e,n)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=r.default,o="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},u=n.useState,i=n.useEffect,a=n.useLayoutEffect,c=n.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,r){s||void 0===n.startTransition||(s=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=r();if(!f){var d=r();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:r}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=r,e(p)&&v({inst:p})},[t,l,r]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),c(l),l};t.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),b=d(function(e){"production"===process.env.NODE_ENV?e.exports=g:e.exports=O});e.IntentProvider=function(e){var t=e.engine,n=e.children;return r.default.createElement(f.Provider,{value:t},n)},e.composeMiddleware=s,e.createContext=o,e.createIntentEngine=function(e){var t,n,r=c(e.initialState),f=null!==(t=e.effects)&&void 0!==t?t:{},l=new Map,d=new Map,p=new Map,v=s(null!==(n=e.middleware)&&void 0!==n?n:[]);return{emit:function e(t){var n;return u(this,void 0,void 0,function(){var a,c=this;return i(this,function(s){switch(s.label){case 0:return a=o(r,e,f),(null===(n=d.get(t.type))||void 0===n?void 0:n.some(function(e){return!e(a)}))?[2]:(p.set(t.type,"pending"),[4,v(t,function(){return u(c,void 0,void 0,function(){var e,n,r;return i(this,function(o){switch(o.label){case 0:e=0,n=null!==(r=l.get(t.type))&&void 0!==r?r:[],o.label=1;case 1:return e<n.length?[4,(0,n[e])(t,a)]:[3,4];case 2:o.sent(),o.label=3;case 3:return e++,[3,1];case 4:return[2]}})})})]);case 1:return s.sent(),p.set(t.type,"success"),[2]}})})},on:function(e,t){var n;l.set(e,a(a([],null!==(n=l.get(e))&&void 0!==n?n:[],!0),[t],!1))},guard:function(e,t){var n;d.set(e,a(a([],null!==(n=d.get(e))&&void 0!==n?n:[],!0),[t],!1))},store:r,getStatus:function(e){var t;return null!==(t=p.get(e))&&void 0!==t?t:"idle"}}},e.createStore=c,e.useEngine=l,e.useIntent=function(){var e=l();return function(t){return e.emit(t)}},e.useIntentState=function(e){var n=l(),r=t.useRef();return b.useSyncExternalStore(n.store.subscribe,function(){var t=e(n.store.getState());return Object.is(t,r.current)?r.current:(r.current=t,t)})},e.useIntentStatus=function(e){var t=l();return b.useSyncExternalStore(function(n){return t.subscribeStatus(e,n)},function(){return t.getStatus(e)})},Object.defineProperty(e,"__esModule",{value:!0})});
@@ -1 +1 @@
1
- export declare function useIntentState<T = any>(intentType: string): T | undefined;
1
+ export declare function useIntentState<T>(selector: (state: any) => T): T;
@@ -1 +1 @@
1
- export declare function useIntentStatus(type: string): any;
1
+ export declare function useIntentStatus(intentType: string): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intent-engine-z",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Intent-first orchestration engine for React applications",
5
5
  "license": "MIT",
6
6
  "author": "Delpi.Kye",