@wirestate/react 0.6.2 → 0.7.0-experimental.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.
Files changed (158) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +185 -221
  3. package/cjs/development/index.js +462 -222
  4. package/cjs/development/index.js.map +1 -1
  5. package/cjs/development/lib.js +167 -45
  6. package/cjs/development/lib.js.map +1 -1
  7. package/cjs/development/test-utils.js +22 -11
  8. package/cjs/development/test-utils.js.map +1 -1
  9. package/cjs/production/index.js +1 -1
  10. package/cjs/production/index.js.map +1 -1
  11. package/cjs/production/lib.js +1 -1
  12. package/cjs/production/lib.js.map +1 -1
  13. package/cjs/production/test-utils.js +1 -1
  14. package/cjs/production/test-utils.js.map +1 -1
  15. package/esm/development/commands/use-command-caller.js +16 -3
  16. package/esm/development/commands/use-command-caller.js.map +1 -1
  17. package/esm/development/commands/use-command-handler.js +20 -4
  18. package/esm/development/commands/use-command-handler.js.map +1 -1
  19. package/esm/development/commands/use-optional-command-caller.js +20 -4
  20. package/esm/development/commands/use-optional-command-caller.js.map +1 -1
  21. package/esm/development/context/container-context.js +16 -0
  22. package/esm/development/context/container-context.js.map +1 -0
  23. package/esm/development/context/use-container.js +33 -0
  24. package/esm/development/context/use-container.js.map +1 -0
  25. package/esm/development/context/use-root-container.js +35 -0
  26. package/esm/development/context/use-root-container.js.map +1 -0
  27. package/esm/development/context/use-scope.js +31 -0
  28. package/esm/development/context/use-scope.js.map +1 -0
  29. package/esm/development/error/error-code.js +1 -3
  30. package/esm/development/error/error-code.js.map +1 -1
  31. package/esm/development/events/use-event-emitter.js +20 -4
  32. package/esm/development/events/use-event-emitter.js.map +1 -1
  33. package/esm/development/events/use-event.js +18 -4
  34. package/esm/development/events/use-event.js.map +1 -1
  35. package/esm/development/events/use-events-handler.js +18 -3
  36. package/esm/development/events/use-events-handler.js.map +1 -1
  37. package/esm/development/events/use-events.js +18 -4
  38. package/esm/development/events/use-events.js.map +1 -1
  39. package/esm/development/index.js +12 -10
  40. package/esm/development/index.js.map +1 -1
  41. package/esm/development/injection/use-injection.js +36 -0
  42. package/esm/development/injection/use-injection.js.map +1 -0
  43. package/esm/development/injection/use-optional-injection.js +40 -0
  44. package/esm/development/injection/use-optional-injection.js.map +1 -0
  45. package/esm/development/provision/container-activator.js +33 -0
  46. package/esm/development/provision/container-activator.js.map +1 -0
  47. package/esm/development/provision/container-provider.js +74 -0
  48. package/esm/development/provision/container-provider.js.map +1 -0
  49. package/esm/development/provision/sub-container-provider.js +69 -0
  50. package/esm/development/provision/sub-container-provider.js.map +1 -0
  51. package/esm/development/provision/use-container-provision-state.js +76 -0
  52. package/esm/development/provision/use-container-provision-state.js.map +1 -0
  53. package/esm/development/queries/use-optional-query-caller.js +16 -4
  54. package/esm/development/queries/use-optional-query-caller.js.map +1 -1
  55. package/esm/development/queries/use-optional-sync-query-caller.js +14 -3
  56. package/esm/development/queries/use-optional-sync-query-caller.js.map +1 -1
  57. package/esm/development/queries/use-query-caller.js +15 -3
  58. package/esm/development/queries/use-query-caller.js.map +1 -1
  59. package/esm/development/queries/use-query-handler.js +21 -5
  60. package/esm/development/queries/use-query-handler.js.map +1 -1
  61. package/esm/development/queries/use-sync-query-caller.js +15 -3
  62. package/esm/development/queries/use-sync-query-caller.js.map +1 -1
  63. package/esm/development/test-utils/with-container-provider.js +35 -0
  64. package/esm/development/test-utils/with-container-provider.js.map +1 -0
  65. package/esm/development/test-utils.js +1 -1
  66. package/esm/development/utils/shallow-equal-arrays.js +28 -0
  67. package/esm/development/utils/shallow-equal-arrays.js.map +1 -0
  68. package/esm/production/commands/use-command-caller.js +1 -1
  69. package/esm/production/commands/use-command-caller.js.map +1 -1
  70. package/esm/production/commands/use-command-handler.js +1 -1
  71. package/esm/production/commands/use-command-handler.js.map +1 -1
  72. package/esm/production/commands/use-optional-command-caller.js +1 -1
  73. package/esm/production/commands/use-optional-command-caller.js.map +1 -1
  74. package/esm/production/context/container-context.js +1 -0
  75. package/esm/production/context/container-context.js.map +1 -0
  76. package/esm/production/context/use-container.js +1 -0
  77. package/esm/production/context/use-container.js.map +1 -0
  78. package/esm/production/context/use-root-container.js +1 -0
  79. package/esm/production/context/use-root-container.js.map +1 -0
  80. package/esm/production/context/use-scope.js +1 -0
  81. package/esm/production/context/use-scope.js.map +1 -0
  82. package/esm/production/error/error-code.js +1 -1
  83. package/esm/production/error/error-code.js.map +1 -1
  84. package/esm/production/events/use-event-emitter.js +1 -1
  85. package/esm/production/events/use-event-emitter.js.map +1 -1
  86. package/esm/production/events/use-event.js +1 -1
  87. package/esm/production/events/use-event.js.map +1 -1
  88. package/esm/production/events/use-events-handler.js +1 -1
  89. package/esm/production/events/use-events-handler.js.map +1 -1
  90. package/esm/production/events/use-events.js +1 -1
  91. package/esm/production/events/use-events.js.map +1 -1
  92. package/esm/production/index.js +1 -1
  93. package/esm/production/injection/use-injection.js +1 -0
  94. package/esm/production/injection/use-injection.js.map +1 -0
  95. package/esm/production/injection/use-optional-injection.js +1 -0
  96. package/esm/production/injection/use-optional-injection.js.map +1 -0
  97. package/esm/production/provision/container-activator.js +1 -0
  98. package/esm/production/provision/container-activator.js.map +1 -0
  99. package/esm/production/provision/container-provider.js +1 -0
  100. package/esm/production/provision/container-provider.js.map +1 -0
  101. package/esm/production/provision/sub-container-provider.js +1 -0
  102. package/esm/production/provision/sub-container-provider.js.map +1 -0
  103. package/esm/production/provision/use-container-provision-state.js +1 -0
  104. package/esm/production/provision/use-container-provision-state.js.map +1 -0
  105. package/esm/production/queries/use-optional-query-caller.js +1 -1
  106. package/esm/production/queries/use-optional-query-caller.js.map +1 -1
  107. package/esm/production/queries/use-optional-sync-query-caller.js +1 -1
  108. package/esm/production/queries/use-optional-sync-query-caller.js.map +1 -1
  109. package/esm/production/queries/use-query-caller.js +1 -1
  110. package/esm/production/queries/use-query-caller.js.map +1 -1
  111. package/esm/production/queries/use-query-handler.js +1 -1
  112. package/esm/production/queries/use-query-handler.js.map +1 -1
  113. package/esm/production/queries/use-sync-query-caller.js +1 -1
  114. package/esm/production/queries/use-sync-query-caller.js.map +1 -1
  115. package/esm/production/test-utils/with-container-provider.js +1 -0
  116. package/esm/production/test-utils/with-container-provider.js.map +1 -0
  117. package/esm/production/test-utils.js +1 -1
  118. package/esm/production/utils/shallow-equal-arrays.js +1 -0
  119. package/esm/production/utils/shallow-equal-arrays.js.map +1 -0
  120. package/index.d.ts +554 -137
  121. package/package.json +1 -1
  122. package/test-utils.d.ts +19 -8
  123. package/esm/development/provision/create-injectables-provider.js +0 -101
  124. package/esm/development/provision/create-injectables-provider.js.map +0 -1
  125. package/esm/development/provision/ioc-context.js +0 -11
  126. package/esm/development/provision/ioc-context.js.map +0 -1
  127. package/esm/development/provision/ioc-provider.js +0 -50
  128. package/esm/development/provision/ioc-provider.js.map +0 -1
  129. package/esm/development/provision/use-container-revision.js +0 -13
  130. package/esm/development/provision/use-container-revision.js.map +0 -1
  131. package/esm/development/provision/use-container.js +0 -13
  132. package/esm/development/provision/use-container.js.map +0 -1
  133. package/esm/development/provision/use-injection.js +0 -22
  134. package/esm/development/provision/use-injection.js.map +0 -1
  135. package/esm/development/provision/use-ioc-context.js +0 -21
  136. package/esm/development/provision/use-ioc-context.js.map +0 -1
  137. package/esm/development/provision/use-optional-injection.js +0 -29
  138. package/esm/development/provision/use-optional-injection.js.map +0 -1
  139. package/esm/development/test-utils/with-ioc-provider.js +0 -24
  140. package/esm/development/test-utils/with-ioc-provider.js.map +0 -1
  141. package/esm/production/provision/create-injectables-provider.js +0 -1
  142. package/esm/production/provision/create-injectables-provider.js.map +0 -1
  143. package/esm/production/provision/ioc-context.js +0 -1
  144. package/esm/production/provision/ioc-context.js.map +0 -1
  145. package/esm/production/provision/ioc-provider.js +0 -1
  146. package/esm/production/provision/ioc-provider.js.map +0 -1
  147. package/esm/production/provision/use-container-revision.js +0 -1
  148. package/esm/production/provision/use-container-revision.js.map +0 -1
  149. package/esm/production/provision/use-container.js +0 -1
  150. package/esm/production/provision/use-container.js.map +0 -1
  151. package/esm/production/provision/use-injection.js +0 -1
  152. package/esm/production/provision/use-injection.js.map +0 -1
  153. package/esm/production/provision/use-ioc-context.js +0 -1
  154. package/esm/production/provision/use-ioc-context.js.map +0 -1
  155. package/esm/production/provision/use-optional-injection.js +0 -1
  156. package/esm/production/provision/use-optional-injection.js.map +0 -1
  157. package/esm/production/test-utils/with-ioc-provider.js +0 -1
  158. package/esm/production/test-utils/with-ioc-provider.js.map +0 -1
@@ -1,12 +1,28 @@
1
1
  import { CommandBus } from '@wirestate/core';
2
2
  import { useCallback } from 'react';
3
- import { useContainer } from '../provision/use-container.js';
3
+ import { useContainer } from '../context/use-container.js';
4
4
 
5
5
  /**
6
- * Returns a function to dispatch optional commands on the active container.
7
- * Returns null instead of throwing when no handler is registered.
6
+ * Returns a stable function to dispatch optional commands on the active container.
8
7
  *
9
- * @returns optional command dispatcher
8
+ * @remarks
9
+ * Similar to {@link useCommandCaller}, but returns `null` instead of throwing
10
+ * {WirestateError} if no handler is registered for the command type.
11
+ * Uses {@link CommandBus.commandOptional} internally.
12
+ *
13
+ * @group Commands
14
+ *
15
+ * @returns An optional command dispatcher function.
16
+ *
17
+ * @example
18
+ * ```tsx
19
+ * const callOptional: OptionalCommandCaller = useOptionalCommandCaller();
20
+ * const descriptor: CommandDescriptor<string> | null = callOptional("OPTIONAL_COMMAND", data);
21
+ *
22
+ * if (descriptor) {
23
+ * const result: string = await descriptor.task;
24
+ * }
25
+ * ```
10
26
  */
11
27
  function useOptionalCommandCaller() {
12
28
  var container = useContainer();
@@ -1 +1 @@
1
- {"version":3,"file":"use-optional-command-caller.js","sources":["../../../../../../../../src/wirestate-react/commands/use-optional-command-caller.ts"],"sourcesContent":[null],"names":["useOptionalCommandCaller","container","useContainer","useCallback","type","data","get","CommandBus","commandOptional"],"mappings":";;;;AAQA;;;;;AAKG;SACaA,wBAAwBA,GAAA;AACtC,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;AAE3C,EAAA,OAAOC,WAAW,CAChB,UAAgEC,IAAO,EAAEC,IAAQ,EAAA;AAM/E,IAAA,OAAOJ,SAAS,CAACK,GAAG,CAACC,UAAU,CAAC,CAACC,eAAe,CAAOJ,IAAI,EAAEC,IAAI,CAAC;AACpE,EAAA,CAAC,EACD,CAACJ,SAAS,CAAC,CACZ;AACH;;;;"}
1
+ {"version":3,"file":"use-optional-command-caller.js","sources":["../../../../../../../../src/wirestate-react/commands/use-optional-command-caller.ts"],"sourcesContent":[null],"names":["useOptionalCommandCaller","container","useContainer","useCallback","type","data","get","CommandBus","commandOptional"],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;;AAqBG;SACaA,wBAAwBA,GAAA;AACtC,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;AAE3C,EAAA,OAAOC,WAAW,CAChB,UAAgEC,IAAO,EAAEC,IAAQ,EAAA;AAM/E,IAAA,OAAOJ,SAAS,CAACK,GAAG,CAACC,UAAU,CAAC,CAACC,eAAe,CAAOJ,IAAI,EAAEC,IAAI,CAAC;AACpE,EAAA,CAAC,EACD,CAACJ,SAAS,CAAC,CACZ;AACH;;;;"}
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+
3
+ /**
4
+ * React context carrying the container.
5
+ *
6
+ * @remarks
7
+ * This context is internal to Wirestate. Consumers should use provided hooks
8
+ * like {@link useContainer}, {@link useInjection} or {@link useScope} to access the container and resolved services.
9
+ *
10
+ * @group Context
11
+ */
12
+ var ContainerReactContext = createContext(null);
13
+ ContainerReactContext.displayName = "ContainerContext";
14
+
15
+ export { ContainerReactContext };
16
+ //# sourceMappingURL=container-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-context.js","sources":["../../../../../../../../src/wirestate-react/context/container-context.ts"],"sourcesContent":[null],"names":["ContainerReactContext","createContext","displayName"],"mappings":";;AAKA;;;;;;;;AAQG;IACUA,qBAAqB,GAAiCC,aAAa,CAAsB,IAAI;AAE1GD,qBAAqB,CAACE,WAAW,GAAG,kBAAkB;;;;"}
@@ -0,0 +1,33 @@
1
+ import { WirestateError } from '@wirestate/core';
2
+ import { useContext } from 'react';
3
+ import { ERROR_CODE_INVALID_CONTEXT } from '../error/error-code.js';
4
+ import { ContainerReactContext } from './container-context.js';
5
+
6
+ /**
7
+ * Returns the active container from the context.
8
+ *
9
+ * @remarks
10
+ * Use this hook when you need direct access to the {@link Container} for manual
11
+ * resolution or checking bindings. For typical service usage, prefer
12
+ * {@link useInjection}.
13
+ *
14
+ * @group Context
15
+ *
16
+ * @returns The active container.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const container: Container = useContainer();
21
+ * const isBound: boolean = container.isBound(MyToken);
22
+ * ```
23
+ */
24
+ function useContainer() {
25
+ var value = useContext(ContainerReactContext);
26
+ if (!value) {
27
+ throw new WirestateError(ERROR_CODE_INVALID_CONTEXT, "Trying to access container context from React subtree not wrapped in <ContainerProvider>.");
28
+ }
29
+ return value;
30
+ }
31
+
32
+ export { useContainer };
33
+ //# sourceMappingURL=use-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-container.js","sources":["../../../../../../../../src/wirestate-react/context/use-container.ts"],"sourcesContent":[null],"names":["useContainer","value","useContext","ContainerReactContext","WirestateError","ERROR_CODE_INVALID_CONTEXT"],"mappings":";;;;;AAQA;;;;;;;;;;;;;;;;;AAiBG;SACaA,YAAYA,GAAA;AAC1B,EAAA,IAAMC,KAAK,GAAwBC,UAAU,CAACC,qBAAqB,CAAC;EAEpE,IAAI,CAACF,KAAK,EAAE;AACV,IAAA,MAAM,IAAIG,cAAc,CACtBC,0BAA0B,EAC1B,2FAA2F,CAC5F;AACH,EAAA;AAEA,EAAA,OAAOJ,KAAK;AACd;;;;"}
@@ -0,0 +1,35 @@
1
+ import { useMemo } from 'react';
2
+
3
+ /**
4
+ * Creates and memoizes a root container for a component.
5
+ *
6
+ * @remarks
7
+ * The `factory` function re-runs only when one of `deps` changes.
8
+ * Between such changes, the same container instance is returned.
9
+ *
10
+ * @group Context
11
+ *
12
+ * @param factory - Lazily creates the root container.
13
+ * @param deps - Dependency list controlling when container is recreated.
14
+ * @returns The memoized root container instance.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const container: Container = useRootContainer(
19
+ * () =>
20
+ * createIocContainer({
21
+ * entries: [CounterService, LoggerService],
22
+ * }),
23
+ * []
24
+ * );
25
+ * ```
26
+ */
27
+ function useRootContainer(factory, deps) {
28
+ return useMemo(function () {
29
+ var container = factory();
30
+ return container;
31
+ }, deps);
32
+ }
33
+
34
+ export { useRootContainer };
35
+ //# sourceMappingURL=use-root-container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-root-container.js","sources":["../../../../../../../../src/wirestate-react/context/use-root-container.ts"],"sourcesContent":[null],"names":["useRootContainer","factory","deps","useMemo","container"],"mappings":";;AAMA;;;;;;;;;;;;;;;;;;;;;;;AAuBG;AACG,SAAUA,gBAAgBA,CAACC,OAAwB,EAAEC,IAAoB,EAAA;EAC7E,OAAOC,OAAO,CAAC,YAAA;AACb,IAAA,IAAMC,SAAS,GAAcH,OAAO,EAAE;AAItC,IAAA,OAAOG,SAAS;EAClB,CAAC,EAAEF,IAAI,CAAC;AACV;;;;"}
@@ -0,0 +1,31 @@
1
+ import { WireScope } from '@wirestate/core';
2
+ import { useMemo } from 'react';
3
+ import { useContainer } from './use-container.js';
4
+
5
+ /**
6
+ * Returns a {@link WireScope} instance bound to the active container.
7
+ *
8
+ * @remarks
9
+ * The scope is recreated if the container changes. It provides a convenient
10
+ * way to access container features like events, commands, and queries.
11
+ *
12
+ * @group Context
13
+ *
14
+ * @returns A {@link WireScope} instance.
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * const scope: WireScope = useScope();
19
+ *
20
+ * scope.emitEvent("UI_READY");
21
+ * ```
22
+ */
23
+ function useScope() {
24
+ var container = useContainer();
25
+ return useMemo(function () {
26
+ return container.get(WireScope);
27
+ }, [container]);
28
+ }
29
+
30
+ export { useScope };
31
+ //# sourceMappingURL=use-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-scope.js","sources":["../../../../../../../../src/wirestate-react/context/use-scope.ts"],"sourcesContent":[null],"names":["useScope","container","useContainer","useMemo","get","WireScope"],"mappings":";;;;AAQA;;;;;;;;;;;;;;;;;AAiBG;SACaA,QAAQA,GAAA;AACtB,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;EAE3C,OAAOC,OAAO,CAAC,YAAA;AAKb,IAAA,OAAOF,SAAS,CAACG,GAAG,CAAYC,SAAS,CAAC;AAC5C,EAAA,CAAC,EAAE,CAACJ,SAAS,CAAC,CAAC;AACjB;;;;"}
@@ -1,6 +1,4 @@
1
- var ERROR_CODE_VALIDATION_ERROR = 1050;
2
1
  var ERROR_CODE_INVALID_CONTEXT = 1052;
3
- var ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER = 1101;
4
2
 
5
- export { ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER, ERROR_CODE_INVALID_CONTEXT, ERROR_CODE_VALIDATION_ERROR };
3
+ export { ERROR_CODE_INVALID_CONTEXT };
6
4
  //# sourceMappingURL=error-code.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-code.js","sources":["../../../../../../../../src/wirestate-react/error/error-code.ts"],"sourcesContent":[null],"names":["ERROR_CODE_VALIDATION_ERROR","ERROR_CODE_INVALID_CONTEXT","ERROR_CODE_FAILED_TO_RESOLVE_QUERY_HANDLER"],"mappings":"AAAO,IAAMA,2BAA2B,GAAW;AAC5C,IAAMC,0BAA0B,GAAW;AAE3C,IAAMC,0CAA0C,GAAW;;;;"}
1
+ {"version":3,"file":"error-code.js","sources":["../../../../../../../../src/wirestate-react/error/error-code.ts"],"sourcesContent":[null],"names":["ERROR_CODE_INVALID_CONTEXT"],"mappings":"AACO,IAAMA,0BAA0B,GAAW;;;;"}
@@ -1,14 +1,30 @@
1
1
  import { EventBus } from '@wirestate/core';
2
2
  import { useCallback } from 'react';
3
- import { useIocContext } from '../provision/use-ioc-context.js';
3
+ import { useContainer } from '../context/use-container.js';
4
4
 
5
5
  /**
6
- * Returns a stable function to emit events.
6
+ * Returns a stable function to emit events via the {@link EventBus}.
7
7
  *
8
- * @returns event emitter
8
+ * @remarks
9
+ * The returned emitter is memoized using `useCallback` and stays stable
10
+ * for the lifetime of the container.
11
+ *
12
+ * @group Events
13
+ *
14
+ * @template P - Default payload type for emitted events.
15
+ * @template T - Default event identifier type.
16
+ *
17
+ * @returns An event emitter function.
18
+ *
19
+ * @example
20
+ * ```tsx
21
+ * const emit: EventEmitter = useEventEmitter();
22
+ *
23
+ * const onClick = () => emit("BUTTON_CLICKED", { id: "submit" });
24
+ * ```
9
25
  */
10
26
  function useEventEmitter() {
11
- var container = useIocContext().container;
27
+ var container = useContainer();
12
28
  return useCallback(function (type, payload, from) {
13
29
  container.get(EventBus).emit({
14
30
  type: type,
@@ -1 +1 @@
1
- {"version":3,"file":"use-event-emitter.js","sources":["../../../../../../../../src/wirestate-react/events/use-event-emitter.ts"],"sourcesContent":[null],"names":["useEventEmitter","container","useIocContext","useCallback","type","payload","from","get","EventBus","emit"],"mappings":";;;;AASA;;;;AAIG;SACaA,eAAeA,GAAA;AAC7B,EAAA,IAAMC,SAAS,GAAcC,aAAa,EAAE,CAACD,SAAS;EAEtD,OAAOE,WAAW,CAChB,UAAyBC,IAAO,EAAEC,OAAW,EAAEC,IAAc,EAAA;AAO3DL,IAAAA,SAAS,CAACM,GAAG,CAACC,QAAQ,CAAC,CAACC,IAAI,CAAC;AAAEL,MAAAA,IAAI,EAAAA,IAAA;AAAEC,MAAAA,OAAO,EAAAA,OAAA;AAAEC,MAAAA,IAAI,EAAAA;AAAA,KAAE,CAAC;AACvD,EAAA,CAAC,EACD,CAACL,SAAS,CAAC,CACZ;AACH;;;;"}
1
+ {"version":3,"file":"use-event-emitter.js","sources":["../../../../../../../../src/wirestate-react/events/use-event-emitter.ts"],"sourcesContent":[null],"names":["useEventEmitter","container","useContainer","useCallback","type","payload","from","get","EventBus","emit"],"mappings":";;;;AASA;;;;;;;;;;;;;;;;;;;;AAoBG;SACaA,eAAeA,GAAA;AAC7B,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;EAE3C,OAAOC,WAAW,CAChB,UAAyBC,IAAO,EAAEC,OAAW,EAAEC,IAAc,EAAA;AAO3DL,IAAAA,SAAS,CAACM,GAAG,CAACC,QAAQ,CAAC,CAACC,IAAI,CAAC;AAAEL,MAAAA,IAAI,EAAAA,IAAA;AAAEC,MAAAA,OAAO,EAAAA,OAAA;AAAEC,MAAAA,IAAI,EAAAA;AAAA,KAAE,CAAC;AACvD,EAAA,CAAC,EACD,CAACL,SAAS,CAAC,CACZ;AACH;;;;"}
@@ -1,12 +1,26 @@
1
1
  import { EventBus } from '@wirestate/core';
2
2
  import { useRef, useEffect } from 'react';
3
- import { useContainer } from '../provision/use-container.js';
3
+ import { useContainer } from '../context/use-container.js';
4
4
 
5
5
  /**
6
- * Subscribes a component to events.
6
+ * Subscribes a component to a specific event type on the {@link EventBus}.
7
7
  *
8
- * @param type - event type to listen to
9
- * @param handler - event handler to invoke when event is emitted
8
+ * @remarks
9
+ * The subscription is active for the component's lifetime and is automatically
10
+ * cleaned up on unmount. The handler is synced via `useRef` to avoid stale
11
+ * closures without requiring manual memoization of the handler function.
12
+ *
13
+ * @group Events
14
+ *
15
+ * @param type - Event type to listen for.
16
+ * @param handler - Function invoked when the specified event is emitted.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * useEvent("USER_LOGGED_IN", (event) => {
21
+ * console.log("User logged in:,", event);
22
+ * });
23
+ * ```
10
24
  */
11
25
  function useEvent(type, handler) {
12
26
  var typeRef = useRef(type);
@@ -1 +1 @@
1
- {"version":3,"file":"use-event.js","sources":["../../../../../../../../src/wirestate-react/events/use-event.ts"],"sourcesContent":[null],"names":["useEvent","type","handler","typeRef","useRef","handlerRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","_a","call"],"mappings":";;;;AAKA;;;;;AAKG;AACG,SAAUA,QAAQA,CAACC,IAAe,EAAEC,OAAqB,EAAA;AAC7D,EAAA,IAAMC,OAAO,GAAgCC,MAAM,CAACH,IAAI,CAAC;AACzD,EAAA,IAAMI,UAAU,GAAmCD,MAAM,CAACF,OAAO,CAAC;AAClE,EAAA,IAAMI,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRL,OAAO,CAACM,OAAO,GAAGR,IAAI;IACtBI,UAAU,CAACI,OAAO,GAAGP,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFM,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;AAC7C,MAAA,IAAIA,KAAK,CAACZ,IAAI,KAAKE,OAAO,CAACM,OAAO,EAAE;QAClC,CAAAK,EAAA,GAAAT,UAAU,CAACI,OAAO,MAAA,IAAA,IAAAK,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAV,UAAA,EAAGQ,KAAK,CAAC;AAC7B,MAAA;AACF,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,EAAEL,IAAI,CAAC,CAAC;AACvB;;;;"}
1
+ {"version":3,"file":"use-event.js","sources":["../../../../../../../../src/wirestate-react/events/use-event.ts"],"sourcesContent":[null],"names":["useEvent","type","handler","typeRef","useRef","handlerRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","_a","call"],"mappings":";;;;AAKA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAUA,QAAQA,CAACC,IAAe,EAAEC,OAAqB,EAAA;AAC7D,EAAA,IAAMC,OAAO,GAAgCC,MAAM,CAACH,IAAI,CAAC;AACzD,EAAA,IAAMI,UAAU,GAAmCD,MAAM,CAACF,OAAO,CAAC;AAClE,EAAA,IAAMI,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRL,OAAO,CAACM,OAAO,GAAGR,IAAI;IACtBI,UAAU,CAACI,OAAO,GAAGP,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFM,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;AAC7C,MAAA,IAAIA,KAAK,CAACZ,IAAI,KAAKE,OAAO,CAACM,OAAO,EAAE;QAClC,CAAAK,EAAA,GAAAT,UAAU,CAACI,OAAO,MAAA,IAAA,IAAAK,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAV,UAAA,EAAGQ,KAAK,CAAC;AAC7B,MAAA;AACF,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,EAAEL,IAAI,CAAC,CAAC;AACvB;;;;"}
@@ -1,11 +1,26 @@
1
1
  import { EventBus } from '@wirestate/core';
2
2
  import { useRef, useEffect } from 'react';
3
- import { useContainer } from '../provision/use-container.js';
3
+ import { useContainer } from '../context/use-container.js';
4
4
 
5
5
  /**
6
- * Subscribes a component to all events without type filtering.
6
+ * Subscribes a component to all events on the {@link EventBus} without type filtering.
7
7
  *
8
- * @param handler - event handler invoked for every emitted event
8
+ * @remarks
9
+ * Useful for logging, debugging, or cross-cutting concerns that need to see
10
+ * every event passing through the bus.
11
+ * The handler is synced via `useRef` to avoid stale closures.
12
+ * The subscription is automatically cleaned up on unmount.
13
+ *
14
+ * @group Events
15
+ *
16
+ * @param handler - Event handler invoked for every emitted event.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * useEventsHandler((event) => {
21
+ * console.log('Event receieved:', event.type, event.payload);
22
+ * });
23
+ * ```
9
24
  */
10
25
  function useEventsHandler(handler) {
11
26
  var handlerRef = useRef(handler);
@@ -1 +1 @@
1
- {"version":3,"file":"use-events-handler.js","sources":["../../../../../../../../src/wirestate-react/events/use-events-handler.ts"],"sourcesContent":[null],"names":["useEventsHandler","handler","handlerRef","useRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","_a","call"],"mappings":";;;;AAMA;;;;AAIG;AACG,SAAUA,gBAAgBA,CAACC,OAAqB,EAAA;AACpD,EAAA,IAAMC,UAAU,GAA0CC,MAAM,CAACF,OAAO,CAAC;AACzE,EAAA,IAAMG,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRJ,UAAU,CAACK,OAAO,GAAGN,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFK,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;MAC7C,CAAAC,EAAA,GAAAV,UAAU,CAACK,OAAO,MAAA,IAAA,IAAAK,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAX,UAAA,EAAGS,KAAK,CAAC;AAC7B,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,CAAC,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"use-events-handler.js","sources":["../../../../../../../../src/wirestate-react/events/use-events-handler.ts"],"sourcesContent":[null],"names":["useEventsHandler","handler","handlerRef","useRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","_a","call"],"mappings":";;;;AAMA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAUA,gBAAgBA,CAACC,OAAqB,EAAA;AACpD,EAAA,IAAMC,UAAU,GAA0CC,MAAM,CAACF,OAAO,CAAC;AACzE,EAAA,IAAMG,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRJ,UAAU,CAACK,OAAO,GAAGN,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFK,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;MAC7C,CAAAC,EAAA,GAAAV,UAAU,CAACK,OAAO,MAAA,IAAA,IAAAK,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAX,UAAA,EAAGS,KAAK,CAAC;AAC7B,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,CAAC,CAAC;AACjB;;;;"}
@@ -1,12 +1,26 @@
1
1
  import { EventBus } from '@wirestate/core';
2
2
  import { useRef, useEffect } from 'react';
3
- import { useContainer } from '../provision/use-container.js';
3
+ import { useContainer } from '../context/use-container.js';
4
4
 
5
5
  /**
6
- * Subscribes a component to multiple event types.
6
+ * Subscribes a component to multiple event types on the {@link EventBus}.
7
7
  *
8
- * @param types - event types to filter by
9
- * @param handler - events handler
8
+ * @remarks
9
+ * Similar to {@link useEvent}, but allows listening for a collection of event
10
+ * types using a single handler.
11
+ * The handler and type list are synced via `useRef` to avoid stale closures.
12
+ *
13
+ * @group Events
14
+ *
15
+ * @param types - Array of event types (strings or symbols) to filter by.
16
+ * @param handler - Function invoked when any of the specified events are emitted.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * useEvents(["USER_UPDATED", "USER_DELETED"], (event) => {
21
+ * refreshList();
22
+ * });
23
+ * ```
10
24
  */
11
25
  function useEvents(types, handler) {
12
26
  var typesRef = useRef(types);
@@ -1 +1 @@
1
- {"version":3,"file":"use-events.js","sources":["../../../../../../../../src/wirestate-react/events/use-events.ts"],"sourcesContent":[null],"names":["useEvents","types","handler","typesRef","useRef","handlerRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","includes","type","_a","call"],"mappings":";;;;AAKA;;;;;AAKG;AACG,SAAUA,SAASA,CAACC,KAA+B,EAAEC,OAAqB,EAAA;AAC9E,EAAA,IAAMC,QAAQ,GAA+CC,MAAM,CAACH,KAAK,CAAC;AAC1E,EAAA,IAAMI,UAAU,GAAmCD,MAAM,CAACF,OAAO,CAAC;AAClE,EAAA,IAAMI,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRL,QAAQ,CAACM,OAAO,GAAGR,KAAK;IACxBI,UAAU,CAACI,OAAO,GAAGP,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFM,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;MAC7C,IAAIV,QAAQ,CAACM,OAAO,CAACK,QAAQ,CAACD,KAAK,CAACE,IAAI,CAAC,EAAE;QACzC,CAAAC,EAAA,GAAAX,UAAU,CAACI,OAAO,MAAA,IAAA,IAAAO,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAZ,UAAA,EAAGQ,KAAK,CAAC;AAC7B,MAAA;AACF,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,CAAC,CAAC;AACjB;;;;"}
1
+ {"version":3,"file":"use-events.js","sources":["../../../../../../../../src/wirestate-react/events/use-events.ts"],"sourcesContent":[null],"names":["useEvents","types","handler","typesRef","useRef","handlerRef","container","useContainer","useEffect","current","get","EventBus","subscribe","event","includes","type","_a","call"],"mappings":";;;;AAKA;;;;;;;;;;;;;;;;;;;AAmBG;AACG,SAAUA,SAASA,CAACC,KAA+B,EAAEC,OAAqB,EAAA;AAC9E,EAAA,IAAMC,QAAQ,GAA+CC,MAAM,CAACH,KAAK,CAAC;AAC1E,EAAA,IAAMI,UAAU,GAAmCD,MAAM,CAACF,OAAO,CAAC;AAClE,EAAA,IAAMI,SAAS,GAAcC,YAAY,EAAE;AAE3CC,EAAAA,SAAS,CAAC,YAAA;IACRL,QAAQ,CAACM,OAAO,GAAGR,KAAK;IACxBI,UAAU,CAACI,OAAO,GAAGP,OAAO;AAC9B,EAAA,CAAC,CAAC;AAEFM,EAAAA,SAAS,CAAC,YAAA;IACR,OAAOF,SAAS,CAACI,GAAG,CAACC,QAAQ,CAAC,CAACC,SAAS,CAAC,UAACC,KAAK,EAAA;;MAC7C,IAAIV,QAAQ,CAACM,OAAO,CAACK,QAAQ,CAACD,KAAK,CAACE,IAAI,CAAC,EAAE;QACzC,CAAAC,EAAA,GAAAX,UAAU,CAACI,OAAO,MAAA,IAAA,IAAAO,EAAA,KAAA,MAAA,GAAA,MAAA,GAAAA,EAAA,CAAAC,IAAA,CAAAZ,UAAA,EAAGQ,KAAK,CAAC;AAC7B,MAAA;AACF,IAAA,CAAC,CAAC;AACJ,EAAA,CAAC,EAAE,CAACP,SAAS,CAAC,CAAC;AACjB;;;;"}
@@ -1,19 +1,21 @@
1
1
  export { useCommandCaller } from './commands/use-command-caller.js';
2
2
  export { useOptionalCommandCaller } from './commands/use-optional-command-caller.js';
3
3
  export { useCommandHandler } from './commands/use-command-handler.js';
4
+ export { useContainer } from './context/use-container.js';
5
+ export { useRootContainer } from './context/use-root-container.js';
6
+ export { useScope } from './context/use-scope.js';
7
+ export { useEvent } from './events/use-event.js';
8
+ export { useEvents } from './events/use-events.js';
9
+ export { useEventsHandler } from './events/use-events-handler.js';
10
+ export { useEventEmitter } from './events/use-event-emitter.js';
11
+ export { useInjection } from './injection/use-injection.js';
12
+ export { useOptionalInjection } from './injection/use-optional-injection.js';
13
+ export { SubContainerProvider } from './provision/sub-container-provider.js';
14
+ export { ContainerActivator } from './provision/container-activator.js';
15
+ export { ContainerProvider } from './provision/container-provider.js';
4
16
  export { useQueryCaller } from './queries/use-query-caller.js';
5
17
  export { useOptionalQueryCaller } from './queries/use-optional-query-caller.js';
6
18
  export { useQueryHandler } from './queries/use-query-handler.js';
7
19
  export { useSyncQueryCaller } from './queries/use-sync-query-caller.js';
8
20
  export { useOptionalSyncQueryCaller } from './queries/use-optional-sync-query-caller.js';
9
- export { useInjection } from './provision/use-injection.js';
10
- export { useOptionalInjection } from './provision/use-optional-injection.js';
11
- export { createInjectablesProvider } from './provision/create-injectables-provider.js';
12
- export { IocProvider } from './provision/ioc-provider.js';
13
- export { useContainer } from './provision/use-container.js';
14
- export { useContainerRevision } from './provision/use-container-revision.js';
15
- export { useEvent } from './events/use-event.js';
16
- export { useEvents } from './events/use-events.js';
17
- export { useEventsHandler } from './events/use-events-handler.js';
18
- export { useEventEmitter } from './events/use-event-emitter.js';
19
21
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,36 @@
1
+ import { useMemo } from 'react';
2
+ import { useContainer } from '../context/use-container.js';
3
+
4
+ /**
5
+ * Resolves a service or constant from the active container.
6
+ *
7
+ * @remarks
8
+ * This hook automatically re-resolves the dependency if the container's
9
+ * revision changes (e.g., due to re-binding in a provider).
10
+ *
11
+ * @group Injection
12
+ *
13
+ * @template T - The type of the value being resolved.
14
+ *
15
+ * @param injectionId - The service identifier (string, symbol, or constructor).
16
+ *
17
+ * @returns The resolved instance or value.
18
+ *
19
+ * @throws {WirestateError} If the container is not found in context.
20
+ * @throws {Error} If Inversify fails to resolve the identifier.
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * const api: ApiService = useInjection(ApiService);
25
+ * ```
26
+ */
27
+ function useInjection(injectionId) {
28
+ var container = useContainer();
29
+ // Revision bump causes a container reset; force re-resolution to drop stale instances.
30
+ return useMemo(function () {
31
+ return container.get(injectionId);
32
+ }, [container, injectionId]);
33
+ }
34
+
35
+ export { useInjection };
36
+ //# sourceMappingURL=use-injection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-injection.js","sources":["../../../../../../../../src/wirestate-react/injection/use-injection.ts"],"sourcesContent":[null],"names":["useInjection","injectionId","container","useContainer","useMemo","get"],"mappings":";;;AASA;;;;;;;;;;;;;;;;;;;;;;AAsBG;AACG,SAAUA,YAAYA,CAAIC,WAAiC,EAAA;AAC/D,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;AAE3C;EACA,OAAOC,OAAO,CAAC,YAAA;AAOb,IAAA,OAAOF,SAAS,CAACG,GAAG,CAAIJ,WAAW,CAAC;AACtC,EAAA,CAAC,EAAE,CAACC,SAAS,EAAED,WAAW,CAAC,CAAC;AAC9B;;;;"}
@@ -0,0 +1,40 @@
1
+ import { useMemo } from 'react';
2
+ import { useContainer } from '../context/use-container.js';
3
+
4
+ /**
5
+ * Safely resolves a value from the container, returning a fallback or null if not bound.
6
+ *
7
+ * @remarks
8
+ * Unlike {@link useInjection}, this hook does not throw if the dependency
9
+ * is missing from the container.
10
+ *
11
+ * @group Injection
12
+ *
13
+ * @template T - The type of the value being resolved.
14
+ *
15
+ * @param injectionId - The service identifier (string, symbol, or constructor).
16
+ * @param onFallback - Optional function called to provide a value if the token is not bound.
17
+ *
18
+ * @returns The resolved value, the result of the fallback function, or `null`.
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * const logger = useOptionalInjection(FileLogger, (container) => container.get(ConsoleLoggerService);
23
+ * ```
24
+ */
25
+ function useOptionalInjection(injectionId, onFallback) {
26
+ var container = useContainer();
27
+ // Revision bump forces a container reset; force re-resolution to drop stale instances.
28
+ return useMemo(function () {
29
+ if (container.isBound(injectionId)) {
30
+ return container.get(injectionId);
31
+ } else if (onFallback) {
32
+ return onFallback(container);
33
+ } else {
34
+ return null;
35
+ }
36
+ }, [container, injectionId]);
37
+ }
38
+
39
+ export { useOptionalInjection };
40
+ //# sourceMappingURL=use-optional-injection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-optional-injection.js","sources":["../../../../../../../../src/wirestate-react/injection/use-optional-injection.ts"],"sourcesContent":[null],"names":["useOptionalInjection","injectionId","onFallback","container","useContainer","useMemo","isBound","get"],"mappings":";;;AASA;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAUA,oBAAoBA,CAClCC,WAAiC,EACjCC,UAAwC,EAAA;AAExC,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;AAE3C;EACA,OAAOC,OAAO,CAAC,YAAA;AACb,IAAA,IAAIF,SAAS,CAACG,OAAO,CAACL,WAAW,CAAC,EAAE;AAQlC,MAAA,OAAOE,SAAS,CAACI,GAAG,CAAIN,WAAW,CAAC;IACtC,CAAC,MAAM,IAAIC,UAAU,EAAE;MAQrB,OAAOA,UAAU,CAACC,SAAS,CAAC;AAC9B,IAAA,CAAC,MAAM;AAQL,MAAA,OAAO,IAAI;AACb,IAAA;AACF,EAAA,CAAC,EAAE,CAACA,SAAS,EAAEF,WAAW,CAAC,CAAC;AAC9B;;;;"}
@@ -0,0 +1,33 @@
1
+ import { useRef } from 'react';
2
+ import { useContainer } from '../context/use-container.js';
3
+
4
+ /**
5
+ * Resolves specified services from the current IoC container before rendering children.
6
+ *
7
+ * @remarks
8
+ * Activation runs once per container instance.
9
+ * On rerender with the same container, services are not resolved again.
10
+ *
11
+ * @group Provision
12
+ *
13
+ * @param props - Component properties.
14
+ * @param props.activate - Services to resolve eagerly from container.
15
+ * @param props.children - React children element.
16
+ * @returns React children after activation side effect is applied.
17
+ */
18
+ function ContainerActivator(props) {
19
+ var _a;
20
+ var container = useContainer();
21
+ var activatedContainerRef = useRef(null);
22
+ if (activatedContainerRef.current !== container) {
23
+ activatedContainerRef.current = container;
24
+ for (var _i = 0, _b = props.activate; _i < _b.length; _i++) {
25
+ var entry = _b[_i];
26
+ container.get(entry);
27
+ }
28
+ }
29
+ return (_a = props.children) !== null && _a !== void 0 ? _a : null;
30
+ }
31
+
32
+ export { ContainerActivator };
33
+ //# sourceMappingURL=container-activator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-activator.js","sources":["../../../../../../../../src/wirestate-react/provision/container-activator.ts"],"sourcesContent":[null],"names":["ContainerActivator","props","container","useContainer","activatedContainerRef","useRef","current","_i","_b","activate","length","entry","get","children","_a"],"mappings":";;;AA0BA;;;;;;;;;;;;;AAaG;AACG,SAAUA,kBAAkBA,CAACC,KAA8B,EAAA;;AAC/D,EAAA,IAAMC,SAAS,GAAcC,YAAY,EAAE;AAC3C,EAAA,IAAMC,qBAAqB,GAA0CC,MAAM,CAAC,IAAI,CAAC;AAEjF,EAAA,IAAID,qBAAqB,CAACE,OAAO,KAAKJ,SAAS,EAAE;IAC/CE,qBAAqB,CAACE,OAAO,GAAGJ,SAAS;AAEzC,IAAA,KAAoB,IAAAK,EAAA,GAAA,CAAc,EAAdC,EAAA,GAAAP,KAAK,CAACQ,QAAQ,EAAdF,EAAA,GAAAC,EAAA,CAAAE,MAAc,EAAdH,EAAA,EAAc,EAAE;AAA/B,MAAA,IAAMI,KAAK,GAAAH,EAAA,CAAAD,EAAA,CAAA;AACdL,MAAAA,SAAS,CAACU,GAAG,CAACD,KAAK,CAAC;AACtB,IAAA;AACF,EAAA;AAEA,EAAA,OAAO,MAACV,KAAK,CAACY,QAAyB,MAAA,IAAA,IAAAC,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,IAAI;AACjD;;;;"}
@@ -0,0 +1,74 @@
1
+ import { Container, createContainer } from '@wirestate/core';
2
+ import { createElement } from 'react';
3
+ import { ContainerReactContext } from '../context/container-context.js';
4
+ import { shallowEqualArrays } from '../utils/shallow-equal-arrays.js';
5
+ import { useContainerProvisionState } from './use-container-provision-state.js';
6
+
7
+ /**
8
+ * Provides a root Wirestate container to a React subtree.
9
+ *
10
+ * @remarks
11
+ * The provider supports two modes:
12
+ *
13
+ * - External mode: `container` is a prebuilt {@link Container}. The provider
14
+ * only passes it through context.
15
+ * - Managed mode: `container` is {@link CreateContainerOptions}. The provider
16
+ * creates a container, owns its disposal, recreates it when `entries` change,
17
+ * and revives it after React development remount cleanup.
18
+ *
19
+ * @group Provision
20
+ *
21
+ * @param props - Provider props.
22
+ * @returns A React context provider for the active container.
23
+ */
24
+ function ContainerProvider(props) {
25
+ var _a;
26
+ var state = useContainerProvisionState(props.container, {
27
+ create: createContainerState,
28
+ label: "ContainerProvider",
29
+ reuse: canReuseContainerState
30
+ });
31
+ return createElement(ContainerReactContext.Provider, {
32
+ value: state.container
33
+ }, (_a = props.children) !== null && _a !== void 0 ? _a : null);
34
+ }
35
+ /**
36
+ * Selects the provider state that should be exposed for the current source.
37
+ *
38
+ * @param current - Previously exposed state, if any.
39
+ * @param source - Current container source prop.
40
+ * @param disposed - Containers already disposed by this provider.
41
+ * @returns `true` when current state can be reused.
42
+ */
43
+ function canReuseContainerState(current, source, disposed) {
44
+ var _a, _b;
45
+ if (source instanceof Container) {
46
+ return !current.owned && current.container === source;
47
+ }
48
+ return current.owned && !disposed.has(current.container) && shallowEqualArrays((_a = source.entries) !== null && _a !== void 0 ? _a : [], current.source instanceof Container ? [] : (_b = current.source.entries) !== null && _b !== void 0 ? _b : []);
49
+ }
50
+ /**
51
+ * Creates provider state for an external or managed container source.
52
+ *
53
+ * @param source - Container instance or creation options.
54
+ * @returns Provider state ready for context.
55
+ */
56
+ function createContainerState(source) {
57
+ if (source instanceof Container) {
58
+ return {
59
+ source: source,
60
+ container: source,
61
+ owned: false
62
+ };
63
+ } else {
64
+ var container = createContainer(source);
65
+ return {
66
+ source: source,
67
+ container: container,
68
+ owned: true
69
+ };
70
+ }
71
+ }
72
+
73
+ export { ContainerProvider };
74
+ //# sourceMappingURL=container-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container-provider.js","sources":["../../../../../../../../src/wirestate-react/provision/container-provider.ts"],"sourcesContent":[null],"names":["ContainerProvider","props","state","useContainerProvisionState","container","create","createContainerState","label","reuse","canReuseContainerState","createElement","ContainerReactContext","Provider","value","_a","children","current","source","disposed","Container","owned","has","shallowEqualArrays","entries","_b","createContainer"],"mappings":";;;;;;AAkDA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAUA,iBAAiBA,CAACC,KAA6B,EAAA;;AAC7D,EAAA,IAAMC,KAAK,GAA2BC,0BAA0B,CAACF,KAAK,CAACG,SAAS,EAAE;AAChFC,IAAAA,MAAM,EAAEC,oBAAoB;AAC5BC,IAAAA,KAAK,EAAE,mBAAmB;AAC1BC,IAAAA,KAAK,EAAEC;AACR,GAAA,CAAC;AAEF,EAAA,OAAOC,aAAa,CAACC,qBAAqB,CAACC,QAAQ,EAAE;IAAEC,KAAK,EAAEX,KAAK,CAACE;AAAS,GAAE,EAAE,CAAAU,EAAA,GAAAb,KAAK,CAACc,QAAQ,MAAA,IAAA,IAAAD,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,IAAI,CAAC;AAC1G;AAEA;;;;;;;AAOG;AACH,SAASL,sBAAsBA,CAC7BO,OAA+B,EAC/BC,MAA+B,EAC/BC,QAA4B,EAAA;;EAE5B,IAAID,MAAM,YAAYE,SAAS,EAAE;IAC/B,OAAO,CAACH,OAAO,CAACI,KAAK,IAAIJ,OAAO,CAACZ,SAAS,KAAKa,MAAM;AACvD,EAAA;AAEA,EAAA,OACED,OAAO,CAACI,KAAK,IACb,CAACF,QAAQ,CAACG,GAAG,CAACL,OAAO,CAACZ,SAAS,CAAC,IAChCkB,kBAAkB,CAAC,CAAAR,EAAA,GAAAG,MAAM,CAACM,OAAO,MAAA,IAAA,IAAAT,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,EAAE,EAAEE,OAAO,CAACC,MAAM,YAAYE,SAAS,GAAG,EAAE,GAAI,CAAAK,EAAA,GAAAR,OAAO,CAACC,MAAM,CAACM,OAAO,MAAA,IAAA,IAAAC,EAAA,KAAA,MAAA,GAAAA,EAAA,GAAI,EAAG,CAAC;AAEvH;AAEA;;;;;AAKG;AACH,SAASlB,oBAAoBA,CAACW,MAA+B,EAAA;EAC3D,IAAIA,MAAM,YAAYE,SAAS,EAAE;IAK/B,OAAO;AACLF,MAAAA,MAAM,EAAAA,MAAA;AACNb,MAAAA,SAAS,EAAEa,MAAM;AACjBG,MAAAA,KAAK,EAAE;KACR;AACH,EAAA,CAAC,MAAM;AAKL,IAAA,IAAMhB,SAAS,GAAcqB,eAAe,CAACR,MAAM,CAAC;IAEpD,OAAO;AACLA,MAAAA,MAAM,EAAAA,MAAA;AACNb,MAAAA,SAAS,EAAAA,SAAA;AACTgB,MAAAA,KAAK,EAAE;KACR;AACH,EAAA;AACF;;;;"}