Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast initialization fixes #52

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading