From f57d06468d64f3bb4f65aefd5c110772c29a8365 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Tue, 28 Nov 2023 22:47:33 -0500 Subject: [PATCH] Removes unneeded @gate call unneeded custom resolver --- src/system/decorators/resolver.ts | 42 ++++++++++------------- src/views/nodes/abstract/subscribeableViewNode.ts | 1 - src/views/nodes/abstract/viewNode.ts | 2 +- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/system/decorators/resolver.ts b/src/system/decorators/resolver.ts index 7f9a7e9..fcf2a95 100644 --- a/src/system/decorators/resolver.ts +++ b/src/system/decorators/resolver.ts @@ -6,15 +6,12 @@ import { isTag } from '../../git/models/tag'; import { isViewNode } from '../../views/nodes/abstract/viewNode'; function replacer(key: string, value: any): any { - if (key === '') return value; - - if (value == null) return value; - if (typeof value !== 'object') return value; + if (key === '' || value == null || typeof value !== 'object') return value; if (value instanceof Error) return String(value); if (value instanceof Uri) { - if ('sha' in (value as any) && (value as any).sha) { - return `${(value as any).sha}:${value.toString()}`; + if ('sha' in value && typeof value.sha === 'string' && value.sha) { + return `${value.sha}:${value.toString()}`; } return value.toString(); } @@ -28,37 +25,36 @@ function replacer(key: string, value: any): any { export function defaultResolver(...args: any[]): string { if (args.length === 0) return ''; - if (args.length !== 1) { - return JSON.stringify(args, replacer); - } + if (args.length > 1) return JSON.stringify(args, replacer); + + const [arg] = args; + if (arg == null) return ''; - const arg0 = args[0]; - if (arg0 == null) return ''; - switch (typeof arg0) { + switch (typeof arg) { case 'string': - return arg0; + return arg; case 'number': case 'boolean': case 'undefined': case 'symbol': case 'bigint': - return String(arg0); + return String(arg); default: - if (arg0 instanceof Error) return String(arg0); - if (arg0 instanceof Uri) { - if ('sha' in arg0 && typeof arg0.sha === 'string' && arg0.sha) { - return `${arg0.sha}:${arg0.toString()}`; + if (arg instanceof Error) return String(arg); + if (arg instanceof Uri) { + if ('sha' in arg && typeof arg.sha === 'string' && arg.sha) { + return `${arg.sha}:${arg.toString()}`; } - return arg0.toString(); + return arg.toString(); } - if (isBranch(arg0) || isCommit(arg0) || isTag(arg0) || isViewNode(arg0)) { - return arg0.toString(); + if (isBranch(arg) || isCommit(arg) || isTag(arg) || isViewNode(arg)) { + return arg.toString(); } - if (isContainer(arg0)) return ''; + if (isContainer(arg)) return ''; - return JSON.stringify(arg0, replacer); + return JSON.stringify(arg, replacer); } } diff --git a/src/views/nodes/abstract/subscribeableViewNode.ts b/src/views/nodes/abstract/subscribeableViewNode.ts index 0399843..b727af5 100644 --- a/src/views/nodes/abstract/subscribeableViewNode.ts +++ b/src/views/nodes/abstract/subscribeableViewNode.ts @@ -57,7 +57,6 @@ export abstract class SubscribeableViewNode< this.disposable?.dispose(); } - @gate((reset, force) => `${reset}|${force}`) @debug() override async triggerChange(reset: boolean = false, force: boolean = false): Promise { if (!this.loaded || this._disposed) return; diff --git a/src/views/nodes/abstract/viewNode.ts b/src/views/nodes/abstract/viewNode.ts index 02179d1..1162085 100644 --- a/src/views/nodes/abstract/viewNode.ts +++ b/src/views/nodes/abstract/viewNode.ts @@ -285,7 +285,7 @@ export abstract class ViewNode< refresh?(reset?: boolean): boolean | void | Promise | Promise; - @gate((reset, force, avoidSelf) => `${reset}|${force}|${avoidSelf?.toString()}`) + @gate() @debug() triggerChange(reset: boolean = false, force: boolean = false, avoidSelf?: ViewNode): Promise { if (this._disposed) return Promise.resolve();