From b6a331ada7547e0dc6b1d290855c5fa7a2e3cda6 Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Sun, 3 Mar 2024 12:44:26 +0100 Subject: [PATCH 1/2] issue-56 paused methods resolver refactor method name is explicitly passed --- src/classes/adapter.ts | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/classes/adapter.ts b/src/classes/adapter.ts index d7798b25..b6f99187 100644 --- a/src/classes/adapter.ts +++ b/src/classes/adapter.ts @@ -120,16 +120,6 @@ export class Adapter implements IAdapter { private relax$: Reactive | null; private relaxRun: Promise | null; - private shouldIgnorePausedMethod(method: MethodResolver) { - const methodName = method.name as AdapterPropName; - return this.paused && !ALLOWED_METHODS_WHEN_PAUSED.includes(methodName); - } - - private getPausedMethodResult(method: MethodResolver) { - this.logger?.log?.(() => 'scroller is paused: ' + method.name + ' method is ignored'); - return Promise.resolve(methodPausedResult); - } - private getPromisifiedMethod(method: MethodResolver, args: unknown[]) { return new Promise(resolve => { if (this.relax$) { @@ -139,13 +129,19 @@ export class Adapter implements IAdapter { }); } - private getWorkflowRunnerMethod(method: MethodResolver, defaultMethod: MethodResolver) { - return (...args: unknown[]): Promise => - !this.relax$ - ? defaultMethod.apply(this, args) - : this.shouldIgnorePausedMethod(method) - ? this.getPausedMethodResult(method) - : this.getPromisifiedMethod(method, args); + private getWorkflowRunnerMethod(method: MethodResolver, name: AdapterPropName) { + return (...args: unknown[]): Promise => { + if (!this.relax$) { + this.logger?.log?.(() => 'scroller is not initialized: ' + name + ' method is ignored'); + return Promise.resolve(methodPreResult); + } + if (this.paused && !ALLOWED_METHODS_WHEN_PAUSED.includes(name)) { + this.logger?.log?.(() => 'scroller is paused: ' + name + ' method is ignored'); + return Promise.resolve(methodPausedResult); + + } + return this.getPromisifiedMethod(method, args); + }; } constructor(context: IAdapter | null, getWorkflow: WorkflowGetter, logger: Logger) { @@ -269,12 +265,12 @@ export class Adapter implements IAdapter { // Adapter public context augmentation adapterProps .forEach((prop: IAdapterProp) => { - const { name, type, value: defaultValue, permanent } = prop; + const { name, type, permanent } = prop; let value = (this as IAdapter)[name]; if (type === AdapterPropType.Function) { value = (value as () => void).bind(this); } else if (type === AdapterPropType.WorkflowRunner) { - value = this.getWorkflowRunnerMethod(value as MethodResolver, defaultValue as MethodResolver); + value = this.getWorkflowRunnerMethod(value as MethodResolver, name); } else if (type === AdapterPropType.Reactive && reactivePropsStore[name]) { value = (context as IAdapter)[name]; } else if (name === AdapterPropName.augmented) { From 02431c2ad4762bf5c6807d9df5191a80086065c9 Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Sun, 3 Mar 2024 12:44:46 +0100 Subject: [PATCH 2/2] v1.6.1 --- package-lock.json | 4 ++-- package.json | 2 +- src/version.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index cca72133..476024d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscroll", - "version": "1.6.0", + "version": "1.6.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscroll", - "version": "1.6.0", + "version": "1.6.1", "license": "MIT", "dependencies": { "tslib": "^2.3.1" diff --git a/package.json b/package.json index 6af0a7b4..f23f49f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vscroll", - "version": "1.6.0", + "version": "1.6.1", "description": "Virtual scroll engine", "main": "dist/bundles/vscroll.umd.js", "module": "dist/bundles/vscroll.esm5.js", diff --git a/src/version.ts b/src/version.ts index 90fd6bf8..434ab753 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,4 @@ export default { name: 'vscroll', - version: '1.6.0' + version: '1.6.1' };