• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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
16class InteropExtractorModule {
17    static getInteropObservedObject<T extends Object>(newValue: T, owningProperty: ObservedPropertyPU<T>): T {
18        if ((newValue instanceof Array || newValue instanceof Set || newValue instanceof Map || newValue instanceof Date) &&
19            !('addWatchSubscriber' in newValue) && (typeof InteropExtractorModule.makeObserved !== undefined && typeof InteropExtractorModule.makeObserved === 'function')) {
20            newValue = InteropExtractorModule.makeObserved(newValue) as T;
21        }
22        if ('addWatchSubscriber' in newValue && typeof (newValue as any).addWatchSubscriber === 'function') {
23            const callback = () => {
24                owningProperty.onTrackedObjectPropertyCompatModeHasChangedPU(null, '');
25            };
26            if (typeof InteropExtractorModule.createWatchFunc !== undefined && typeof InteropExtractorModule.createWatchFunc === 'function') {
27                owningProperty.staticWatchId = InteropExtractorModule.createWatchFunc(callback, newValue);
28            }
29        }
30        return newValue;
31    }
32
33    static setStaticValueForInterop<T>(state: ObservedPropertyPU<T>, newValue: T): void {
34        if (state._setInteropValueForStaticState !== undefined &&
35            typeof state._setInteropValueForStaticState === 'function') {
36            state._setInteropValueForStaticState(newValue);
37        }
38    }
39
40    static createWatchFunc?: (watchFuncCallback: WatchFuncType, newValue: Object) => any;
41    static makeObserved?: (value: Object) => Object;
42}