File tree Expand file tree Collapse file tree
docs/src/content/packages/command-flow Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,6 +42,17 @@ Facade:
4242- ` useCommand `
4343 {{ JSDoc.description("packages/command-flow/src/index.ts#useCommand") }}
4444
45+ Flow:
46+
47+ - ` Flow `
48+ {{ JSDoc.description("packages/command-flow/src/flow.ts#Flow") }}
49+ - ` FlowEffect `
50+ {{ JSDoc.description("packages/command-flow/src/flow.ts#FlowEffect") }}
51+ - ` createFlow `
52+ {{ JSDoc.description("packages/command-flow/src/flow.ts#createFlow") }}
53+ - ` provideFlows `
54+ {{ JSDoc.description("packages/command-flow/src/flow.ts#provideFlows") }}
55+
4556### Exported from ` @angularity/command-flow/process-flow `
4657
4758Foundation:
Original file line number Diff line number Diff line change @@ -5,13 +5,15 @@ import {
55
66/**
77 * A function that registers side-effects (of commands/events).
8+ * @deprecated Use `createFlow` instead.
89 */
910export interface Effects {
1011 ( ) : void ;
1112}
1213
1314/**
1415 * Registers the provided effects in an environment initializer.
16+ * @deprecated Use `provideFlows` instead.
1517 */
1618export function provideEffects (
1719 ...effectsInput : ( Effects | Effects [ ] ) [ ]
Original file line number Diff line number Diff line change 1+ import {
2+ EnvironmentProviders ,
3+ inject ,
4+ Injector ,
5+ makeEnvironmentProviders ,
6+ provideEnvironmentInitializer ,
7+ runInInjectionContext ,
8+ } from '@angular/core' ;
9+
10+ /**
11+ * A collection of effects that are run in an injection context.
12+ */
13+ export interface Flow {
14+ effects : FlowEffect [ ] ;
15+ }
16+
17+ /**
18+ * A function that is run in an injection context and registers some side effects.
19+ */
20+ export interface FlowEffect {
21+ ( ) : void ;
22+ }
23+
24+ /**
25+ * Creates a `Flow` with the given `FlowEffect`s.
26+ * @example
27+ * ```ts
28+ * export const authFlow = createFlow(
29+ * () =>
30+ * onCommand(
31+ * [Alert],
32+ * map((payload) => {
33+ * window.alert(payload.message);
34+ * return AlertCompleted();
35+ * }),
36+ * ),
37+ * (confirm = inject(ConfirmService)) =>
38+ * onCommand(
39+ * [Confirm],
40+ * map((payload) => {
41+ * const result = confirm.launch(payload.message);
42+ * return ConfirmCompleted(result);
43+ * }),
44+ * ),
45+ * );
46+ * ```
47+ */
48+ export function createFlow ( ...effects : FlowEffect [ ] ) : Flow {
49+ return { effects } ;
50+ }
51+
52+ /**
53+ * Provides the given flows to an environment.
54+ */
55+ export function provideFlows ( ...flows : Flow [ ] ) : EnvironmentProviders {
56+ return makeEnvironmentProviders ( [
57+ provideEnvironmentInitializer ( ( ) => {
58+ const injector = inject ( Injector ) ;
59+ for ( const flow of flows )
60+ for ( const effect of flow . effects )
61+ runInInjectionContext ( injector , effect ) ;
62+ } ) ,
63+ ] ) ;
64+ }
You can’t perform that action at this time.
0 commit comments