import { Message } from "@hpcc-js/util"; import { HPCCElement } from "."; export interface Change { oldValue: T; newValue: T; } export type ChangeMap = { [what in keyof T]+?: Change; } export class AttrChangedMessage extends Message { get canConflate(): boolean { return true; } changes: ChangeMap = {}; constructor(what: string, oldValue: any, newValue: any) { super(); this.changes[what] = { oldValue, newValue }; } conflate(other: AttrChangedMessage): boolean { for (const what in other.changes) { const thisChange = this.changes[what]; const otherChange = other.changes[what]; if (thisChange) { this.changes[what]!.newValue = otherChange?.newValue; } else { this.changes[what] = otherChange; } } return true; } }