Skip to content

Commit

Permalink
Remove *Immediate typings from Derby since they were moved to Racer
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyhwang committed Apr 29, 2024
1 parent 3a70f3a commit a2081ba
Showing 1 changed file with 6 additions and 40 deletions.
46 changes: 6 additions & 40 deletions src/Page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import {
type Model,
type RootModel,
util,
ChangeEvent,
MoveEvent,
RemoveEvent,
InsertEvent,
LoadEvent,
UnloadEvent,
} from 'racer';

import { type App } from './App';
Expand All @@ -28,28 +22,6 @@ const {
templates,
} = derbyTemplates;


interface ModelOnImmediateEventMap {
changeImmediate: ChangeEvent,
insertImmediate: InsertEvent,
loadImmediate: LoadEvent,
moveImmediate: MoveEvent,
removeImmediate: RemoveEvent,
unloadImmediate: UnloadEvent,
}

declare module 'racer' {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Model<T> {
on<TEvent extends keyof ModelOnImmediateEventMap>(
eventType: TEvent,
listener: (captures: string[], event: ModelOnImmediateEventMap[TEvent]) => void,
);

removeListener(eventType: keyof ModelOnImmediateEventMap, listener: () => void): void;
}
}

export abstract class Page extends Controller {
model: RootModel;
params: Readonly<PageParams>;
Expand Down Expand Up @@ -204,33 +176,27 @@ export class PageForClient extends Page {
const changeListener = model.on('changeImmediate', function onChange(segments, event) {
// The pass parameter is passed in for special handling of updates
// resulting from stringInsert or stringRemove
segments = util.castSegments(segments.slice());
eventModel.set(segments, event.previous, event.passed);
eventModel.set(util.castSegments(segments), event.previous, event.passed);
});

const loadListener = model.on('loadImmediate', function onLoad(segments) {
segments = util.castSegments(segments.slice());
eventModel.set(segments);
eventModel.set(util.castSegments(segments));
});

const unloadListener = model.on('unloadImmediate', function onUnload(segments, event) {
segments = util.castSegments(segments.slice());
eventModel.set(segments, event.previous);
eventModel.set(util.castSegments(segments), event.previous);
});

const insertListener = model.on('insertImmediate', function onInsert(segments, event) {
segments = util.castSegments(segments.slice());
eventModel.insert(segments, event.index, event.values.length);
eventModel.insert(util.castSegments(segments), event.index, event.values.length);
});

const removeListener = model.on('removeImmediate', function onRemove(segments, event) {
segments = util.castSegments(segments.slice());
eventModel.remove(segments, event.index, event.values.length);
eventModel.remove(util.castSegments(segments), event.index, event.values.length);
});

const moveListener = model.on('moveImmediate', function onMove(segments, event) {
segments = util.castSegments(segments.slice());
eventModel.move(segments, event.from, event.to, event.howMany);
eventModel.move(util.castSegments(segments), event.from, event.to, event.howMany);
});

this._removeModelListeners = function() {
Expand Down

0 comments on commit a2081ba

Please sign in to comment.