Skip to content

Commit

Permalink
Merge pull request #52 from dhilt/issue-51-Fast-initialization-fixes
Browse files Browse the repository at this point in the history
Fast initialization fixes
  • Loading branch information
dhilt committed Jun 16, 2023
2 parents 4b1b433 + f0b5c17 commit ae8416f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/processes/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export default class Fetch extends BaseProcessFactory(CommonProcess.fetch) {
if (typeof (getResult as PromiseLike<unknown>).then === 'function') {
return getResult as Promise<unknown>;
} else if (typeof (getResult as ObservableLike).subscribe === 'function') {
const sub = (getResult as ObservableLike).subscribe(done, fail, () => {
let sub: undefined | ReturnType<ObservableLike['subscribe']> = void 0;
sub = (getResult as ObservableLike).subscribe(done, fail, () => {
if (sub && typeof sub === 'object' && typeof sub.unsubscribe === 'function') {
sub.unsubscribe();
}
Expand Down
1 change: 1 addition & 0 deletions src/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class Scroller<Data = unknown> {
}

dispose(forever?: boolean): void {
this.logger.log(() => 'disposing scroller' + (forever ? ' (forever)' : ''));
if (forever) { // Adapter is not re-instantiated on reset
this.adapter.dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default {
name: 'vscroll',
version: '1.5.4'
version: '1.5.5'
};
18 changes: 11 additions & 7 deletions src/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
export class Workflow<ItemData = unknown> {

isInitialized: boolean;
disposed: boolean;
initTimer: ReturnType<typeof setTimeout> | null;
adapterRun$: Reactive<ProcessSubject>;
cyclesDone: number;
Expand All @@ -32,6 +33,7 @@ export class Workflow<ItemData = unknown> {

constructor({ element, datasource, consumer, run, Routines }: WorkflowParams<ItemData>) {
this.isInitialized = false;
this.disposed = false;
this.initTimer = null;
this.adapterRun$ = new Reactive();
this.cyclesDone = 0;
Expand Down Expand Up @@ -62,13 +64,6 @@ export class Workflow<ItemData = unknown> {

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;
Expand All @@ -79,6 +74,13 @@ export class Workflow<ItemData = unknown> {
payload: { event }
});
this.offScroll = routines.onScroll(onScrollHandler);

// run the Workflow
this.isInitialized = true;
this.callWorkflow({
process: CommonProcess.init,
status: Status.start
});
}

changeItems(items: Item<ItemData>[]): void {
Expand Down Expand Up @@ -185,6 +187,7 @@ export class Workflow<ItemData = unknown> {
}

dispose(): void {
this.scroller.logger.log(() => 'disposing workflow');
if (this.initTimer) {
clearTimeout(this.initTimer);
}
Expand All @@ -194,6 +197,7 @@ export class Workflow<ItemData = unknown> {
Object.getOwnPropertyNames(this).forEach(prop => {
delete (this as Record<string, unknown>)[prop];
});
this.disposed = true;
}

finalize(): void {
Expand Down

0 comments on commit ae8416f

Please sign in to comment.