ViewBase.ts 994 Bytes
import { Event, Emitter } from "simba-eventkit";

export interface View {
    readonly _type: "View";
    name: string;
    open(parent: View): void;
    show(): void;
    hide(): void;
    close(destroy?: boolean): void;
    readonly isHidden: boolean;
    onShow: Event<() => void>;
    onHide: Event<() => void>;
    onClose: Event<() => void>;
}

export interface Subview {
    readonly _type: "Subview";
    name: string;
    attachParent(parent: View): void;
    show(): void;
    hide(): void;
    readonly isHidden: boolean;
    onShow: Event<() => void>;
    onHide: Event<() => void>;
}

interface PureViewBase<P> {
    setProps(props: P): void;
    updateProps(props: Partial<P>): void;
    // onLoadProps(props: P): void;
    // onPropChange(key: keyof P): void;
}

let emitter = new Emitter;
export const OnSubviewCreated = emitter.createEvent<(subview: Subview) => void>();

export type PureView<P> = PureViewBase<P> & View;
export type PureSubview<P> = PureViewBase<P> & Subview;