Skip to content

Commit 7f838b9

Browse files
Update libs/hooks/debounce/src/lib/debounce-hook.ts
Co-authored-by: Lukas Reining <[email protected]> Signed-off-by: Todd Baert <[email protected]>
1 parent d29aec0 commit 7f838b9

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

libs/hooks/debounce/src/lib/debounce-hook.ts

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,33 +158,32 @@ export class DebounceHook<T extends FlagValue = FlagValue> implements Hook {
158158
// the cache key is a concatenation of the result of calling keyGenCallback and the stage
159159
const dynamicKey = keyGenCallback();
160160

161-
// if the keyGenCallback returns nothing, we don't do any caching
162-
if (dynamicKey) {
163-
const cacheKeySuffix = stage;
164-
const cacheKey = `${dynamicKey}::${cacheKeySuffix}`;
165-
const got = this.cache.get(cacheKey);
161+
// if the keyGenCallback returns nothing, we don't do any caching
162+
if (!dynamicKey) {
163+
hookCallback.call(this.innerHook);
164+
}
165+
166+
const cacheKeySuffix = stage;
167+
const cacheKey = `${dynamicKey}::${cacheKeySuffix}`;
168+
const got = this.cache.get(cacheKey);
166169

167-
if (got) {
168-
// throw cached errors
169-
if (got instanceof CachedError) {
170-
throw got;
171-
}
172-
return;
173-
} else {
174-
try {
175-
hookCallback.call(this.innerHook);
176-
this.cache.set(cacheKey, true);
177-
} catch (error: unknown) {
178-
if (this.cacheErrors) {
179-
// cache error
180-
this.cache.set(cacheKey, new CachedError(error));
181-
}
182-
throw error;
183-
}
184-
return;
170+
if (got) {
171+
// throw cached errors
172+
if (got instanceof CachedError) {
173+
throw got;
185174
}
186-
} else {
175+
return;
176+
}
177+
178+
try {
187179
hookCallback.call(this.innerHook);
188-
}
180+
this.cache.set(cacheKey, true);
181+
} catch (error: unknown) {
182+
if (this.cacheErrors) {
183+
// cache error
184+
this.cache.set(cacheKey, new CachedError(error));
185+
}
186+
throw error;
187+
}
189188
}
190189
}

0 commit comments

Comments
 (0)