@wirestate/react 0.6.0 → 0.6.2
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/CHANGELOG.md +9 -0
- package/cjs/development/index.js +2 -2
- package/cjs/development/index.js.map +1 -1
- package/cjs/development/lib.js +4 -4
- package/cjs/development/lib.js.map +1 -1
- package/cjs/development/test-utils.js +2 -1050
- package/cjs/development/test-utils.js.map +1 -1
- package/cjs/production/index.js.map +1 -1
- package/cjs/production/lib.js.map +1 -1
- package/cjs/production/test-utils.js +1 -1
- package/cjs/production/test-utils.js.map +1 -1
- package/esm/development/commands/use-command-caller.js.map +1 -0
- package/esm/development/commands/use-command-handler.js.map +1 -0
- package/esm/development/commands/use-optional-command-caller.js.map +1 -0
- package/esm/development/error/error-code.js.map +1 -0
- package/esm/development/events/use-event-emitter.js.map +1 -0
- package/esm/development/events/use-event.js.map +1 -0
- package/esm/development/events/use-events-handler.js.map +1 -0
- package/esm/development/{wirestate-react/events → events}/use-events.js +0 -1
- package/esm/development/events/use-events.js.map +1 -0
- package/esm/development/{wirestate-react/provision → provision}/create-injectables-provider.js +2 -2
- package/esm/development/provision/create-injectables-provider.js.map +1 -0
- package/esm/development/{wirestate-react/provision → provision}/ioc-context.js +3 -3
- package/esm/development/provision/ioc-context.js.map +1 -0
- package/esm/development/{wirestate-react/provision → provision}/ioc-provider.js +2 -2
- package/esm/development/provision/ioc-provider.js.map +1 -0
- package/esm/development/provision/use-container-revision.js.map +1 -0
- package/esm/development/provision/use-container.js.map +1 -0
- package/esm/development/provision/use-injection.js.map +1 -0
- package/esm/development/{wirestate-react/provision → provision}/use-ioc-context.js +2 -2
- package/esm/development/provision/use-ioc-context.js.map +1 -0
- package/esm/development/provision/use-optional-injection.js.map +1 -0
- package/esm/development/queries/use-optional-query-caller.js.map +1 -0
- package/esm/development/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/development/queries/use-query-caller.js.map +1 -0
- package/esm/development/queries/use-query-handler.js.map +1 -0
- package/esm/development/queries/use-sync-query-caller.js.map +1 -0
- package/esm/development/{wirestate-react/test-utils → test-utils}/with-ioc-provider.js +1 -7
- package/esm/development/test-utils/with-ioc-provider.js.map +1 -0
- package/esm/production/commands/use-command-caller.js.map +1 -0
- package/esm/production/commands/use-command-handler.js.map +1 -0
- package/esm/production/commands/use-optional-command-caller.js.map +1 -0
- package/esm/production/error/error-code.js.map +1 -0
- package/esm/production/events/use-event-emitter.js.map +1 -0
- package/esm/production/events/use-event.js.map +1 -0
- package/esm/production/events/use-events-handler.js.map +1 -0
- package/esm/production/events/use-events.js +1 -0
- package/esm/production/events/use-events.js.map +1 -0
- package/esm/production/provision/create-injectables-provider.js +1 -0
- package/esm/production/provision/create-injectables-provider.js.map +1 -0
- package/esm/production/provision/ioc-context.js +1 -0
- package/esm/production/provision/ioc-context.js.map +1 -0
- package/esm/production/provision/ioc-provider.js +1 -0
- package/esm/production/provision/ioc-provider.js.map +1 -0
- package/esm/production/provision/use-container-revision.js.map +1 -0
- package/esm/production/provision/use-container.js.map +1 -0
- package/esm/production/provision/use-injection.js.map +1 -0
- package/esm/production/provision/use-ioc-context.js +1 -0
- package/esm/production/provision/use-ioc-context.js.map +1 -0
- package/esm/production/provision/use-optional-injection.js.map +1 -0
- package/esm/production/queries/use-optional-query-caller.js.map +1 -0
- package/esm/production/queries/use-optional-sync-query-caller.js.map +1 -0
- package/esm/production/queries/use-query-caller.js.map +1 -0
- package/esm/production/queries/use-query-handler.js.map +1 -0
- package/esm/production/queries/use-sync-query-caller.js.map +1 -0
- package/esm/production/test-utils/with-ioc-provider.js +1 -0
- package/esm/production/test-utils/with-ioc-provider.js.map +1 -0
- package/index.d.ts +47 -11
- package/package.json +1 -1
- package/esm/development/wirestate-core/bind/bind-constant.js +0 -19
- package/esm/development/wirestate-core/bind/bind-constant.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js +0 -28
- package/esm/development/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-entry.js +0 -39
- package/esm/development/wirestate-core/bind/bind-entry.js.map +0 -1
- package/esm/development/wirestate-core/bind/bind-service.js +0 -253
- package/esm/development/wirestate-core/bind/bind-service.js.map +0 -1
- package/esm/development/wirestate-core/bind/get-entry-token.js +0 -14
- package/esm/development/wirestate-core/bind/get-entry-token.js.map +0 -1
- package/esm/development/wirestate-core/commands/command-bus.js +0 -112
- package/esm/development/wirestate-core/commands/command-bus.js.map +0 -1
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/container/create-ioc-container.js +0 -35
- package/esm/development/wirestate-core/container/create-ioc-container.js.map +0 -1
- package/esm/development/wirestate-core/container/wire-scope.js +0 -151
- package/esm/development/wirestate-core/container/wire-scope.js.map +0 -1
- package/esm/development/wirestate-core/error/error-code.js +0 -10
- package/esm/development/wirestate-core/error/error-code.js.map +0 -1
- package/esm/development/wirestate-core/error/wirestate-error.js +0 -29
- package/esm/development/wirestate-core/error/wirestate-error.js.map +0 -1
- package/esm/development/wirestate-core/events/build-event-dispatcher.js +0 -39
- package/esm/development/wirestate-core/events/build-event-dispatcher.js.map +0 -1
- package/esm/development/wirestate-core/events/event-bus.js +0 -52
- package/esm/development/wirestate-core/events/event-bus.js.map +0 -1
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/queries/query-bus.js +0 -99
- package/esm/development/wirestate-core/queries/query-bus.js.map +0 -1
- package/esm/development/wirestate-core/registry.js +0 -56
- package/esm/development/wirestate-core/registry.js.map +0 -1
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js +0 -27
- package/esm/development/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js +0 -24
- package/esm/development/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
- package/esm/development/wirestate-core/test-utils/mock-container.js +0 -52
- package/esm/development/wirestate-core/test-utils/mock-container.js.map +0 -1
- package/esm/development/wirestate-core/types/commands.js +0 -12
- package/esm/development/wirestate-core/types/commands.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-command-caller.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-command-handler.js.map +0 -1
- package/esm/development/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
- package/esm/development/wirestate-react/error/error-code.js.map +0 -1
- package/esm/development/wirestate-react/events/use-event-emitter.js.map +0 -1
- package/esm/development/wirestate-react/events/use-event.js.map +0 -1
- package/esm/development/wirestate-react/events/use-events-handler.js.map +0 -1
- package/esm/development/wirestate-react/events/use-events.js.map +0 -1
- package/esm/development/wirestate-react/provision/create-injectables-provider.js.map +0 -1
- package/esm/development/wirestate-react/provision/ioc-context.js.map +0 -1
- package/esm/development/wirestate-react/provision/ioc-provider.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-container-revision.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-container.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-injection.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-ioc-context.js.map +0 -1
- package/esm/development/wirestate-react/provision/use-optional-injection.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-query-handler.js.map +0 -1
- package/esm/development/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
- package/esm/development/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-constant.js +0 -1
- package/esm/production/wirestate-core/bind/bind-constant.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js +0 -1
- package/esm/production/wirestate-core/bind/bind-dynamic-value.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-entry.js +0 -1
- package/esm/production/wirestate-core/bind/bind-entry.js.map +0 -1
- package/esm/production/wirestate-core/bind/bind-service.js +0 -1
- package/esm/production/wirestate-core/bind/bind-service.js.map +0 -1
- package/esm/production/wirestate-core/bind/get-entry-token.js +0 -1
- package/esm/production/wirestate-core/bind/get-entry-token.js.map +0 -1
- package/esm/production/wirestate-core/commands/command-bus.js +0 -1
- package/esm/production/wirestate-core/commands/command-bus.js.map +0 -1
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/commands/get-command-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/container/create-ioc-container.js +0 -1
- package/esm/production/wirestate-core/container/create-ioc-container.js.map +0 -1
- package/esm/production/wirestate-core/container/wire-scope.js +0 -1
- package/esm/production/wirestate-core/container/wire-scope.js.map +0 -1
- package/esm/production/wirestate-core/error/error-code.js +0 -1
- package/esm/production/wirestate-core/error/error-code.js.map +0 -1
- package/esm/production/wirestate-core/error/wirestate-error.js +0 -1
- package/esm/production/wirestate-core/error/wirestate-error.js.map +0 -1
- package/esm/production/wirestate-core/events/build-event-dispatcher.js +0 -1
- package/esm/production/wirestate-core/events/build-event-dispatcher.js.map +0 -1
- package/esm/production/wirestate-core/events/event-bus.js +0 -1
- package/esm/production/wirestate-core/events/event-bus.js.map +0 -1
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/events/get-event-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/queries/get-query-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/queries/query-bus.js +0 -1
- package/esm/production/wirestate-core/queries/query-bus.js.map +0 -1
- package/esm/production/wirestate-core/registry.js +0 -1
- package/esm/production/wirestate-core/registry.js.map +0 -1
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/service/get-activated-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js +0 -1
- package/esm/production/wirestate-core/service/get-deactivation-handler-metadata.js.map +0 -1
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js +0 -1
- package/esm/production/wirestate-core/test-utils/mock-bind-entry.js.map +0 -1
- package/esm/production/wirestate-core/test-utils/mock-container.js +0 -1
- package/esm/production/wirestate-core/test-utils/mock-container.js.map +0 -1
- package/esm/production/wirestate-core/types/commands.js +0 -1
- package/esm/production/wirestate-core/types/commands.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-command-caller.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-command-handler.js.map +0 -1
- package/esm/production/wirestate-react/commands/use-optional-command-caller.js.map +0 -1
- package/esm/production/wirestate-react/error/error-code.js.map +0 -1
- package/esm/production/wirestate-react/events/use-event-emitter.js.map +0 -1
- package/esm/production/wirestate-react/events/use-event.js.map +0 -1
- package/esm/production/wirestate-react/events/use-events-handler.js.map +0 -1
- package/esm/production/wirestate-react/events/use-events.js +0 -1
- package/esm/production/wirestate-react/events/use-events.js.map +0 -1
- package/esm/production/wirestate-react/provision/create-injectables-provider.js +0 -1
- package/esm/production/wirestate-react/provision/create-injectables-provider.js.map +0 -1
- package/esm/production/wirestate-react/provision/ioc-context.js +0 -1
- package/esm/production/wirestate-react/provision/ioc-context.js.map +0 -1
- package/esm/production/wirestate-react/provision/ioc-provider.js +0 -1
- package/esm/production/wirestate-react/provision/ioc-provider.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-container-revision.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-container.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-injection.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-ioc-context.js +0 -1
- package/esm/production/wirestate-react/provision/use-ioc-context.js.map +0 -1
- package/esm/production/wirestate-react/provision/use-optional-injection.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-optional-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-optional-sync-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-query-handler.js.map +0 -1
- package/esm/production/wirestate-react/queries/use-sync-query-caller.js.map +0 -1
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js +0 -1
- package/esm/production/wirestate-react/test-utils/with-ioc-provider.js.map +0 -1
- /package/esm/development/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
- /package/esm/development/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
- /package/esm/development/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
- /package/esm/development/{wirestate-react/error → error}/error-code.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-event-emitter.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-event.js +0 -0
- /package/esm/development/{wirestate-react/events → events}/use-events-handler.js +0 -0
- /package/esm/development/{wirestate-react/index.js → index.js} +0 -0
- /package/esm/development/{wirestate-react/index.js.map → index.js.map} +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-container.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-injection.js +0 -0
- /package/esm/development/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
- /package/esm/development/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
- /package/esm/development/{wirestate-react/test-utils.js → test-utils.js} +0 -0
- /package/esm/development/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-command-caller.js +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-command-handler.js +0 -0
- /package/esm/production/{wirestate-react/commands → commands}/use-optional-command-caller.js +0 -0
- /package/esm/production/{wirestate-react/error → error}/error-code.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-event-emitter.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-event.js +0 -0
- /package/esm/production/{wirestate-react/events → events}/use-events-handler.js +0 -0
- /package/esm/production/{wirestate-react/index.js → index.js} +0 -0
- /package/esm/production/{wirestate-react/index.js.map → index.js.map} +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-container-revision.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-container.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-injection.js +0 -0
- /package/esm/production/{wirestate-react/provision → provision}/use-optional-injection.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-optional-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-optional-sync-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-query-handler.js +0 -0
- /package/esm/production/{wirestate-react/queries → queries}/use-sync-query-caller.js +0 -0
- /package/esm/production/{wirestate-react/test-utils.js → test-utils.js} +0 -0
- /package/esm/production/{wirestate-react/test-utils.js.map → test-utils.js.map} +0 -0
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandType, CommandDescriptor, CommandHandler,
|
|
1
|
+
import { CommandType, CommandDescriptor, CommandHandler, QueryType, QueryHandler, ServiceIdentifier, Container, Newable, InjectableDescriptor, SeedEntries, EventType, EventHandler } from '@wirestate/core';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode, ReactElement, Dispatch, SetStateAction, PropsWithChildren } from 'react';
|
|
4
4
|
|
|
@@ -27,6 +27,30 @@ declare function useOptionalCommandCaller(): <R = unknown, D = unknown, T extend
|
|
|
27
27
|
*/
|
|
28
28
|
declare function useCommandHandler<R = unknown, D = unknown>(type: CommandType, handler: CommandHandler<D, R>): void;
|
|
29
29
|
|
|
30
|
+
type Optional<T> = T | null;
|
|
31
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Public query responder signature.
|
|
35
|
+
*/
|
|
36
|
+
type QueryResponder<R = unknown, D = unknown> = (data?: D) => MaybePromise<R>;
|
|
37
|
+
/**
|
|
38
|
+
* Dispatches queries and returns their result as a value or promise.
|
|
39
|
+
*/
|
|
40
|
+
type QueryCaller = <R = unknown, D = unknown, T extends QueryType = QueryType>(type: T, data?: D) => MaybePromise<R>;
|
|
41
|
+
/**
|
|
42
|
+
* Dispatches synchronous queries and returns their result directly.
|
|
43
|
+
*/
|
|
44
|
+
type SyncQueryCaller = <R = unknown, D = unknown, T extends QueryType = QueryType>(type: T, data?: D) => R;
|
|
45
|
+
/**
|
|
46
|
+
* Dispatches optional queries. Returns null when no handler is registered.
|
|
47
|
+
*/
|
|
48
|
+
type OptionalQueryCaller = <R = unknown, D = unknown, T extends QueryType = QueryType>(type: T, data?: D) => Optional<MaybePromise<R>>;
|
|
49
|
+
/**
|
|
50
|
+
* Dispatches optional synchronous queries. Returns null when no handler is registered.
|
|
51
|
+
*/
|
|
52
|
+
type OptionalSyncQueryCaller = <R = unknown, D = unknown, T extends QueryType = QueryType>(type: T, data?: D) => Optional<R>;
|
|
53
|
+
|
|
30
54
|
/**
|
|
31
55
|
* Returns a function to dispatch queries on the active container.
|
|
32
56
|
*
|
|
@@ -77,8 +101,6 @@ declare function useOptionalSyncQueryCaller(): OptionalSyncQueryCaller;
|
|
|
77
101
|
*/
|
|
78
102
|
declare function useInjection<T>(injectionId: ServiceIdentifier<T>): T;
|
|
79
103
|
|
|
80
|
-
type Optional<T> = T | null;
|
|
81
|
-
|
|
82
104
|
/**
|
|
83
105
|
* Resolves a value from the container if bound, returning null otherwise.
|
|
84
106
|
* Unlike {@link useInjection}, this hook does not throw when the token is not bound.
|
|
@@ -92,7 +114,7 @@ declare function useOptionalInjection<T>(injectionId: ServiceIdentifier<T>, onFa
|
|
|
92
114
|
/**
|
|
93
115
|
* Props for the component returned by {@link createInjectablesProvider}.
|
|
94
116
|
*/
|
|
95
|
-
interface
|
|
117
|
+
interface InjectablesProviderProps {
|
|
96
118
|
/**
|
|
97
119
|
* Targeted seeds bound to specific injectables or tokens.
|
|
98
120
|
* Subsequent prop changes are ignored. Use a React `key` to re-seed the tree.
|
|
@@ -110,7 +132,7 @@ type InjectablesProvider = ReturnType<typeof createInjectablesProvider>;
|
|
|
110
132
|
/**
|
|
111
133
|
* Configuration for {@link createInjectablesProvider}.
|
|
112
134
|
*/
|
|
113
|
-
interface
|
|
135
|
+
interface CreateInjectablesProviderOptions {
|
|
114
136
|
/**
|
|
115
137
|
* Services to resolve immediately on mount.
|
|
116
138
|
*/
|
|
@@ -123,15 +145,15 @@ interface ICreateInjectablesProviderOptions {
|
|
|
123
145
|
* @param options - provider configuration
|
|
124
146
|
* @returns injectables provider component
|
|
125
147
|
*/
|
|
126
|
-
declare function createInjectablesProvider(entries: ReadonlyArray<Newable<object> | InjectableDescriptor>, options?:
|
|
127
|
-
(props:
|
|
148
|
+
declare function createInjectablesProvider(entries: ReadonlyArray<Newable<object> | InjectableDescriptor>, options?: CreateInjectablesProviderOptions): {
|
|
149
|
+
(props: InjectablesProviderProps): ReactElement;
|
|
128
150
|
displayName: string;
|
|
129
151
|
};
|
|
130
152
|
|
|
131
153
|
/**
|
|
132
154
|
* React context value.
|
|
133
155
|
*/
|
|
134
|
-
interface
|
|
156
|
+
interface IocContext {
|
|
135
157
|
/**
|
|
136
158
|
* Inversify container.
|
|
137
159
|
*/
|
|
@@ -149,7 +171,7 @@ interface IIocContext {
|
|
|
149
171
|
/**
|
|
150
172
|
* Props for {@link IocProvider}.
|
|
151
173
|
*/
|
|
152
|
-
interface
|
|
174
|
+
interface IocProviderProps extends PropsWithChildren<unknown> {
|
|
153
175
|
/**
|
|
154
176
|
* External container instance. If omitted, a new container is created.
|
|
155
177
|
*/
|
|
@@ -168,7 +190,7 @@ interface IIocProviderProps extends PropsWithChildren<unknown> {
|
|
|
168
190
|
* @param props.children - components to wrap
|
|
169
191
|
* @returns provider element
|
|
170
192
|
*/
|
|
171
|
-
declare function IocProvider({ container: externalContainer, seed, children }:
|
|
193
|
+
declare function IocProvider({ container: externalContainer, seed, children }: IocProviderProps): react.FunctionComponentElement<react.ProviderProps<Optional<IocContext>>>;
|
|
172
194
|
|
|
173
195
|
/**
|
|
174
196
|
* Returns the active IoC container.
|
|
@@ -207,6 +229,11 @@ declare function useEvents(types: ReadonlyArray<EventType>, handler: EventHandle
|
|
|
207
229
|
*/
|
|
208
230
|
declare function useEventsHandler(handler: EventHandler): void;
|
|
209
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Event emitter signature.
|
|
234
|
+
*/
|
|
235
|
+
type EventEmitter<P = unknown, T extends EventType = EventType, F = unknown> = (type: T, payload?: P, from?: F) => void;
|
|
236
|
+
|
|
210
237
|
/**
|
|
211
238
|
* Returns a stable function to emit events.
|
|
212
239
|
*
|
|
@@ -214,5 +241,14 @@ declare function useEventsHandler(handler: EventHandler): void;
|
|
|
214
241
|
*/
|
|
215
242
|
declare function useEventEmitter<P = unknown, T extends EventType = EventType>(): EventEmitter<P, T>;
|
|
216
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Command calling function signature.
|
|
246
|
+
*/
|
|
247
|
+
type CommandCaller<R = unknown, D = unknown, T extends CommandType = CommandType> = (type: T, data?: D) => CommandDescriptor<R>;
|
|
248
|
+
/**
|
|
249
|
+
* Command calling function signature.
|
|
250
|
+
*/
|
|
251
|
+
type OptionalCommandCaller<R = unknown, D = unknown, T extends CommandType = CommandType> = (type: T, data?: D) => Optional<CommandDescriptor<R>>;
|
|
252
|
+
|
|
217
253
|
export { IocProvider, createInjectablesProvider, useCommandCaller, useCommandHandler, useContainer, useContainerRevision, useEvent, useEventEmitter, useEvents, useEventsHandler, useInjection, useOptionalCommandCaller, useOptionalInjection, useOptionalQueryCaller, useOptionalSyncQueryCaller, useQueryCaller, useQueryHandler, useSyncQueryCaller };
|
|
218
|
-
export type {
|
|
254
|
+
export type { CommandCaller, EventEmitter, InjectablesProvider, InjectablesProviderProps, OptionalCommandCaller, OptionalQueryCaller, OptionalSyncQueryCaller, QueryCaller, QueryResponder, SyncQueryCaller };
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { bindingScopeValues } from 'inversify';
|
|
2
|
-
import { ERROR_CODE_BINDING_SCOPE } from '../error/error-code.js';
|
|
3
|
-
import { WirestateError } from '../error/wirestate-error.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Binds a constant value to a token in the container.
|
|
7
|
-
*
|
|
8
|
-
* @param container - target Inversify container
|
|
9
|
-
* @param entry - entry descriptor to bind
|
|
10
|
-
*/
|
|
11
|
-
function bindConstant(container, entry) {
|
|
12
|
-
if (entry.scopeBindingType && entry.scopeBindingType !== bindingScopeValues.Singleton) {
|
|
13
|
-
throw new WirestateError(ERROR_CODE_BINDING_SCOPE, "Provided unexpected binding scope for constant value.");
|
|
14
|
-
}
|
|
15
|
-
container.bind(entry.id).toConstantValue(entry.value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { bindConstant };
|
|
19
|
-
//# sourceMappingURL=bind-constant.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bind-constant.js","sources":["../../../../../../../../../src/wirestate-core/bind/bind-constant.ts"],"sourcesContent":[null],"names":["bindConstant","container","entry","scopeBindingType","ScopeBindingType","Singleton","WirestateError","ERROR_CODE_BINDING_SCOPE","bind","id","toConstantValue","value"],"mappings":";;;;AAUA;;;;;AAKG;AACG,SAAUA,YAAYA,CAAIC,SAAoB,EAAEC,KAA4B,EAAA;EAQhF,IAAIA,KAAK,CAACC,gBAAgB,IAAID,KAAK,CAACC,gBAAgB,KAAKC,kBAAgB,CAACC,SAAS,EAAE;AACnF,IAAA,MAAM,IAAIC,cAAc,CAACC,wBAAwB,EAAE,uDAAuD,CAAC;AAC7G,EAAA;AAEAN,EAAAA,SAAS,CAACO,IAAI,CAAIN,KAAK,CAACO,EAA0B,CAAC,CAACC,eAAe,CAACR,KAAK,CAACS,KAAU,CAAC;AACvF;;;;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { bindingScopeValues } from 'inversify';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Binds a constant value to a token in the container.
|
|
5
|
-
*
|
|
6
|
-
* @param container - target Inversify container
|
|
7
|
-
* @param entry - descriptor of entry to bind
|
|
8
|
-
*/
|
|
9
|
-
function bindDynamicValue(container, entry) {
|
|
10
|
-
var binding = container.bind(entry.id).toDynamicValue(function () {
|
|
11
|
-
if (entry.factory) {
|
|
12
|
-
return entry.factory();
|
|
13
|
-
}
|
|
14
|
-
return entry.value;
|
|
15
|
-
});
|
|
16
|
-
if (!entry.scopeBindingType) {
|
|
17
|
-
return;
|
|
18
|
-
} else if (entry.scopeBindingType === bindingScopeValues.Transient) {
|
|
19
|
-
binding.inTransientScope();
|
|
20
|
-
} else if (entry.scopeBindingType === bindingScopeValues.Request) {
|
|
21
|
-
binding.inRequestScope();
|
|
22
|
-
} else {
|
|
23
|
-
binding.inSingletonScope();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export { bindDynamicValue };
|
|
28
|
-
//# sourceMappingURL=bind-dynamic-value.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bind-dynamic-value.js","sources":["../../../../../../../../../src/wirestate-core/bind/bind-dynamic-value.ts"],"sourcesContent":[null],"names":["bindDynamicValue","container","entry","binding","bind","id","toDynamicValue","factory","value","scopeBindingType","bindingScopeValues","Transient","inTransientScope","Request","inRequestScope","inSingletonScope"],"mappings":";;AAOA;;;;;AAKG;AACG,SAAUA,gBAAgBA,CAACC,SAAoB,EAAEC,KAA4B,EAAA;AAMjF,EAAA,IAAMC,OAAO,GAAsCF,SAAS,CAACG,IAAI,CAACF,KAAK,CAACG,EAAE,CAAC,CAACC,cAAc,CAAC,YAAA;IACzF,IAAIJ,KAAK,CAACK,OAAO,EAAE;AACjB,MAAA,OAAOL,KAAK,CAACK,OAAO,EAAE;AACxB,IAAA;IAEA,OAAOL,KAAK,CAACM,KAAK;AACpB,EAAA,CAAC,CAAC;AAEF,EAAA,IAAI,CAACN,KAAK,CAACO,gBAAgB,EAAE;AAC3B,IAAA;EACF,CAAC,MAAM,IAAIP,KAAK,CAACO,gBAAgB,KAAKC,kBAAkB,CAACC,SAAS,EAAE;IAClER,OAAO,CAACS,gBAAgB,EAAE;EAC5B,CAAC,MAAM,IAAIV,KAAK,CAACO,gBAAgB,KAAKC,kBAAkB,CAACG,OAAO,EAAE;IAChEV,OAAO,CAACW,cAAc,EAAE;AAC1B,EAAA,CAAC,MAAM;IACLX,OAAO,CAACY,gBAAgB,EAAE;AAC5B,EAAA;AACF;;;;"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { bindingTypeValues } from 'inversify';
|
|
2
|
-
import { bindConstant } from './bind-constant.js';
|
|
3
|
-
import { bindDynamicValue } from './bind-dynamic-value.js';
|
|
4
|
-
import { bindService } from './bind-service.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Binds a single service entry to the container, dispatching to the
|
|
8
|
-
* correct binding strategy based on the descriptor's `type` field.
|
|
9
|
-
*
|
|
10
|
-
* Supports:
|
|
11
|
-
* - Service classes (function entries) - bound as singleton
|
|
12
|
-
* - Constant values - bound via `bindConstant`
|
|
13
|
-
* - Dynamic values - bound via `toDynamicValue` with optional scope
|
|
14
|
-
* - Instance bindings - bound as generic singleton service
|
|
15
|
-
*
|
|
16
|
-
* @param container - target IOC container to bind into
|
|
17
|
-
* @param entry - entry descriptor to bind
|
|
18
|
-
* @param options - optional binding configuration
|
|
19
|
-
* @returns void
|
|
20
|
-
*/
|
|
21
|
-
function bindEntry(container, entry, options) {
|
|
22
|
-
if (options === void 0) {
|
|
23
|
-
options = {};
|
|
24
|
-
}
|
|
25
|
-
if (typeof entry === "function") {
|
|
26
|
-
return bindService(container, entry, options);
|
|
27
|
-
}
|
|
28
|
-
if (!entry.bindingType || entry.bindingType === bindingTypeValues.ConstantValue) {
|
|
29
|
-
return bindConstant(container, entry);
|
|
30
|
-
}
|
|
31
|
-
if (entry.bindingType === bindingTypeValues.DynamicValue) {
|
|
32
|
-
return bindDynamicValue(container, entry);
|
|
33
|
-
}
|
|
34
|
-
// Default: treat as class descriptor (Instance binding).
|
|
35
|
-
return bindService(container, entry.value, options);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { bindEntry };
|
|
39
|
-
//# sourceMappingURL=bind-entry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bind-entry.js","sources":["../../../../../../../../../src/wirestate-core/bind/bind-entry.ts"],"sourcesContent":[null],"names":["bindEntry","container","entry","options","bindService","bindingType","bindingTypeValues","ConstantValue","bindConstant","DynamicValue","bindDynamicValue","value"],"mappings":";;;;;AAiBA;;;;;;;;;;;;;;AAcG;SACaA,SAASA,CACvBC,SAAoB,EACpBC,KAAyC,EACzCC,OAA+B,EAAA;AAA/B,EAAA,IAAAA,OAAA,KAAA,MAAA,EAAA;IAAAA,OAAA,GAAA,EAA+B;AAAA,EAAA;AAE/B,EAAA,IAAI,OAAOD,KAAK,KAAK,UAAU,EAAE;AAC/B,IAAA,OAAOE,WAAW,CAACH,SAAS,EAAEC,KAAK,EAAEC,OAAO,CAAC;AAC/C,EAAA;AAEA,EAAA,IAAI,CAACD,KAAK,CAACG,WAAW,IAAIH,KAAK,CAACG,WAAW,KAAKC,iBAAiB,CAACC,aAAa,EAAE;AAC/E,IAAA,OAAOC,YAAY,CAACP,SAAS,EAAEC,KAAK,CAAC;AACvC,EAAA;AAEA,EAAA,IAAIA,KAAK,CAACG,WAAW,KAAKC,iBAAiB,CAACG,YAAY,EAAE;AAMxD,IAAA,OAAOC,gBAAgB,CAACT,SAAS,EAAEC,KAAK,CAAC;AAC3C,EAAA;AAOA;EACA,OAAOE,WAAW,CAACH,SAAS,EAAEC,KAAK,CAACS,KAA8B,EAAER,OAAO,CAAC;AAC9E;;;;"}
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
import { CommandBus } from '../commands/command-bus.js';
|
|
2
|
-
import { getCommandHandlerMetadata } from '../commands/get-command-handler-metadata.js';
|
|
3
|
-
import { WireScope } from '../container/wire-scope.js';
|
|
4
|
-
import { buildEventDispatcher } from '../events/build-event-dispatcher.js';
|
|
5
|
-
import { EventBus } from '../events/event-bus.js';
|
|
6
|
-
import { getQueryHandlerMetadata } from '../queries/get-query-handler-metadata.js';
|
|
7
|
-
import { QueryBus } from '../queries/query-bus.js';
|
|
8
|
-
import { CONTAINER_REFS_BY_SERVICE, WIRE_SCOPES_BY_SERVICE, EVENT_UNSUBSCRIBERS_BY_SERVICE, QUERY_UNREGISTERS_BY_SERVICE, COMMAND_UNREGISTERS_BY_SERVICE } from '../registry.js';
|
|
9
|
-
import { getActivatedHandlerMetadata } from '../service/get-activated-handler-metadata.js';
|
|
10
|
-
import { getDeactivationHandlerMetadata } from '../service/get-deactivation-handler-metadata.js';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Registers a service class in the container with activation/deactivation logic.
|
|
14
|
-
* Ensures container references, event subscriptions, command and query handlers are managed correctly.
|
|
15
|
-
*
|
|
16
|
-
* @param container - target Inversify container
|
|
17
|
-
* @param entry - service constructor
|
|
18
|
-
* @param options - options object to control binding flow
|
|
19
|
-
*/
|
|
20
|
-
function bindService(container, entry, options) {
|
|
21
|
-
// Inversify's fluent binding API only allows a single `.onActivation` /
|
|
22
|
-
// `.onDeactivation` call per chain, so we register them on the container
|
|
23
|
-
// itself instead — this also works correctly if a later call rebinds the
|
|
24
|
-
// same token.
|
|
25
|
-
var whenBind = container.bind(entry).to(entry).inSingletonScope();
|
|
26
|
-
whenBind.onActivation(function (context, instance) {
|
|
27
|
-
// Ensure flag is initialized on activation.
|
|
28
|
-
instance.IS_DISPOSED = false;
|
|
29
|
-
CONTAINER_REFS_BY_SERVICE.set(instance, container);
|
|
30
|
-
attachWireScopes(instance, entry);
|
|
31
|
-
// Compose all events listeners into a single bus subscription so we only
|
|
32
|
-
// pay one Set lookup per emitted event.
|
|
33
|
-
var dispatcher = buildEventDispatcher(instance);
|
|
34
|
-
if (dispatcher) {
|
|
35
|
-
attachEventsSubscription(instance, dispatcher);
|
|
36
|
-
}
|
|
37
|
-
// Register every `@OnQuery` handler on the container's QueryBus, and
|
|
38
|
-
// remember the unregister functions so we can roll them back when the
|
|
39
|
-
// service is deactivated.
|
|
40
|
-
var queryBus = container.get(QueryBus);
|
|
41
|
-
for (var _i = 0, _a = getQueryHandlerMetadata(instance); _i < _a.length; _i++) {
|
|
42
|
-
var meta = _a[_i];
|
|
43
|
-
var method = instance[meta.methodName];
|
|
44
|
-
if (typeof method !== "function") {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
var unregister = queryBus.register(meta.type, method.bind(instance));
|
|
48
|
-
attachQueryUnregister(instance, unregister);
|
|
49
|
-
}
|
|
50
|
-
// Register every `@OnCommand` handler on the container's CommandBus, and
|
|
51
|
-
// remember the unregister functions so we can roll them back when the
|
|
52
|
-
// service is deactivated.
|
|
53
|
-
var commandBus = container.get(CommandBus);
|
|
54
|
-
for (var _b = 0, _c = getCommandHandlerMetadata(instance); _b < _c.length; _b++) {
|
|
55
|
-
var meta = _c[_b];
|
|
56
|
-
var method = instance[meta.methodName];
|
|
57
|
-
if (typeof method !== "function") {
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
var unregister = commandBus.register(meta.type, method.bind(instance));
|
|
61
|
-
attachCommandUnregister(instance, unregister);
|
|
62
|
-
}
|
|
63
|
-
if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
|
|
64
|
-
var _loop_1 = function (methodName) {
|
|
65
|
-
var method = instance[methodName];
|
|
66
|
-
if (typeof method !== "function") {
|
|
67
|
-
return "continue";
|
|
68
|
-
}
|
|
69
|
-
var result = method.call(instance);
|
|
70
|
-
if (result && typeof result.then === "function") {
|
|
71
|
-
result.catch(function (error) {
|
|
72
|
-
console.error("[wirestate] @OnActivated rejected for:", entry.name, String(methodName), error);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
// Call every `@OnActivated`-decorated method in base-to-derived order.
|
|
77
|
-
// Fire-and-forget any async init so we stay synchronous from the
|
|
78
|
-
// container's point of view.
|
|
79
|
-
for (var _d = 0, _e = getActivatedHandlerMetadata(instance); _d < _e.length; _d++) {
|
|
80
|
-
var methodName = _e[_d];
|
|
81
|
-
_loop_1(methodName);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return instance;
|
|
85
|
-
});
|
|
86
|
-
whenBind.onDeactivation(function (instance) {
|
|
87
|
-
if (options === null || options === void 0 ? void 0 : options.isWithIgnoreLifecycle) ; else {
|
|
88
|
-
// Call every `@OnDeactivation`-decorated method in base-to-derived order.
|
|
89
|
-
for (var _i = 0, _a = getDeactivationHandlerMetadata(instance); _i < _a.length; _i++) {
|
|
90
|
-
var methodName = _a[_i];
|
|
91
|
-
var method = instance[methodName];
|
|
92
|
-
if (typeof method === "function") {
|
|
93
|
-
method.call(instance);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// Flip the public disposal flag first so any async work already in
|
|
98
|
-
// flight (fetches awaiting in @Action methods, scheduled reactions,
|
|
99
|
-
// etc.) can short-circuit before it mutates the about-to-die instance.
|
|
100
|
-
// The cast is the only write-site for this `readonly` field.
|
|
101
|
-
instance.IS_DISPOSED = true;
|
|
102
|
-
detachWireScopes(instance);
|
|
103
|
-
detachCommandUnregister(instance);
|
|
104
|
-
detachQueryUnregister(instance);
|
|
105
|
-
detachEventSubscription(instance);
|
|
106
|
-
CONTAINER_REFS_BY_SERVICE.delete(instance);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Attaches a event subscription to a service.
|
|
111
|
-
*
|
|
112
|
-
* @param service - service instance
|
|
113
|
-
* @param handler - event handler
|
|
114
|
-
* @internal
|
|
115
|
-
*/
|
|
116
|
-
function attachEventsSubscription(service, handler) {
|
|
117
|
-
var _a;
|
|
118
|
-
var bus = (_a = CONTAINER_REFS_BY_SERVICE.get(service)) === null || _a === void 0 ? void 0 : _a.get(EventBus);
|
|
119
|
-
if (bus) {
|
|
120
|
-
EVENT_UNSUBSCRIBERS_BY_SERVICE.set(service, bus.subscribe(handler));
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Detaches the event subscription from a service.
|
|
125
|
-
*
|
|
126
|
-
* @param service - service instance
|
|
127
|
-
* @internal
|
|
128
|
-
*/
|
|
129
|
-
function detachEventSubscription(service) {
|
|
130
|
-
var unsubscribe = EVENT_UNSUBSCRIBERS_BY_SERVICE.get(service);
|
|
131
|
-
if (unsubscribe) {
|
|
132
|
-
unsubscribe();
|
|
133
|
-
EVENT_UNSUBSCRIBERS_BY_SERVICE.delete(service);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Registers a query unregister function for a service.
|
|
138
|
-
*
|
|
139
|
-
* @param service - service instance
|
|
140
|
-
* @param unregister - query unregister function
|
|
141
|
-
* @internal
|
|
142
|
-
*/
|
|
143
|
-
function attachQueryUnregister(service, unregister) {
|
|
144
|
-
var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
145
|
-
if (!list) {
|
|
146
|
-
list = [];
|
|
147
|
-
QUERY_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
148
|
-
}
|
|
149
|
-
list.push(unregister);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Executes and removes all query unregister functions for a service.
|
|
153
|
-
*
|
|
154
|
-
* @param service - service instance
|
|
155
|
-
* @internal
|
|
156
|
-
*/
|
|
157
|
-
function detachQueryUnregister(service) {
|
|
158
|
-
var list = QUERY_UNREGISTERS_BY_SERVICE.get(service);
|
|
159
|
-
if (!list) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
for (var _i = 0, list_1 = list; _i < list_1.length; _i++) {
|
|
163
|
-
var unregister = list_1[_i];
|
|
164
|
-
unregister();
|
|
165
|
-
}
|
|
166
|
-
QUERY_UNREGISTERS_BY_SERVICE.delete(service);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Registers a command unregister function for a service.
|
|
170
|
-
*
|
|
171
|
-
* @param service - service instance
|
|
172
|
-
* @param unregister - command unregister function
|
|
173
|
-
* @internal
|
|
174
|
-
*/
|
|
175
|
-
function attachCommandUnregister(service, unregister) {
|
|
176
|
-
var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
177
|
-
if (!list) {
|
|
178
|
-
list = [];
|
|
179
|
-
COMMAND_UNREGISTERS_BY_SERVICE.set(service, list);
|
|
180
|
-
}
|
|
181
|
-
list.push(unregister);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Executes and removes all command unregister functions for a service.
|
|
185
|
-
*
|
|
186
|
-
* @param service - service instance
|
|
187
|
-
* @internal
|
|
188
|
-
*/
|
|
189
|
-
function detachCommandUnregister(service) {
|
|
190
|
-
var list = COMMAND_UNREGISTERS_BY_SERVICE.get(service);
|
|
191
|
-
if (!list) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
for (var _i = 0, list_2 = list; _i < list_2.length; _i++) {
|
|
195
|
-
var unregister = list_2[_i];
|
|
196
|
-
unregister();
|
|
197
|
-
}
|
|
198
|
-
COMMAND_UNREGISTERS_BY_SERVICE.delete(service);
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Reads `design:paramtypes` from the service constructor to find parameters typed as WireScope.
|
|
202
|
-
* Property iteration happens only when the constructor metadata declares a WireScope
|
|
203
|
-
* parameter, avoiding false positives from manually created or subclassed scopes.
|
|
204
|
-
*
|
|
205
|
-
* todo: Simplify this part.
|
|
206
|
-
*
|
|
207
|
-
* @param service - service instance
|
|
208
|
-
* @param Service - service constructor
|
|
209
|
-
* @internal
|
|
210
|
-
*/
|
|
211
|
-
function attachWireScopes(service, Service) {
|
|
212
|
-
var paramTypes = Reflect.getMetadata("design:paramtypes", Service);
|
|
213
|
-
if (!(paramTypes === null || paramTypes === void 0 ? void 0 : paramTypes.some(function (type) {
|
|
214
|
-
return type === WireScope;
|
|
215
|
-
}))) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
var scopes = [];
|
|
219
|
-
for (var _i = 0, _a = Object.getOwnPropertyNames(service); _i < _a.length; _i++) {
|
|
220
|
-
var key = _a[_i];
|
|
221
|
-
var value = service[key];
|
|
222
|
-
if ((value === null || value === void 0 ? void 0 : value.constructor) === WireScope) {
|
|
223
|
-
scopes.push(value);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
if (scopes.length > 0) {
|
|
227
|
-
WIRE_SCOPES_BY_SERVICE.set(service, scopes);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Marks all injected WireScope instances for this service as disposed and removes
|
|
232
|
-
* the stored references.
|
|
233
|
-
*
|
|
234
|
-
* todo: Simplify this part.
|
|
235
|
-
*
|
|
236
|
-
* @param service - service instance
|
|
237
|
-
* @internal
|
|
238
|
-
*/
|
|
239
|
-
function detachWireScopes(service) {
|
|
240
|
-
var scopes = WIRE_SCOPES_BY_SERVICE.get(service);
|
|
241
|
-
if (!scopes) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
for (var _i = 0, scopes_1 = scopes; _i < scopes_1.length; _i++) {
|
|
245
|
-
var scope = scopes_1[_i];
|
|
246
|
-
scope.isDisposed = true;
|
|
247
|
-
scope.container = null;
|
|
248
|
-
}
|
|
249
|
-
WIRE_SCOPES_BY_SERVICE.delete(service);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
export { bindService };
|
|
253
|
-
//# sourceMappingURL=bind-service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bind-service.js","sources":["../../../../../../../../../src/wirestate-core/bind/bind-service.ts"],"sourcesContent":[null],"names":["bindService","container","entry","options","whenBind","bind","to","inSingletonScope","onActivation","context","instance","IS_DISPOSED","CONTAINER_REFS_BY_SERVICE","set","attachWireScopes","dispatcher","buildEventDispatcher","attachEventsSubscription","queryBus","get","QueryBus","_i","_a","getQueryHandlerMetadata","length","meta","method","methodName","unregister","register","type","attachQueryUnregister","commandBus","CommandBus","_b","_c","getCommandHandlerMetadata","attachCommandUnregister","isWithIgnoreLifecycle","result","call","then","catch","error","console","name","String","_d","_e","getActivatedHandlerMetadata","onDeactivation","getDeactivationHandlerMetadata","detachWireScopes","detachCommandUnregister","detachQueryUnregister","detachEventSubscription","delete","service","handler","bus","EventBus","EVENT_UNSUBSCRIBERS_BY_SERVICE","subscribe","unsubscribe","list","QUERY_UNREGISTERS_BY_SERVICE","push","list_1","COMMAND_UNREGISTERS_BY_SERVICE","list_2","Service","paramTypes","Reflect","getMetadata","some","WireScope","scopes","Object","getOwnPropertyNames","key","value","constructor","WIRE_SCOPES_BY_SERVICE","scopes_1","scope","isDisposed"],"mappings":";;;;;;;;;;;AA8BA;;;;;;;AAOG;SACaA,WAAWA,CACzBC,SAAoB,EACpBC,KAAiB,EACjBC,OAA6B,EAAA;AAS7B;AACA;AACA;AACA;AACA,EAAA,IAAMC,QAAQ,GAA8BH,SAAS,CAACI,IAAI,CAAIH,KAAK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CAACC,UAAU,GAAG,IAAI;IACnDD,KAAuD,CAACnF,SAAS,GAAG,IAAI;AAC3E,EAAA;AAEAiF,EAAAA,sBAAsB,CAAC1B,MAAM,CAACC,OAAO,CAAC;AACxC;;;;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the container token for a service entry.
|
|
3
|
-
* For plain service classes the class itself is the token;
|
|
4
|
-
* for descriptors the `id` field is used.
|
|
5
|
-
*
|
|
6
|
-
* @param entry - entry descriptor to get service identifier for
|
|
7
|
-
* @returns injectable identifier token
|
|
8
|
-
*/
|
|
9
|
-
function getEntryToken(entry) {
|
|
10
|
-
return typeof entry === "function" ? entry : entry.id;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { getEntryToken };
|
|
14
|
-
//# sourceMappingURL=get-entry-token.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-entry-token.js","sources":["../../../../../../../../../src/wirestate-core/bind/get-entry-token.ts"],"sourcesContent":[null],"names":["getEntryToken","entry","id"],"mappings":"AAIA;;;;;;;AAOG;AACG,SAAUA,aAAaA,CAA4BC,KAAyC,EAAA;EAChG,OAAO,OAAOA,KAAK,KAAK,UAAU,GAAGA,KAAK,GAAGA,KAAK,CAACC,EAAE;AACvD;;;;"}
|
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER } from '../error/error-code.js';
|
|
2
|
-
import { WirestateError } from '../error/wirestate-error.js';
|
|
3
|
-
import { ECommandStatus } from '../types/commands.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Dispatches commands to handlers.
|
|
7
|
-
*
|
|
8
|
-
* Unlike queries, command execution always wraps the handler in a promise
|
|
9
|
-
* and returns a descriptor with task, status, and responder.
|
|
10
|
-
*/
|
|
11
|
-
var CommandBus = /** @class */function () {
|
|
12
|
-
function CommandBus() {
|
|
13
|
-
/**
|
|
14
|
-
* Internal handler storage.
|
|
15
|
-
* Uses a stack for each command type to support shadowing.
|
|
16
|
-
*/
|
|
17
|
-
this.handlers = new Map();
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Registers a command handler.
|
|
21
|
-
* Returns an unregister function.
|
|
22
|
-
*
|
|
23
|
-
* @param type - command type
|
|
24
|
-
* @param handler - handler function
|
|
25
|
-
* @returns unregister function
|
|
26
|
-
*/
|
|
27
|
-
CommandBus.prototype.register = function (type, handler) {
|
|
28
|
-
var _this = this;
|
|
29
|
-
var stack = this.handlers.get(type);
|
|
30
|
-
if (!stack) {
|
|
31
|
-
stack = [];
|
|
32
|
-
this.handlers.set(type, stack);
|
|
33
|
-
}
|
|
34
|
-
stack.push(handler);
|
|
35
|
-
return function () {
|
|
36
|
-
var current = _this.handlers.get(type);
|
|
37
|
-
if (!current) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
var index = current.indexOf(handler);
|
|
41
|
-
if (index >= 0) {
|
|
42
|
-
current.splice(index, 1);
|
|
43
|
-
}
|
|
44
|
-
// Clean empty stacks.
|
|
45
|
-
if (current.length === 0) {
|
|
46
|
-
_this.handlers.delete(type);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Dispatches a command to the last registered handler.
|
|
52
|
-
* Wraps the handler execution in a promise and returns a descriptor.
|
|
53
|
-
*
|
|
54
|
-
* @param type - command type
|
|
55
|
-
* @param data - command payload
|
|
56
|
-
* @returns command descriptor with task, status, and responder
|
|
57
|
-
*
|
|
58
|
-
* @throws if no handler is registered
|
|
59
|
-
*/
|
|
60
|
-
CommandBus.prototype.command = function (type, data) {
|
|
61
|
-
var stack = this.handlers.get(type);
|
|
62
|
-
if (!(stack === null || stack === void 0 ? void 0 : stack.length)) {
|
|
63
|
-
throw new WirestateError(ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER, "No command handler registered in container for type: '".concat(String(type), "'."));
|
|
64
|
-
}
|
|
65
|
-
var handler = stack[stack.length - 1];
|
|
66
|
-
var descriptor = {
|
|
67
|
-
task: null,
|
|
68
|
-
status: ECommandStatus.PENDING
|
|
69
|
-
};
|
|
70
|
-
descriptor.task = Promise.resolve().then(function () {
|
|
71
|
-
return handler(data);
|
|
72
|
-
}).then(function (result) {
|
|
73
|
-
descriptor.status = ECommandStatus.SETTLED;
|
|
74
|
-
return result;
|
|
75
|
-
}).catch(function (error) {
|
|
76
|
-
descriptor.status = ECommandStatus.ERROR;
|
|
77
|
-
throw error;
|
|
78
|
-
});
|
|
79
|
-
return descriptor;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* Dispatches a command to the last registered handler, returning null if no handler exists.
|
|
83
|
-
*
|
|
84
|
-
* @param type - command type
|
|
85
|
-
* @param data - command payload
|
|
86
|
-
* @returns command descriptor or null if no handler is registered
|
|
87
|
-
*/
|
|
88
|
-
CommandBus.prototype.commandOptional = function (type, data) {
|
|
89
|
-
var stack = this.handlers.get(type);
|
|
90
|
-
return (stack === null || stack === void 0 ? void 0 : stack.length) ? this.command(type, data) : null;
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Checks if a handler is registered for the given type.
|
|
94
|
-
*
|
|
95
|
-
* @param type - command type
|
|
96
|
-
* @returns true if handler exists
|
|
97
|
-
*/
|
|
98
|
-
CommandBus.prototype.has = function (type) {
|
|
99
|
-
var _a;
|
|
100
|
-
return Boolean((_a = this.handlers.get(type)) === null || _a === void 0 ? void 0 : _a.length);
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Removes all registered handlers.
|
|
104
|
-
*/
|
|
105
|
-
CommandBus.prototype.clear = function () {
|
|
106
|
-
this.handlers.clear();
|
|
107
|
-
};
|
|
108
|
-
return CommandBus;
|
|
109
|
-
}();
|
|
110
|
-
|
|
111
|
-
export { CommandBus };
|
|
112
|
-
//# sourceMappingURL=command-bus.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-bus.js","sources":["../../../../../../../../../src/wirestate-core/commands/command-bus.ts"],"sourcesContent":[null],"names":["CommandBus","handlers","Map","prototype","register","type","handler","_this","stack","get","set","push","current","index","indexOf","splice","length","delete","command","data","WirestateError","ERROR_CODE_FAILED_TO_RESOLVE_COMMAND_HANDLER","concat","String","descriptor","task","status","ECommandStatus","PENDING","Promise","resolve","then","result","SETTLED","catch","error","ERROR","commandOptional","has","Boolean","_a","clear"],"mappings":";;;;AAcA;;;;;AAKG;AACH,IAAAA,UAAA,gBAAA,YAAA;EAAA,SAAAA,UAAAA,GAAA;AACE;;;AAGG;AACc,IAAA,IAAA,CAAAC,QAAQ,GAA8C,IAAIC,GAAG,EAAE;AA4HlF,EAAA;AA1HE;;;;;;;AAOG;EACIF,UAAA,CAAAG,SAAA,CAAAC,QAAQ,GAAf,UAA0CC,IAAkB,EAAEC,OAA8B,EAAA;IAA5F,IAAAC,KAAA,GAAA,IAAA;IAOE,IAAIC,KAAK,GAAkC,IAAI,CAACP,QAAQ,CAACQ,GAAG,CAACJ,IAAI,CAAC;IAElE,IAAI,CAACG,KAAK,EAAE;AACVA,MAAAA,KAAK,GAAG,EAAE;MACV,IAAI,CAACP,QAAQ,CAACS,GAAG,CAACL,IAAI,EAAEG,KAAK,CAAC;AAChC,IAAA;AAEAA,IAAAA,KAAK,CAACG,IAAI,CAACL,OAA0B,CAAC;AAEtC,IAAA,OAAO,YAAA;MAOL,IAAMM,OAAO,GAAkCL,KAAI,CAACN,QAAQ,CAACQ,GAAG,CAACJ,IAAI,CAAC;MAEtE,IAAI,CAACO,OAAO,EAAE;AACZ,QAAA;AACF,MAAA;AAEA,MAAA,IAAMC,KAAK,GAAWD,OAAO,CAACE,OAAO,CAACR,OAA0B,CAAC;MAEjE,IAAIO,KAAK,IAAI,CAAC,EAAE;AACdD,QAAAA,OAAO,CAACG,MAAM,CAACF,KAAK,EAAE,CAAC,CAAC;AAC1B,MAAA;AAEA;AACA,MAAA,IA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