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

Pause-resume methods fixes #58

Merged
merged 2 commits into from
Mar 3, 2024
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
4 changes: 2 additions & 2 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.6.0",
"version": "1.6.1",
"description": "Virtual scroll engine",
"main": "dist/bundles/vscroll.umd.js",
"module": "dist/bundles/vscroll.esm5.js",
Expand Down
34 changes: 15 additions & 19 deletions src/classes/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,6 @@ export class Adapter<Item = unknown> implements IAdapter<Item> {
private relax$: Reactive<AdapterMethodResult> | null;
private relaxRun: Promise<AdapterMethodResult> | 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<AdapterMethodResult>(resolve => {
if (this.relax$) {
Expand All @@ -139,13 +129,19 @@ export class Adapter<Item = unknown> implements IAdapter<Item> {
});
}

private getWorkflowRunnerMethod(method: MethodResolver, defaultMethod: MethodResolver) {
return (...args: unknown[]): Promise<AdapterMethodResult> =>
!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<AdapterMethodResult> => {
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<Item> | null, getWorkflow: WorkflowGetter<Item>, logger: Logger) {
Expand Down Expand Up @@ -269,12 +265,12 @@ export class Adapter<Item = unknown> implements IAdapter<Item> {
// 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) {
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.6.0'
version: '1.6.1'
};
Loading