immutable-class
Version:
A template for creating immutable classes
47 lines • 2.17 kB
TypeScript
export type DiffAction = 'create' | 'update' | 'delete';
export interface Nameable {
name: string;
}
export interface SynchronizerOptions<T> {
key?: (thing: T, index?: number) => string;
equals?: (thingA: T, thingB: T) => boolean;
onEnter?: (newThing: T) => void;
onUpdate?: (newThing: T, oldThing: T) => void;
onExit?: (oldThing: T) => void;
}
export interface DiffJS {
before?: any;
after?: any;
}
export declare class Diff<T extends Nameable> {
static inflateFromJS<T extends Nameable>(Class: {
fromJS: (js: any, context?: any) => T;
}, diffJS: DiffJS, context?: any): Diff<T>;
static inflateFromJSs<T extends Nameable>(Class: {
fromJS: (js: any, context?: any) => T;
}, diffJSs: DiffJS[], context?: any): Diff<T>[];
before?: T;
after?: T;
constructor(before: T | undefined, after: T | undefined);
toJS(): DiffJS;
toJSON(): DiffJS;
getAction(): DiffAction;
getName(): string;
}
export declare class NamedArray {
static isValid<T extends Nameable>(array: T[]): boolean;
static checkValid<T extends Nameable>(array: T[], what?: string, where?: string): void;
static get<T extends Nameable>(array: T[], name: string): T;
static toRecord<T extends NamedArray>(array: T[]): Record<string, T>;
static containsByName<T extends Nameable>(array: T[], name: string): boolean;
static findByNameCI<T extends Nameable>(array: T[], name: string): T | undefined;
static findByName<T extends Nameable>(array: T[], name: string): T | undefined;
static findIndexByName<T extends Nameable>(array: T[], name: string): number;
static overrideByName<T extends Nameable>(things: T[], thingOverride: T): T[];
static overridesByName<T extends Nameable>(things: T[], thingOverrides: T[]): T[];
static dedupe<T extends Nameable>(things: T[]): T[];
static deleteByName<T extends Nameable>(array: T[], name: string): T[];
static synchronize<T>(oldThings: T[], newThings: T[], updatedOptions: SynchronizerOptions<T>): void;
static computeDiffs<T extends Nameable>(oldThings: T[], newThings: T[]): Diff<T>[];
}
//# sourceMappingURL=named-array.d.ts.map