From 63149487c80e209f926df60d84c239fc40388bcc Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Thu, 15 Jun 2023 01:46:21 +0200 Subject: [PATCH 1/4] issue-51 do not call the workflow before the scroll event listener is set The workflow can be disposed immediately after instantiation during the first "init" call. It means the context can be empty, so there must be no "this" instructions after the first "init" call. --- src/workflow.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/workflow.ts b/src/workflow.ts index 0053b340..52e9cea7 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -18,6 +18,7 @@ import { export class Workflow { isInitialized: boolean; + disposed: boolean; initTimer: ReturnType | null; adapterRun$: Reactive; cyclesDone: number; @@ -32,6 +33,7 @@ export class Workflow { constructor({ element, datasource, consumer, run, Routines }: WorkflowParams) { this.isInitialized = false; + this.disposed = false; this.initTimer = null; this.adapterRun$ = new Reactive(); this.cyclesDone = 0; @@ -62,13 +64,6 @@ export class Workflow { init(): void { this.scroller.init(this.adapterRun$); - this.isInitialized = true; - - // run the Workflow - this.callWorkflow({ - process: CommonProcess.init, - status: Status.start - }); // set up scroll event listener const { routines } = this.scroller; @@ -79,6 +74,13 @@ export class Workflow { payload: { event } }); this.offScroll = routines.onScroll(onScrollHandler); + + // run the Workflow + this.isInitialized = true; + this.callWorkflow({ + process: CommonProcess.init, + status: Status.start + }); } changeItems(items: Item[]): void { @@ -194,6 +196,7 @@ export class Workflow { Object.getOwnPropertyNames(this).forEach(prop => { delete (this as Record)[prop]; }); + this.disposed = true; } finalize(): void { From b33a585d2c88abdbe12163cfc8a5f405532e5307 Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Thu, 15 Jun 2023 01:52:56 +0200 Subject: [PATCH 2/4] issue-51 cannot access sub before initialization --- src/processes/fetch.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/processes/fetch.ts b/src/processes/fetch.ts index a922c5d9..9f1b6cd7 100644 --- a/src/processes/fetch.ts +++ b/src/processes/fetch.ts @@ -96,7 +96,8 @@ export default class Fetch extends BaseProcessFactory(CommonProcess.fetch) { if (typeof (getResult as PromiseLike).then === 'function') { return getResult as Promise; } else if (typeof (getResult as ObservableLike).subscribe === 'function') { - const sub = (getResult as ObservableLike).subscribe(done, fail, () => { + let sub: undefined | ReturnType = void 0; + sub = (getResult as ObservableLike).subscribe(done, fail, () => { if (sub && typeof sub === 'object' && typeof sub.unsubscribe === 'function') { sub.unsubscribe(); } From 37bf43fcc52d074f46976f9bbebc39eb6a3fca9d Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Fri, 16 Jun 2023 16:36:01 +0200 Subject: [PATCH 3/4] issue-51 workflow/scroller disposing log --- src/scroller.ts | 1 + src/workflow.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/scroller.ts b/src/scroller.ts index 1506abbe..fa8203e9 100644 --- a/src/scroller.ts +++ b/src/scroller.ts @@ -89,6 +89,7 @@ export class Scroller { } dispose(forever?: boolean): void { + this.logger.log(() => 'disposing scroller' + (forever ? ' (forever)' : '')); if (forever) { // Adapter is not re-instantiated on reset this.adapter.dispose(); } diff --git a/src/workflow.ts b/src/workflow.ts index 52e9cea7..9e31b41a 100644 --- a/src/workflow.ts +++ b/src/workflow.ts @@ -187,6 +187,7 @@ export class Workflow { } dispose(): void { + this.scroller.logger.log(() => 'disposing workflow'); if (this.initTimer) { clearTimeout(this.initTimer); } From f0b5c1782c5cde759af49c0e5fcbf6a7be74a63d Mon Sep 17 00:00:00 2001 From: Denis Hilt Date: Fri, 16 Jun 2023 16:36:45 +0200 Subject: [PATCH 4/4] v1.5.5 --- package-lock.json | 6 +++--- package.json | 2 +- src/version.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 022b158b..bf35e2c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscroll", - "version": "1.5.4", + "version": "1.5.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "vscroll", - "version": "1.5.4", + "version": "1.5.5", "license": "MIT", "dependencies": { "tslib": "^2.3.1" @@ -13893,4 +13893,4 @@ "dev": true } } -} +} \ No newline at end of file diff --git a/package.json b/package.json index d567c709..8f64d4ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vscroll", - "version": "1.5.4", + "version": "1.5.5", "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 23be8f3d..2666877a 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,4 +1,4 @@ export default { name: 'vscroll', - version: '1.5.4' + version: '1.5.5' };