UNPKG

1.76 kBTypeScriptView Raw
1import { ComponentOption } from '../../interface';
2import View from '../view';
3/** Component controller class type define */
4export declare type ControllerCtor<O = any> = new (view: View) => Controller<O>;
5/**
6 * Component Controller 规范需要定义的基类
7 * 1. 规范的 option 输入
8 * 2. 统一的信息获取 API
9 * 3. 明确定义的组件事件(名称、数据)
10 */
11export declare abstract class Controller<O = unknown> {
12 /** 是否可见 */
13 visible: boolean;
14 protected view: View;
15 /** option 配置,不同组件有自己不同的配置结构 */
16 protected option: O;
17 /** 所有的 component */
18 protected components: ComponentOption[];
19 constructor(view: View);
20 abstract get name(): string;
21 /**
22 * init the component
23 */
24 abstract init(): any;
25 /**
26 * render the components
27 */
28 abstract render(): any;
29 /**
30 * update the components
31 */
32 /**
33 * do layout
34 */
35 abstract layout(): any;
36 /**
37 * 组件的更新逻辑
38 * - 根据字段为标识,为每一个组件生成一个 id,放到 option 中
39 * - 更新的时候按照 id 去做 diff,然后对同的做处理
40 * - 创建增加的
41 * - 更新已有的
42 * - 销毁删除的
43 */
44 abstract update(): any;
45 /**
46 * clear
47 * @param includeOption 是否清空 option 配置项(used in annotation)
48 */
49 clear(includeOption?: boolean): void;
50 /**
51 * destroy the component
52 */
53 destroy(): void;
54 /**
55 * get all components
56 * @returns components array
57 */
58 getComponents(): ComponentOption[];
59 /**
60 * change visibility of component
61 * @param visible
62 */
63 changeVisible(visible: boolean): void;
64}