Component.ts 3.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

S
sushuang 已提交
20
import Group from 'zrender/src/container/Group';
S
sushuang 已提交
21 22
import * as componentUtil from '../util/component';
import * as clazzUtil from '../util/clazz';
23 24 25 26 27
import ComponentModel from '../model/Component';
import GlobalModel from '../model/Global';
import ExtensionAPI from '../ExtensionAPI';
import {Payload, ViewRootGroup, ECEvent, EventQueryItem} from '../util/types';
import Element from 'zrender/src/Element';
S
sushuang 已提交
28

29
class Component {
S
sushuang 已提交
30

31 32 33 34 35
    // [Caution]: for compat the previous "class extend"
    // publich and protected fields must be initialized on
    // prototype rather than in constructor. Otherwise the
    // subclass overrided filed will be overwritten by this
    // class. That is, they should not be initialized here.
L
lang 已提交
36

37
    readonly group: ViewRootGroup;
L
lang 已提交
38

39
    readonly uid: string;
L
lang 已提交
40

41 42 43 44 45 46
    // ----------------------
    // Injectable properties
    // ----------------------
    __model: ComponentModel;
    __alive: boolean;
    __id: string;
L
lang 已提交
47

48 49 50 51
    constructor() {
        this.group = new Group();
        this.uid = componentUtil.getUID('viewComponent');
    }
52

53 54 55 56 57
    init(ecModel: GlobalModel, api: ExtensionAPI): void {}

    render(model: ComponentModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {}

    dispose(ecModel: GlobalModel, api: ExtensionAPI): void {}
58 59

    /**
60 61
     * Pass only when return `true`.
     * Implement it if needed.
62
     */
63 64 65
    filterForExposedEvent: (
        eventType: string, query: EventQueryItem, targetEl: Element, packedEvent: ECEvent
    ) => boolean;
S
sushuang 已提交
66

67 68 69
    updateView(model: ComponentModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {
        // Do nothing;
    }
S
sushuang 已提交
70

71
    updateLayout(model: ComponentModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {
S
sushuang 已提交
72
        // Do nothing;
73 74 75 76 77 78 79 80 81 82 83 84 85
    }

    updateVisual(model: ComponentModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {
        // Do nothing;
    }

    /**
     * Implement it if needed.
     */
    updateTransform: (
        seriesModel: ComponentModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload
    ) => void | {update: true};

86
    static registerClass: clazzUtil.ClassManager['registerClass'];
87 88 89 90 91
};

export type ComponentViewConstructor = typeof Component
    & clazzUtil.ExtendableConstructor
    & clazzUtil.ClassManager;
S
sushuang 已提交
92

93 94
clazzUtil.enableClassExtend(Component as ComponentViewConstructor)
clazzUtil.enableClassManagement(Component as ComponentViewConstructor, {registerWhenExtend: true});
L
lang 已提交
95

96
export default Component;