Skip to content

Commit

Permalink
Merge pull request #58 from dhilt/issue-56-pause-resume-methods
Browse files Browse the repository at this point in the history
Pause-resume methods fixes
  • Loading branch information
dhilt authored Mar 3, 2024
2 parents 045bbba + 02431c2 commit d775f41
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
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'
};

0 comments on commit d775f41

Please sign in to comment.