Skip to content

Commit cbb45ae

Browse files
committed
perf(command-flow): remove dependency on ts-pattern
1 parent 40f858a commit cbb45ae

4 files changed

Lines changed: 21 additions & 21 deletions

File tree

package-lock.json

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
"rxfire": "^6.0.5",
6161
"rxjs": "~7.8.0",
6262
"simple-git": "^3.27.0",
63-
"ts-pattern": "^5.2.0",
6463
"tslib": "^2.3.0",
6564
"type-container": "^1.0.1",
6665
"typescript": "5.8.3",

packages/command-flow/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"@angular/common": ">=19",
88
"@angular/core": ">=19",
99
"@angularity/command-flow": "*",
10-
"@angularity/core": "20.0.0",
11-
"rxjs": ">=7",
12-
"ts-pattern": ">=5"
10+
"@angularity/core": "*",
11+
"rxjs": ">=7"
1312
},
1413
"dependencies": {
1514
"tslib": "2.x.x"

packages/command-flow/process-flow/src/handler.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import {
77
from,
88
mergeMap,
99
Observable,
10+
ObservableInput,
11+
ObservedValueOf,
12+
OperatorFunction,
1013
pipe,
1114
switchMap,
1215
} from 'rxjs';
13-
import { match } from 'ts-pattern';
1416

1517
import { Process } from './core';
1618
import {
@@ -69,6 +71,18 @@ export enum ProcessSchedulingStrategy {
6971
Blocking,
7072
}
7173

74+
const SCHEDULERS: Record<
75+
ProcessSchedulingStrategy,
76+
<T, O extends ObservableInput<any>>(
77+
project: (value: T) => O,
78+
) => OperatorFunction<T, ObservedValueOf<O>>
79+
> = {
80+
[ProcessSchedulingStrategy.Sequential]: concatMap,
81+
[ProcessSchedulingStrategy.Concurrent]: mergeMap,
82+
[ProcessSchedulingStrategy.Preemptive]: switchMap,
83+
[ProcessSchedulingStrategy.Blocking]: exhaustMap,
84+
};
85+
7286
/**
7387
* Register a `ProcessHandler` for some types of processes
7488
* within the current injection context.
@@ -120,12 +134,8 @@ export function onProcess<Types extends Type<Process<any>>[]>(
120134
): void {
121135
const injector = inject(Injector);
122136

123-
const scheduler = match(scheduling)
124-
.with(ProcessSchedulingStrategy.Sequential, () => concatMap)
125-
.with(ProcessSchedulingStrategy.Concurrent, () => mergeMap)
126-
.with(ProcessSchedulingStrategy.Preemptive, () => switchMap)
127-
.with(ProcessSchedulingStrategy.Blocking, () => exhaustMap)
128-
.run();
137+
const scheduler = SCHEDULERS[scheduling];
138+
if (!scheduler) throw new Error(`Invalid scheduling strategy: ${scheduling}`);
129139

130140
onCommand(
131141
types,

0 commit comments

Comments
 (0)