• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/**
17 *
18 * This file includes only framework internal classes and functions
19 * non are part of SDK. Do not access from app.
20 *
21 * Helper classes used by ViewPU and ViewV2
22 *
23 */
24
25
26/**
27 * WeakRef
28 * ref to an Object that does not prevent the Object from getting GC'ed
29 * current version of tsc does not know about WeakRef
30 * but Ark runtime supports it
31 *
32 */
33declare class WeakRef<T extends Object> {
34  constructor(o: T);
35  deref(): T;
36}
37
38  declare class DumpLog {
39    static print(depth: number, content: string): void;
40  }
41
42  // function type of partial update function
43  type UpdateFunc = (elmtId: number, isFirstRender: boolean, param?: Object) => void;
44  type UIClassObject = { prototype: Object, pop?: () => void };
45
46  // UpdateFuncRecord: misc framework-internal info related to updating of a UINode C++ object
47  // that TS side needs to know.
48  // updateFunc_  lambda function to update the UINode
49  // JS interface class reference (it only has static functions)
50  class UpdateFuncRecord {
51    private updateFunc_: UpdateFunc;
52    private classObject_: UIClassObject;
53    private node_?: ArkComponent;
54    private isPending_: boolean = false;
55    private isChanged_: boolean = false;
56
57    constructor(params: { updateFunc: UpdateFunc, classObject?: UIClassObject, node?: ArkComponent }) {
58      this.updateFunc_ = params.updateFunc;
59      this.classObject_ = params.classObject;
60      this.node_ = params.node;
61    }
62
63    public getUpdateFunc(): UpdateFunc | undefined {
64      return this.updateFunc_;
65    }
66
67    public getComponentClass(): UIClassObject | undefined {
68      return this.classObject_;
69    }
70
71    public getComponentName(): string {
72      return (this.classObject_ && ('name' in this.classObject_)) ? Reflect.get(this.classObject_, 'name') as string : 'unspecified UINode';
73    }
74
75    public getPopFunc(): () => void {
76      return (this.classObject_ && 'pop' in this.classObject_) ? this.classObject_.pop! : (): void => { };
77    }
78
79    public getNode(): ArkComponent | undefined {
80      return this.node_;
81    }
82
83    public setNode(node: ArkComponent | undefined): void {
84      this.node_ = node;
85    }
86
87    public isPending(): boolean {
88      return this.isPending_;
89    }
90
91    public setPending(isPending: boolean): void {
92      this.isPending_ = isPending;
93    }
94
95    public isChanged(): boolean {
96      return this.isChanged_;
97    }
98
99    public setIsChanged(isChanged: boolean): void {
100      this.isChanged_ = isChanged;
101    }
102  } // UpdateFuncRecord
103
104
105class UpdateFuncsByElmtId {
106
107    private map_ = new Map<number, UpdateFuncRecord>();
108
109    public delete(elmtId: number): boolean {
110      return this.map_.delete(elmtId);
111    }
112
113    public set(elmtId: number, params: UpdateFunc | { updateFunc: UpdateFunc, classObject?: UIClassObject, node?: ArkComponent }): void {
114      (typeof params === 'object') ?
115        this.map_.set(elmtId, new UpdateFuncRecord(params)) :
116        this.map_.set(elmtId, new UpdateFuncRecord({ updateFunc: params as UpdateFunc }));
117    }
118
119    public get(elmtId: number): UpdateFuncRecord | undefined {
120      return this.map_.get(elmtId);
121    }
122
123    public has(elmtId: number): boolean {
124      return this.map_.has(elmtId);
125    }
126
127    public keys(): IterableIterator<number> {
128      return this.map_.keys();
129    }
130
131    public clear(): void {
132      return this.map_.clear();
133    }
134
135    public get size(): number {
136      return this.map_.size;
137    }
138
139    public forEach(callbackfn: (value: UpdateFuncRecord, key: number, map: Map<number, UpdateFuncRecord>) => void): void {
140      this.map_.forEach(callbackfn);
141    }
142
143    // dump info about known elmtIds to a string
144    // use function only for debug output and DFX.
145    public debugInfoRegisteredElmtIds(): string {
146      let result: string = '';
147      let sepa: string = '';
148      this.map_.forEach((value: UpdateFuncRecord, elmtId: number) => {
149        result += `${sepa}${value.getComponentName()}[${elmtId}]`;
150        sepa = ', ';
151      });
152      return result;
153    }
154
155    public debugInfoElmtId(elmtId: number): string {
156      const updateFuncEntry = this.map_.get(elmtId);
157      return updateFuncEntry ? `${updateFuncEntry!.getComponentName()}[${elmtId}]` : `unknown component type[${elmtId}]`;
158    }
159  } // class UpdateFuncByElmtId
160