Skip to content

Commit 108a0b6

Browse files
alan-agius4dgp1130
authored andcommitted
refactor(@angular-devkit/core): remove fast-json-stable-stringify usage in memoize helper
This is not needed as inputs are typed checked to be `JsonValue`. With this change we get a step closer to remove `fast-json-stable-stringify` dependency.
1 parent 607a723 commit 108a0b6

File tree

1 file changed

+14
-5
lines changed
  • packages/angular_devkit/core/src/experimental/jobs

1 file changed

+14
-5
lines changed

packages/angular_devkit/core/src/experimental/jobs/strategy.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import stableStringify from 'fast-json-stable-stringify';
109
import { Observable, Subject, concat, of } from 'rxjs';
1110
import { finalize, ignoreElements, share, shareReplay, tap } from 'rxjs/operators';
12-
import { JsonValue } from '../../json';
11+
import { JsonObject, JsonValue, isJsonObject } from '../../json';
1312
import {
1413
JobDescription,
1514
JobHandler,
@@ -60,7 +59,7 @@ export namespace strategy {
6059
/**
6160
* Creates a JobStrategy that will always reuse a running job, and restart it if the job ended.
6261
* @param replayMessages Replay ALL messages if a job is reused, otherwise just hook up where it
63-
* is.
62+
* is.
6463
*/
6564
export function reuse<
6665
A extends JsonValue = JsonValue,
@@ -115,7 +114,7 @@ export namespace strategy {
115114
/**
116115
* Creates a JobStrategy that will reuse a running job if the argument matches.
117116
* @param replayMessages Replay ALL messages if a job is reused, otherwise just hook up where it
118-
* is.
117+
* is.
119118
*/
120119
export function memoize<
121120
A extends JsonValue = JsonValue,
@@ -126,7 +125,17 @@ export namespace strategy {
126125

127126
return (handler, options) => {
128127
const newHandler = (argument: A, context: JobHandlerContext<A, I, O>) => {
129-
const argumentJson = stableStringify(argument);
128+
const argumentJson = JSON.stringify(
129+
isJsonObject(argument)
130+
? Object.keys(argument)
131+
.sort()
132+
.reduce((result, key) => {
133+
result[key] = argument[key];
134+
135+
return result;
136+
}, {} as JsonObject)
137+
: argument,
138+
);
130139
const maybeJob = runs.get(argumentJson);
131140

132141
if (maybeJob) {

0 commit comments

Comments
 (0)