Skip to content

Commit

Permalink
issue-54 Routines implicit extending (undocumented)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhilt committed Nov 27, 2023
1 parent c5e0aea commit f629563
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export class Scroller<Data = unknown> {
element = scroller ? scroller.routines.element : (element as HTMLElement);
workflow = scroller ? scroller.workflow : (workflow as ScrollerWorkflow<Data>);

// In general, custom Routines must extend the original Routines. If not, we provide implicit extending.
// This is undocumented feature. It should be removed in vscroll v2.
if (CustomRoutines && !(CustomRoutines.prototype instanceof Routines)) {
class __Routines extends Routines { }
Object.getOwnPropertyNames(CustomRoutines.prototype)
.filter(method => method !== 'constructor')
.forEach(method =>
(__Routines.prototype as unknown as Record<string, unknown>)[method] = CustomRoutines?.prototype[method]
);
CustomRoutines = __Routines;
}

this.workflow = workflow;
this.settings = new Settings<Data>(datasource.settings, datasource.devSettings, ++instanceCount);
this.logger = new Logger(this as Scroller, packageInfo, datasource.adapter);
Expand Down

0 comments on commit f629563

Please sign in to comment.