@bemedev/app-reactjs 1.11.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  ReactJS state hook binding for `@bemedev/app` state machines.
4
4
 
5
- `@bemedev/app-reactjs` provides a lightweight hook to track and select
6
- state from a `@bemedev/app` interpreter service inside ReactJS component
7
- trees.
5
+ `@bemedev/app-reactjs` provides a lightweight hook to track and select state from a
6
+ `@bemedev/app` interpreter service inside ReactJS component trees.
8
7
 
9
8
  <br/>
10
9
 
@@ -23,7 +22,7 @@ npm install @bemedev/app-reactjs
23
22
  pnpm add @bemedev/app-reactjs
24
23
  ```
25
24
 
26
- > **Requirements:** Node.js ≥ 24 · `@bemedev/app` ≥ 1.2.0 · React ≥ 18.0.0
25
+ > **Requirements:** Node.js ≥ 24 · `@bemedev/app` ≥ 2.0.0 · React ≥ 18.0.0
27
26
 
28
27
  <br/>
29
28
 
@@ -60,8 +59,8 @@ function MyComponent() {
60
59
 
61
60
  ## Available Hooks
62
61
 
63
- The package also exports `useState`, `useCan`, and `useIsInside` for common
64
- state selection patterns:
62
+ The package also exports `useState`, `useCan`, and `useIsInside` for common state
63
+ selection patterns:
65
64
 
66
65
  ```typescript
67
66
  const count = useState(service, state => state.context.count);
@@ -69,9 +68,9 @@ const canIncrement = useCan(service, 'INCREMENT');
69
68
  const isInside = useIsInside(service, 'some.state');
70
69
  ```
71
70
 
72
- These helpers are designed to work with the same interpreter service and
73
- provide a lightweight way to subscribe to state slices, transition
74
- permissions, and nested state location checks.
71
+ These helpers are designed to work with the same interpreter service and provide a
72
+ lightweight way to subscribe to state slices, transition permissions, and nested
73
+ state location checks.
75
74
 
76
75
  <br/>
77
76
 
@@ -79,8 +78,8 @@ permissions, and nested state location checks.
79
78
 
80
79
  ### `useService(service, options?)`
81
80
 
82
- Creates a React state hook that updates whenever the interpreter
83
- transitions, using deep comparison to prevent unnecessary renders.
81
+ Creates a React state hook that updates whenever the interpreter transitions, using
82
+ deep comparison to prevent unnecessary renders.
84
83
 
85
84
  | Parameter | Type | Description |
86
85
  | --------- | ------------------- | ----------------------------------------------------------------------------------- |
package/lib/types.d.ts CHANGED
@@ -2,10 +2,10 @@ import type { EventObject, State, PrimitiveObject } from '@bemedev/app';
2
2
  /**
3
3
  * Options for configuring the `useService` hook.
4
4
  *
5
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
6
- * @template {string} Ta - Tag type extending `string`.
7
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
8
- * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
5
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
6
+ * @template `Ta` - Tag type extending `string`.
7
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
8
+ * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
9
9
  *
10
10
  * @property selector - Optional selector function to project the state into a sub-state.
11
11
  * @property equals - Optional equality comparator function to compare previous and next selected state.
package/lib/useCan.cjs CHANGED
@@ -6,9 +6,9 @@ let _bemedev_app_bemedev = require("@bemedev/app/bemedev");
6
6
  /**
7
7
  * React hook that creates reactive helpers for querying event capabilities from a service.
8
8
  *
9
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
10
- * @template {string} Ta - Tag type extending `string`.
11
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
9
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
10
+ * @template `Ta` - Tag type extending `string`.
11
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
12
12
  *
13
13
  * @param service - Service object containing `subscribe`, `state`, and `canEvents`.
14
14
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -16,6 +16,8 @@ let _bemedev_app_bemedev = require("@bemedev/app/bemedev");
16
16
  * @param service.canEvents - Function checking if event types can be accepted.
17
17
  *
18
18
  * @returns Object helper with `or` and `and` methods to check event availability.
19
+ *
20
+ * @see {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
19
21
  */
20
22
  function useCan(service) {
21
23
  const dispatch = (matcher) => (...events) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useCan.cjs","names":["useSync","deepEqual","identity","expandFn"],"sources":["../src/useCan.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for querying event capabilities from a service.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Function checking if event types can be accepted.\n *\n * @returns Object helper with `or` and `and` methods to check event availability.\n */\nexport function useCan<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n const dispatch =\n (matcher: 'some' | 'every') =>\n (...events: Eo['type'][]) => {\n const selector = () =>\n events[matcher](event => service.canEvents(event));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => deepEqual(first.value, next.value),\n firstTime: true,\n });\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,OAId,SAIC;CACD,MAAM,YACH,aACA,GAAG,WAAyB;EAC3B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UAAS,QAAQ,UAAU,KAAK,CAAC;EACnD,QAAA,GAAOA,oBAAAA,QAAAA,EACL,aAAY;GACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;IAClD,SAAS,OAAO,UAAA,GAASC,mBAAAA,UAAAA,CAAU,MAAM,OAAO,KAAK,KAAK;IAC1D,WAAW;GACb,CAAC;GACD,OAAO;EACT,GACA,UACA,UACAC,mBAAAA,QACF;CACF;CAEF,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,QAAA,GADYC,qBAAAA,SAAAA,CAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
1
+ {"version":3,"file":"useCan.cjs","names":["useSync","deepEqual","identity","expandFn"],"sources":["../src/useCan.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for querying event capabilities from a service.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Function checking if event types can be accepted.\n *\n * @returns Object helper with `or` and `and` methods to check event availability.\n *\n * @see {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useCan<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n const dispatch =\n (matcher: 'some' | 'every') =>\n (...events: Eo['type'][]) => {\n const selector = () => events[matcher](event => service.canEvents(event));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => deepEqual(first.value, next.value),\n firstTime: true,\n });\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,OAId,SAIC;CACD,MAAM,YACH,aACA,GAAG,WAAyB;EAC3B,MAAM,iBAAiB,OAAO,QAAQ,EAAC,UAAS,QAAQ,UAAU,KAAK,CAAC;EACxE,QAAA,GAAOA,oBAAAA,QAAAA,EACL,aAAY;GACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;IAClD,SAAS,OAAO,UAAA,GAASC,mBAAAA,UAAAA,CAAU,MAAM,OAAO,KAAK,KAAK;IAC1D,WAAW;GACb,CAAC;GACD,OAAO;EACT,GACA,UACA,UACAC,mBAAAA,QACF;CACF;CAEF,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,QAAA,GADYC,qBAAAA,SAAAA,CAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
package/lib/useCan.d.ts CHANGED
@@ -2,9 +2,9 @@ import { type AddSubscriber_F, type EventObject, type PrimitiveObject, type Stat
2
2
  /**
3
3
  * React hook that creates reactive helpers for querying event capabilities from a service.
4
4
  *
5
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
6
- * @template {string} Ta - Tag type extending `string`.
7
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
5
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
6
+ * @template `Ta` - Tag type extending `string`.
7
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
8
8
  *
9
9
  * @param service - Service object containing `subscribe`, `state`, and `canEvents`.
10
10
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -12,6 +12,8 @@ import { type AddSubscriber_F, type EventObject, type PrimitiveObject, type Stat
12
12
  * @param service.canEvents - Function checking if event types can be accepted.
13
13
  *
14
14
  * @returns Object helper with `or` and `and` methods to check event availability.
15
+ *
16
+ * @see {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
15
17
  */
16
18
  export declare function useCan<Tc extends PrimitiveObject, Ta extends string, Eo extends EventObject>(service: {
17
19
  subscribe: AddSubscriber_F<Tc, Ta, Eo>;
@@ -1 +1 @@
1
- {"version":3,"file":"useCan.d.ts","sourceRoot":"","sources":["../src/useCan.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAKtB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CACpB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IACT,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC;CACjD,sDAGe,EAAE,CAAC,MAAM,CAAC,EAAE;6BAAZ,EAAE,CAAC,MAAM,CAAC,EAAE;8BAAZ,EAAE,CAAC,MAAM,CAAC,EAAE;GAqB3B"}
1
+ {"version":3,"file":"useCan.d.ts","sourceRoot":"","sources":["../src/useCan.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAKtB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,MAAM,CACpB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IACT,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC;CACjD,sDAGe,EAAE,CAAC,MAAM,CAAC,EAAE;6BAAZ,EAAE,CAAC,MAAM,CAAC,EAAE;8BAAZ,EAAE,CAAC,MAAM,CAAC,EAAE;GAoB3B"}
package/lib/useCan.js CHANGED
@@ -5,9 +5,9 @@ import { expandFn } from "@bemedev/app/bemedev";
5
5
  /**
6
6
  * React hook that creates reactive helpers for querying event capabilities from a service.
7
7
  *
8
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
9
- * @template {string} Ta - Tag type extending `string`.
10
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
8
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
9
+ * @template `Ta` - Tag type extending `string`.
10
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
11
11
  *
12
12
  * @param service - Service object containing `subscribe`, `state`, and `canEvents`.
13
13
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -15,6 +15,8 @@ import { expandFn } from "@bemedev/app/bemedev";
15
15
  * @param service.canEvents - Function checking if event types can be accepted.
16
16
  *
17
17
  * @returns Object helper with `or` and `and` methods to check event availability.
18
+ *
19
+ * @see {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
18
20
  */
19
21
  function useCan(service) {
20
22
  const dispatch = (matcher) => (...events) => {
package/lib/useCan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"useCan.js","names":[],"sources":["../src/useCan.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for querying event capabilities from a service.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Function checking if event types can be accepted.\n *\n * @returns Object helper with `or` and `and` methods to check event availability.\n */\nexport function useCan<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n const dispatch =\n (matcher: 'some' | 'every') =>\n (...events: Eo['type'][]) => {\n const selector = () =>\n events[matcher](event => service.canEvents(event));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => deepEqual(first.value, next.value),\n firstTime: true,\n });\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,OAId,SAIC;CACD,MAAM,YACH,aACA,GAAG,WAAyB;EAC3B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UAAS,QAAQ,UAAU,KAAK,CAAC;EACnD,OAAO,SACL,aAAY;GACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;IAClD,SAAS,OAAO,SAAS,UAAU,MAAM,OAAO,KAAK,KAAK;IAC1D,WAAW;GACb,CAAC;GACD,OAAO;EACT,GACA,UACA,UACA,QACF;CACF;CAEF,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,OADY,SAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
1
+ {"version":3,"file":"useCan.js","names":[],"sources":["../src/useCan.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for querying event capabilities from a service.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Function checking if event types can be accepted.\n *\n * @returns Object helper with `or` and `and` methods to check event availability.\n *\n * @see {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useCan<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n const dispatch =\n (matcher: 'some' | 'every') =>\n (...events: Eo['type'][]) => {\n const selector = () => events[matcher](event => service.canEvents(event));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => deepEqual(first.value, next.value),\n firstTime: true,\n });\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,OAId,SAIC;CACD,MAAM,YACH,aACA,GAAG,WAAyB;EAC3B,MAAM,iBAAiB,OAAO,QAAQ,EAAC,UAAS,QAAQ,UAAU,KAAK,CAAC;EACxE,OAAO,SACL,aAAY;GACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;IAClD,SAAS,OAAO,SAAS,UAAU,MAAM,OAAO,KAAK,KAAK;IAC1D,WAAW;GACb,CAAC;GACD,OAAO;EACT,GACA,UACA,UACA,QACF;CACF;CAEF,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,OADY,SAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
@@ -6,15 +6,17 @@ let _bemedev_app_bemedev = require("@bemedev/app/bemedev");
6
6
  /**
7
7
  * React hook that creates reactive helpers for checking active state hierarchy.
8
8
  *
9
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
10
- * @template {string} Ta - Tag type extending `string`.
11
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
9
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
10
+ * @template `Ta` - Tag type extending `string`.
11
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
12
12
  *
13
13
  * @param service - Service object containing `subscribe` and `state`.
14
14
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
15
15
  * @param service.state - Current state of type {@linkcode State}.
16
16
  *
17
17
  * @returns Object helper with `or` and `and` methods to check state hierarchy.
18
+ *
19
+ * @see {@linkcode decomposeSV}, {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
18
20
  */
19
21
  function useIsInside(service) {
20
22
  const selector1 = (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useIsInside.cjs","names":["decomposeSV","useSync","deepEqual","identity","expandFn"],"sources":["../src/useIsInside.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n StateValue,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { decomposeSV, deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for checking active state hierarchy.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe` and `state`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n *\n * @returns Object helper with `or` and `and` methods to check state hierarchy.\n */\nexport function useIsInside<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n}) {\n const selector1 = (value: StateValue) => {\n return decomposeSV(value);\n };\n\n const dispatch = (matcher: 'some' | 'every') => {\n return (...states: string[]) => {\n const selector = () =>\n states[matcher](state =>\n selector1(service.state.value).includes(state),\n );\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => {\n return deepEqual(first.value, next.value);\n },\n firstTime: true,\n });\n\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwBA,SAAgB,YAId,SAGC;CACD,MAAM,aAAa,UAAsB;EACvC,QAAA,GAAOA,mBAAAA,YAAAA,CAAY,KAAK;CAC1B;CAEA,MAAM,YAAY,YAA8B;EAC9C,QAAQ,GAAG,WAAqB;GAC9B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UACd,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,CAC/C;GACF,QAAA,GAAOC,oBAAAA,QAAAA,EACL,aAAY;IACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;KAClD,SAAS,OAAO,SAAS;MACvB,QAAA,GAAOC,mBAAAA,UAAAA,CAAU,MAAM,OAAO,KAAK,KAAK;KAC1C;KACA,WAAW;IACb,CAAC;IAED,OAAO;GACT,GACA,UACA,UACAC,mBAAAA,QACF;EACF;CACF;CAEA,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,QAAA,GADYC,qBAAAA,SAAAA,CAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
1
+ {"version":3,"file":"useIsInside.cjs","names":["decomposeSV","useSync","deepEqual","identity","expandFn"],"sources":["../src/useIsInside.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n StateValue,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { decomposeSV, deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for checking active state hierarchy.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe` and `state`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n *\n * @returns Object helper with `or` and `and` methods to check state hierarchy.\n *\n * @see {@linkcode decomposeSV}, {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useIsInside<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: { subscribe: AddSubscriber_F<Tc, Ta, Eo>; state: State<Eo, Tc, Ta> }) {\n const selector1 = (value: StateValue) => {\n return decomposeSV(value);\n };\n\n const dispatch = (matcher: 'some' | 'every') => {\n return (...states: string[]) => {\n const selector = () =>\n states[matcher](state => selector1(service.state.value).includes(state));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => {\n return deepEqual(first.value, next.value);\n },\n firstTime: true,\n });\n\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,YAId,SAA+E;CAC/E,MAAM,aAAa,UAAsB;EACvC,QAAA,GAAOA,mBAAAA,YAAAA,CAAY,KAAK;CAC1B;CAEA,MAAM,YAAY,YAA8B;EAC9C,QAAQ,GAAG,WAAqB;GAC9B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UAAS,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC;GACzE,QAAA,GAAOC,oBAAAA,QAAAA,EACL,aAAY;IACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;KAClD,SAAS,OAAO,SAAS;MACvB,QAAA,GAAOC,mBAAAA,UAAAA,CAAU,MAAM,OAAO,KAAK,KAAK;KAC1C;KACA,WAAW;IACb,CAAC;IAED,OAAO;GACT,GACA,UACA,UACAC,mBAAAA,QACF;EACF;CACF;CAEA,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,QAAA,GADYC,qBAAAA,SAAAA,CAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
@@ -2,15 +2,17 @@ import type { AddSubscriber_F, EventObject, PrimitiveObject, State } from '@beme
2
2
  /**
3
3
  * React hook that creates reactive helpers for checking active state hierarchy.
4
4
  *
5
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
6
- * @template {string} Ta - Tag type extending `string`.
7
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
5
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
6
+ * @template `Ta` - Tag type extending `string`.
7
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
8
8
  *
9
9
  * @param service - Service object containing `subscribe` and `state`.
10
10
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
11
11
  * @param service.state - Current state of type {@linkcode State}.
12
12
  *
13
13
  * @returns Object helper with `or` and `and` methods to check state hierarchy.
14
+ *
15
+ * @see {@linkcode decomposeSV}, {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
14
16
  */
15
17
  export declare function useIsInside<Tc extends PrimitiveObject, Ta extends string, Eo extends EventObject>(service: {
16
18
  subscribe: AddSubscriber_F<Tc, Ta, Eo>;
@@ -1 +1 @@
1
- {"version":3,"file":"useIsInside.d.ts","sourceRoot":"","sources":["../src/useIsInside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,KAAK,EAEN,MAAM,cAAc,CAAC;AAKtB;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CACzB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IACT,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;CAC1B,sDAMsB,MAAM,EAAE;6BAAR,MAAM,EAAE;8BAAR,MAAM,EAAE;GA2B9B"}
1
+ {"version":3,"file":"useIsInside.d.ts","sourceRoot":"","sources":["../src/useIsInside.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,KAAK,EAEN,MAAM,cAAc,CAAC;AAKtB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IAAE,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;CAAE,sDAMxD,MAAM,EAAE;6BAAR,MAAM,EAAE;8BAAR,MAAM,EAAE;GAyB9B"}
@@ -5,15 +5,17 @@ import { expandFn } from "@bemedev/app/bemedev";
5
5
  /**
6
6
  * React hook that creates reactive helpers for checking active state hierarchy.
7
7
  *
8
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
9
- * @template {string} Ta - Tag type extending `string`.
10
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
8
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
9
+ * @template `Ta` - Tag type extending `string`.
10
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
11
11
  *
12
12
  * @param service - Service object containing `subscribe` and `state`.
13
13
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
14
14
  * @param service.state - Current state of type {@linkcode State}.
15
15
  *
16
16
  * @returns Object helper with `or` and `and` methods to check state hierarchy.
17
+ *
18
+ * @see {@linkcode decomposeSV}, {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}
17
19
  */
18
20
  function useIsInside(service) {
19
21
  const selector1 = (value) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useIsInside.js","names":[],"sources":["../src/useIsInside.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n StateValue,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { decomposeSV, deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for checking active state hierarchy.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe` and `state`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n *\n * @returns Object helper with `or` and `and` methods to check state hierarchy.\n */\nexport function useIsInside<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n}) {\n const selector1 = (value: StateValue) => {\n return decomposeSV(value);\n };\n\n const dispatch = (matcher: 'some' | 'every') => {\n return (...states: string[]) => {\n const selector = () =>\n states[matcher](state =>\n selector1(service.state.value).includes(state),\n );\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => {\n return deepEqual(first.value, next.value);\n },\n firstTime: true,\n });\n\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAwBA,SAAgB,YAId,SAGC;CACD,MAAM,aAAa,UAAsB;EACvC,OAAO,YAAY,KAAK;CAC1B;CAEA,MAAM,YAAY,YAA8B;EAC9C,QAAQ,GAAG,WAAqB;GAC9B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UACd,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,CAC/C;GACF,OAAO,SACL,aAAY;IACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;KAClD,SAAS,OAAO,SAAS;MACvB,OAAO,UAAU,MAAM,OAAO,KAAK,KAAK;KAC1C;KACA,WAAW;IACb,CAAC;IAED,OAAO;GACT,GACA,UACA,UACA,QACF;EACF;CACF;CAEA,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,OADY,SAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
1
+ {"version":3,"file":"useIsInside.js","names":[],"sources":["../src/useIsInside.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n StateValue,\n} from '@bemedev/app';\nimport { expandFn } from '@bemedev/app/bemedev';\nimport { decomposeSV, deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\n\n/**\n * React hook that creates reactive helpers for checking active state hierarchy.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service object containing `subscribe` and `state`.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n *\n * @returns Object helper with `or` and `and` methods to check state hierarchy.\n *\n * @see {@linkcode decomposeSV}, {@linkcode useSync}, {@linkcode expandFn}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useIsInside<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: { subscribe: AddSubscriber_F<Tc, Ta, Eo>; state: State<Eo, Tc, Ta> }) {\n const selector1 = (value: StateValue) => {\n return decomposeSV(value);\n };\n\n const dispatch = (matcher: 'some' | 'every') => {\n return (...states: string[]) => {\n const selector = () =>\n states[matcher](state => selector1(service.state.value).includes(state));\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (first, next) => {\n return deepEqual(first.value, next.value);\n },\n firstTime: true,\n });\n\n return unsubscribe;\n },\n selector,\n selector,\n identity,\n );\n };\n };\n\n const or = dispatch('some');\n const and = dispatch('every');\n const out = expandFn(and, { or, and });\n return out;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0BA,SAAgB,YAId,SAA+E;CAC/E,MAAM,aAAa,UAAsB;EACvC,OAAO,YAAY,KAAK;CAC1B;CAEA,MAAM,YAAY,YAA8B;EAC9C,QAAQ,GAAG,WAAqB;GAC9B,MAAM,iBACJ,OAAO,QAAQ,EAAC,UAAS,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,SAAS,KAAK,CAAC;GACzE,OAAO,SACL,aAAY;IACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;KAClD,SAAS,OAAO,SAAS;MACvB,OAAO,UAAU,MAAM,OAAO,KAAK,KAAK;KAC1C;KACA,WAAW;IACb,CAAC;IAED,OAAO;GACT,GACA,UACA,UACA,QACF;EACF;CACF;CAEA,MAAM,KAAK,SAAS,MAAM;CAC1B,MAAM,MAAM,SAAS,OAAO;CAE5B,OADY,SAAS,KAAK;EAAE;EAAI;CAAI,CAC3B;AACX"}
@@ -6,9 +6,9 @@ const require_useIsInside = require("./useIsInside.cjs");
6
6
  /**
7
7
  * React hook that binds state management, event checking, and hierarchy querying for a service.
8
8
  *
9
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
10
- * @template {string} Ta - Tag type extending `string`.
11
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
9
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
10
+ * @template `Ta` - Tag type extending `string`.
11
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
12
12
  *
13
13
  * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.
14
14
  * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.
@@ -16,6 +16,8 @@ const require_useIsInside = require("./useIsInside.cjs");
16
16
  * @param service.canEvents - Method to check event execution capability.
17
17
  *
18
18
  * @returns Service hooks object containing `state`, `can`, and `isInside`.
19
+ *
20
+ * @see {@linkcode useState}, {@linkcode useCan}, {@linkcode useIsInside}, -- type {@linkcode UseServiceOptions}
19
21
  */
20
22
  function useService(service) {
21
23
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"useService.cjs","names":["useState","useCan","useIsInside"],"sources":["../src/useService.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n} from '@bemedev/app';\nimport type { UseServiceOptions } from './types';\nimport { useCan } from './useCan';\nimport { useIsInside } from './useIsInside';\nimport { useState } from './useState';\n\n/**\n * React hook that binds state management, event checking, and hierarchy querying for a service.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Method to check event execution capability.\n *\n * @returns Service hooks object containing `state`, `can`, and `isInside`.\n */\nexport function useService<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n return {\n state: <T = State<Eo, Tc, Ta>>(\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n ) => useState<Tc, Ta, Eo, T>(service, options),\n\n can: useCan(service),\n isInside: useIsInside(service),\n };\n}\n\n/**\n * Alias for function {@linkcode useService}.\n */\nexport const createHooks = useService;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,WAId,SAIC;CACD,OAAO;EACL,QACE,YACGA,iBAAAA,SAAwB,SAAS,OAAO;EAE7C,KAAKC,eAAAA,OAAO,OAAO;EACnB,UAAUC,oBAAAA,YAAY,OAAO;CAC/B;AACF;;;;AAKA,MAAa,cAAc"}
1
+ {"version":3,"file":"useService.cjs","names":["useState","useCan","useIsInside"],"sources":["../src/useService.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n} from '@bemedev/app';\nimport type { UseServiceOptions } from './types';\nimport { useCan } from './useCan';\nimport { useIsInside } from './useIsInside';\nimport { useState } from './useState';\n\n/**\n * React hook that binds state management, event checking, and hierarchy querying for a service.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Method to check event execution capability.\n *\n * @returns Service hooks object containing `state`, `can`, and `isInside`.\n *\n * @see {@linkcode useState}, {@linkcode useCan}, {@linkcode useIsInside}, -- type {@linkcode UseServiceOptions}\n */\nexport function useService<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n return {\n state: <T = State<Eo, Tc, Ta>>(options?: UseServiceOptions<Tc, Ta, Eo, T>) =>\n useState<Tc, Ta, Eo, T>(service, options),\n\n can: useCan(service),\n isInside: useIsInside(service),\n };\n}\n\n/**\n * Alias for function {@linkcode useService}.\n */\nexport const createHooks = useService;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,WAId,SAIC;CACD,OAAO;EACL,QAA+B,YAC7BA,iBAAAA,SAAwB,SAAS,OAAO;EAE1C,KAAKC,eAAAA,OAAO,OAAO;EACnB,UAAUC,oBAAAA,YAAY,OAAO;CAC/B;AACF;;;;AAKA,MAAa,cAAc"}
@@ -3,9 +3,9 @@ import type { UseServiceOptions } from './types';
3
3
  /**
4
4
  * React hook that binds state management, event checking, and hierarchy querying for a service.
5
5
  *
6
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
7
- * @template {string} Ta - Tag type extending `string`.
8
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
6
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
7
+ * @template `Ta` - Tag type extending `string`.
8
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
9
9
  *
10
10
  * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.
11
11
  * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.
@@ -13,6 +13,8 @@ import type { UseServiceOptions } from './types';
13
13
  * @param service.canEvents - Method to check event execution capability.
14
14
  *
15
15
  * @returns Service hooks object containing `state`, `can`, and `isInside`.
16
+ *
17
+ * @see {@linkcode useState}, {@linkcode useCan}, {@linkcode useIsInside}, -- type {@linkcode UseServiceOptions}
16
18
  */
17
19
  export declare function useService<Tc extends PrimitiveObject, Ta extends string, Eo extends EventObject>(service: {
18
20
  subscribe: AddSubscriber_F<Tc, Ta, Eo>;
@@ -1 +1 @@
1
- {"version":3,"file":"useService.d.ts","sourceRoot":"","sources":["../src/useService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,KAAK,EACN,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAKjD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IACT,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC;CACjD;YAEW,CAAC,gCACG,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;;;;;;;;;EAM/C;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,mBAAa,CAAC"}
1
+ {"version":3,"file":"useService.d.ts","sourceRoot":"","sources":["../src/useService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,eAAe,EACf,KAAK,EACN,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAKjD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CACxB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,OAAO,EAAE;IACT,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACzB,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,OAAO,CAAC;CACjD;YAEW,CAAC,gCAAgC,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;;;;;;;;;EAM5E;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,mBAAa,CAAC"}
package/lib/useService.js CHANGED
@@ -5,9 +5,9 @@ import { useIsInside } from "./useIsInside.js";
5
5
  /**
6
6
  * React hook that binds state management, event checking, and hierarchy querying for a service.
7
7
  *
8
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
9
- * @template {string} Ta - Tag type extending `string`.
10
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
8
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
9
+ * @template `Ta` - Tag type extending `string`.
10
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
11
11
  *
12
12
  * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.
13
13
  * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.
@@ -15,6 +15,8 @@ import { useIsInside } from "./useIsInside.js";
15
15
  * @param service.canEvents - Method to check event execution capability.
16
16
  *
17
17
  * @returns Service hooks object containing `state`, `can`, and `isInside`.
18
+ *
19
+ * @see {@linkcode useState}, {@linkcode useCan}, {@linkcode useIsInside}, -- type {@linkcode UseServiceOptions}
18
20
  */
19
21
  function useService(service) {
20
22
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"useService.js","names":[],"sources":["../src/useService.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n} from '@bemedev/app';\nimport type { UseServiceOptions } from './types';\nimport { useCan } from './useCan';\nimport { useIsInside } from './useIsInside';\nimport { useState } from './useState';\n\n/**\n * React hook that binds state management, event checking, and hierarchy querying for a service.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Method to check event execution capability.\n *\n * @returns Service hooks object containing `state`, `can`, and `isInside`.\n */\nexport function useService<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n return {\n state: <T = State<Eo, Tc, Ta>>(\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n ) => useState<Tc, Ta, Eo, T>(service, options),\n\n can: useCan(service),\n isInside: useIsInside(service),\n };\n}\n\n/**\n * Alias for function {@linkcode useService}.\n */\nexport const createHooks = useService;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,SAAgB,WAId,SAIC;CACD,OAAO;EACL,QACE,YACG,SAAwB,SAAS,OAAO;EAE7C,KAAK,OAAO,OAAO;EACnB,UAAU,YAAY,OAAO;CAC/B;AACF;;;;AAKA,MAAa,cAAc"}
1
+ {"version":3,"file":"useService.js","names":[],"sources":["../src/useService.ts"],"sourcesContent":["import type {\n AddSubscriber_F,\n EventObject,\n PrimitiveObject,\n State,\n} from '@bemedev/app';\nimport type { UseServiceOptions } from './types';\nimport { useCan } from './useCan';\nimport { useIsInside } from './useIsInside';\nimport { useState } from './useState';\n\n/**\n * React hook that binds state management, event checking, and hierarchy querying for a service.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n *\n * @param service - Service instance containing `subscribe`, `state`, and `canEvents`.\n * @param service.subscribe - Subscription function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param service.canEvents - Method to check event execution capability.\n *\n * @returns Service hooks object containing `state`, `can`, and `isInside`.\n *\n * @see {@linkcode useState}, {@linkcode useCan}, {@linkcode useIsInside}, -- type {@linkcode UseServiceOptions}\n */\nexport function useService<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n>(service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n canEvents: (...events: Eo['type'][]) => boolean;\n}) {\n return {\n state: <T = State<Eo, Tc, Ta>>(options?: UseServiceOptions<Tc, Ta, Eo, T>) =>\n useState<Tc, Ta, Eo, T>(service, options),\n\n can: useCan(service),\n isInside: useIsInside(service),\n };\n}\n\n/**\n * Alias for function {@linkcode useService}.\n */\nexport const createHooks = useService;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,WAId,SAIC;CACD,OAAO;EACL,QAA+B,YAC7B,SAAwB,SAAS,OAAO;EAE1C,KAAK,OAAO,OAAO;EACnB,UAAU,YAAY,OAAO;CAC/B;AACF;;;;AAKA,MAAa,cAAc"}
package/lib/useState.cjs CHANGED
@@ -5,10 +5,10 @@ let _bemedev_react_sync = require("@bemedev/react-sync");
5
5
  /**
6
6
  * A hook that creates a React state from a service with a subscribe function.
7
7
  *
8
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
9
- * @template {string} Ta - Tag type extending `string`.
10
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
11
- * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
8
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
9
+ * @template `Ta` - Tag type extending `string`.
10
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
11
+ * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
12
12
  *
13
13
  * @param service - The service containing state and subscribe method.
14
14
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -16,6 +16,8 @@ let _bemedev_react_sync = require("@bemedev/react-sync");
16
16
  * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.
17
17
  *
18
18
  * @returns The selected state of type `T`.
19
+ *
20
+ * @see {@linkcode useSync}, {@linkcode deepEqual}, {@linkcode identity}
19
21
  */
20
22
  function useState(service, options) {
21
23
  const { selector = _bemedev_app_utils.identity, equals = _bemedev_app_utils.deepEqual } = options ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"useState.cjs","names":["identity","deepEqual","useSync"],"sources":["../src/useState.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\nimport type { UseServiceOptions } from './types';\n\n/**\n * A hook that creates a React state from a service with a subscribe function.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.\n *\n * @param service - The service containing state and subscribe method.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.\n *\n * @returns The selected state of type `T`.\n */\nexport function useState<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n T = State<Eo, Tc, Ta>,\n>(\n service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n },\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n): T {\n const { selector = identity, equals = deepEqual<T> } = options ?? {};\n const _selector = () => selector(service.state);\n\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (prev, next) => {\n const _prev = selector(prev);\n const _next = selector(next);\n return equals(_prev, _next);\n },\n firstTime: true,\n });\n return unsubscribe;\n },\n _selector,\n _selector,\n identity,\n equals,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAyBA,SAAgB,SAMd,SAIA,SACG;CACH,MAAM,EAAE,WAAWA,mBAAAA,UAAU,SAASC,mBAAAA,cAAiB,WAAW,CAAC;CACnE,MAAM,kBAAkB,SAAS,QAAQ,KAAK;CAE9C,QAAA,GAAOC,oBAAAA,QAAAA,EACL,aAAY;EACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;GAClD,SAAS,MAAM,SAAS;IACtB,MAAM,QAAQ,SAAS,IAAI;IAC3B,MAAM,QAAQ,SAAS,IAAI;IAC3B,OAAO,OAAO,OAAO,KAAK;GAC5B;GACA,WAAW;EACb,CAAC;EACD,OAAO;CACT,GACA,WACA,WACAF,mBAAAA,UACA,MACF;AACF"}
1
+ {"version":3,"file":"useState.cjs","names":["identity","deepEqual","useSync"],"sources":["../src/useState.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\nimport type { UseServiceOptions } from './types';\n\n/**\n * A hook that creates a React state from a service with a subscribe function.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.\n *\n * @param service - The service containing state and subscribe method.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.\n *\n * @returns The selected state of type `T`.\n *\n * @see {@linkcode useSync}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useState<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n T = State<Eo, Tc, Ta>,\n>(\n service: { subscribe: AddSubscriber_F<Tc, Ta, Eo>; state: State<Eo, Tc, Ta> },\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n): T {\n const { selector = identity, equals = deepEqual<T> } = options ?? {};\n const _selector = () => selector(service.state);\n\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (prev, next) => {\n const _prev = selector(prev);\n const _next = selector(next);\n return equals(_prev, _next);\n },\n firstTime: true,\n });\n return unsubscribe;\n },\n _selector,\n _selector,\n identity,\n equals,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,SAMd,SACA,SACG;CACH,MAAM,EAAE,WAAWA,mBAAAA,UAAU,SAASC,mBAAAA,cAAiB,WAAW,CAAC;CACnE,MAAM,kBAAkB,SAAS,QAAQ,KAAK;CAE9C,QAAA,GAAOC,oBAAAA,QAAAA,EACL,aAAY;EACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;GAClD,SAAS,MAAM,SAAS;IACtB,MAAM,QAAQ,SAAS,IAAI;IAC3B,MAAM,QAAQ,SAAS,IAAI;IAC3B,OAAO,OAAO,OAAO,KAAK;GAC5B;GACA,WAAW;EACb,CAAC;EACD,OAAO;CACT,GACA,WACA,WACAF,mBAAAA,UACA,MACF;AACF"}
package/lib/useState.d.ts CHANGED
@@ -3,10 +3,10 @@ import type { UseServiceOptions } from './types';
3
3
  /**
4
4
  * A hook that creates a React state from a service with a subscribe function.
5
5
  *
6
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
7
- * @template {string} Ta - Tag type extending `string`.
8
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
9
- * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
6
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
7
+ * @template `Ta` - Tag type extending `string`.
8
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
9
+ * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
10
10
  *
11
11
  * @param service - The service containing state and subscribe method.
12
12
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -14,6 +14,8 @@ import type { UseServiceOptions } from './types';
14
14
  * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.
15
15
  *
16
16
  * @returns The selected state of type `T`.
17
+ *
18
+ * @see {@linkcode useSync}, {@linkcode deepEqual}, {@linkcode identity}
17
19
  */
18
20
  export declare function useState<Tc extends PrimitiveObject, Ta extends string, Eo extends EventObject, T = State<Eo, Tc, Ta>>(service: {
19
21
  subscribe: AddSubscriber_F<Tc, Ta, Eo>;
@@ -1 +1 @@
1
- {"version":3,"file":"useState.d.ts","sourceRoot":"","sources":["../src/useState.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CACtB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,CAAC,GAAG,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAErB,OAAO,EAAE;IACP,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IACvC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;CAC1B,EACD,OAAO,CAAC,EAAE,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,GACzC,CAAC,CAqBH"}
1
+ {"version":3,"file":"useState.d.ts","sourceRoot":"","sources":["../src/useState.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,KAAK,EACX,MAAM,cAAc,CAAC;AAGtB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,QAAQ,CACtB,EAAE,SAAS,eAAe,EAC1B,EAAE,SAAS,MAAM,EACjB,EAAE,SAAS,WAAW,EACtB,CAAC,GAAG,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAErB,OAAO,EAAE;IAAE,SAAS,EAAE,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;IAAC,KAAK,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAA;CAAE,EAC7E,OAAO,CAAC,EAAE,iBAAiB,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,GACzC,CAAC,CAqBH"}
package/lib/useState.js CHANGED
@@ -4,10 +4,10 @@ import { useSync } from "@bemedev/react-sync";
4
4
  /**
5
5
  * A hook that creates a React state from a service with a subscribe function.
6
6
  *
7
- * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.
8
- * @template {string} Ta - Tag type extending `string`.
9
- * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.
10
- * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
7
+ * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.
8
+ * @template `Ta` - Tag type extending `string`.
9
+ * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.
10
+ * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.
11
11
  *
12
12
  * @param service - The service containing state and subscribe method.
13
13
  * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.
@@ -15,6 +15,8 @@ import { useSync } from "@bemedev/react-sync";
15
15
  * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.
16
16
  *
17
17
  * @returns The selected state of type `T`.
18
+ *
19
+ * @see {@linkcode useSync}, {@linkcode deepEqual}, {@linkcode identity}
18
20
  */
19
21
  function useState(service, options) {
20
22
  const { selector = identity, equals = deepEqual } = options ?? {};
@@ -1 +1 @@
1
- {"version":3,"file":"useState.js","names":[],"sources":["../src/useState.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\nimport type { UseServiceOptions } from './types';\n\n/**\n * A hook that creates a React state from a service with a subscribe function.\n *\n * @template {PrimitiveObject} Tc - Context type extending type {@linkcode PrimitiveObject}.\n * @template {string} Ta - Tag type extending `string`.\n * @template {EventObject} Eo - Event object type extending type {@linkcode EventObject}.\n * @template T - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.\n *\n * @param service - The service containing state and subscribe method.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.\n *\n * @returns The selected state of type `T`.\n */\nexport function useState<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n T = State<Eo, Tc, Ta>,\n>(\n service: {\n subscribe: AddSubscriber_F<Tc, Ta, Eo>;\n state: State<Eo, Tc, Ta>;\n },\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n): T {\n const { selector = identity, equals = deepEqual<T> } = options ?? {};\n const _selector = () => selector(service.state);\n\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (prev, next) => {\n const _prev = selector(prev);\n const _next = selector(next);\n return equals(_prev, _next);\n },\n firstTime: true,\n });\n return unsubscribe;\n },\n _selector,\n _selector,\n identity,\n equals,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,SAAgB,SAMd,SAIA,SACG;CACH,MAAM,EAAE,WAAW,UAAU,SAAS,cAAiB,WAAW,CAAC;CACnE,MAAM,kBAAkB,SAAS,QAAQ,KAAK;CAE9C,OAAO,SACL,aAAY;EACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;GAClD,SAAS,MAAM,SAAS;IACtB,MAAM,QAAQ,SAAS,IAAI;IAC3B,MAAM,QAAQ,SAAS,IAAI;IAC3B,OAAO,OAAO,OAAO,KAAK;GAC5B;GACA,WAAW;EACb,CAAC;EACD,OAAO;CACT,GACA,WACA,WACA,UACA,MACF;AACF"}
1
+ {"version":3,"file":"useState.js","names":[],"sources":["../src/useState.ts"],"sourcesContent":["import {\n type AddSubscriber_F,\n type EventObject,\n type PrimitiveObject,\n type State,\n} from '@bemedev/app';\nimport { deepEqual, identity } from '@bemedev/app/utils';\nimport { useSync } from '@bemedev/react-sync';\nimport type { UseServiceOptions } from './types';\n\n/**\n * A hook that creates a React state from a service with a subscribe function.\n *\n * @template | {@linkcode PrimitiveObject} `Tc` - Context type extending type {@linkcode PrimitiveObject}.\n * @template `Ta` - Tag type extending `string`.\n * @template | {@linkcode EventObject} `Eo` - Event object type extending type {@linkcode EventObject}.\n * @template `T` - Selected state type, defaults to type {@linkcode State}<{@linkcode Eo}, {@linkcode Tc}, {@linkcode Ta}>.\n *\n * @param service - The service containing state and subscribe method.\n * @param service.subscribe - Subscription handler function of type {@linkcode AddSubscriber_F}.\n * @param service.state - Current state of type {@linkcode State}.\n * @param options - Optional configuration options of type {@linkcode UseServiceOptions}.\n *\n * @returns The selected state of type `T`.\n *\n * @see {@linkcode useSync}, {@linkcode deepEqual}, {@linkcode identity}\n */\nexport function useState<\n Tc extends PrimitiveObject,\n Ta extends string,\n Eo extends EventObject,\n T = State<Eo, Tc, Ta>,\n>(\n service: { subscribe: AddSubscriber_F<Tc, Ta, Eo>; state: State<Eo, Tc, Ta> },\n options?: UseServiceOptions<Tc, Ta, Eo, T>,\n): T {\n const { selector = identity, equals = deepEqual<T> } = options ?? {};\n const _selector = () => selector(service.state);\n\n return useSync(\n listener => {\n const { unsubscribe } = service.subscribe(listener, {\n equals: (prev, next) => {\n const _prev = selector(prev);\n const _next = selector(next);\n return equals(_prev, _next);\n },\n firstTime: true,\n });\n return unsubscribe;\n },\n _selector,\n _selector,\n identity,\n equals,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,SAMd,SACA,SACG;CACH,MAAM,EAAE,WAAW,UAAU,SAAS,cAAiB,WAAW,CAAC;CACnE,MAAM,kBAAkB,SAAS,QAAQ,KAAK;CAE9C,OAAO,SACL,aAAY;EACV,MAAM,EAAE,gBAAgB,QAAQ,UAAU,UAAU;GAClD,SAAS,MAAM,SAAS;IACtB,MAAM,QAAQ,SAAS,IAAI;IAC3B,MAAM,QAAQ,SAAS,IAAI;IAC3B,OAAO,OAAO,OAAO,KAAK;GAC5B;GACA,WAAW;EACb,CAAC;EACD,OAAO;CACT,GACA,WACA,WACA,UACA,MACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bemedev/app-reactjs",
3
- "version": "1.11.0",
3
+ "version": "2.0.0",
4
4
  "description": "Middleware between @bemedev/app and reactjs",
5
5
  "keywords": [
6
6
  "app",
@@ -45,7 +45,7 @@
45
45
  "types": "lib/index.d.ts",
46
46
  "devDependencies": {
47
47
  "@bemedev/decompose": "2.3.0",
48
- "@bemedev/dev-utils": "^1.1.1",
48
+ "@bemedev/dev-utils": "^1.2.0",
49
49
  "@bemedev/sleep": "^0.2.2",
50
50
  "@size-limit/file": "^13.0.3",
51
51
  "@testing-library/jest-dom": "^7.0.1",
@@ -54,32 +54,32 @@
54
54
  "@types/node": "^26.2.0",
55
55
  "@types/react": "^19.2.18",
56
56
  "@types/react-dom": "^19.2.4",
57
- "@vitest/coverage-v8": "^4.1.10",
58
- "@vitest/ui": "4.1.10",
57
+ "@vitest/coverage-v8": "^4.1.11",
58
+ "@vitest/ui": "4.1.11",
59
59
  "glob": "^13.0.6",
60
60
  "globals": "^17.11.0",
61
61
  "husky": "^9.1.7",
62
62
  "jsdom": "^30.0.1",
63
63
  "onchange": "^7.1.0",
64
- "oxfmt": "^0.63.0",
65
- "oxlint": "^1.78.0",
64
+ "oxfmt": "^0.64.0",
65
+ "oxlint": "^1.79.0",
66
66
  "prettier": "^3.9.6",
67
67
  "pretty-quick": "^4.2.2",
68
68
  "react": "^19.2.8",
69
69
  "react-dom": "^19.2.8",
70
- "rolldown": "1.2.4",
70
+ "rolldown": "1.2.5",
71
71
  "rolldown-plugin-dts": "^0.28.2",
72
72
  "size-limit": "^13.0.3",
73
73
  "tslib": "^2.8.1",
74
74
  "tsx": "^4.23.12",
75
75
  "typescript": "6.0.3",
76
- "vitest": "^4.1.10",
77
- "@bemedev/app": "^1.11.0",
78
- "@bemedev/app-vitest": "^1.11.0"
76
+ "vitest": "^4.1.11",
77
+ "@bemedev/app": "^2.0.0",
78
+ "@bemedev/app-vitest": "^2.0.0"
79
79
  },
80
80
  "peerDependencies": {
81
81
  "react": "^19.2.8",
82
- "@bemedev/app": "^1.11.0"
82
+ "@bemedev/app": "^2.0.0"
83
83
  },
84
84
  "size-limit": [
85
85
  {