Skip to content

Commit

Permalink
Duplicate Model on signatures in RootModel to handle overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Apr 25, 2024
1 parent a4ae98c commit 255213e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion src/Model/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ type EventObjectCaptures = string[];

declare module './Model' {
interface RootModel {
// duplicated w on signatures below due to how TS handles overrides
on<T extends keyof ModelOnEventMap>(
eventType: T,
pathPattern: PathLike,
options: { useEventObjects: true },
listener: (event: ModelOnEventMap[T], captures: EventObjectCaptures) => void
): () => void;
on<T extends keyof ModelOnEventMap>(
eventType: T,
options: { useEventObjects: true },
listener: (event: ModelOnEventMap[T], captures: EventObjectCaptures) => void
): () => void;
on(
eventType: 'all',
listener: (pathSegments: string[], event: ModelOnEventMap[keyof ModelOnEventMap]) => void
Expand Down Expand Up @@ -145,7 +157,7 @@ declare module './Model' {
}
}

Model.INITS.push(function(model: Model) {
Model.INITS.push(function(model) {
var root = model.root;
EventEmitter.call(root);

Expand Down
4 changes: 2 additions & 2 deletions src/Model/filter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var util = require('../util');
import { Model } from './Model';
import { Model, RootModel } from './Model';
import { type Segments } from './types';
import * as defaultFns from './defaultFns';
import type { Path, PathLike } from '../types';
Expand Down Expand Up @@ -89,7 +89,7 @@ declare module './Model' {
}
}

Model.INITS.push(function(model: Model) {
Model.INITS.push(function(model) {
model.root._filters = new Filters(model);
model.on('all', filterListener);
function filterListener(segments, event) {
Expand Down

0 comments on commit 255213e

Please sign in to comment.