/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed 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. */ exports.source = ` @Component struct GrandChild { @Consume arr: number[]; build() { } } @Component struct Child { build() { Column() { GrandChild() } } } @Entry @Component struct Parent { @Provide(provideAlias) arr: number[] = [1, 2, 3]; build() { Column() { Child() } } } ` exports.expectResult = `"use strict"; class GrandChild extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.__arr = this.initializeConsume("arr", "arr"); this.updateWithValueParams(params); } updateWithValueParams(params) { } aboutToBeDeleted() { this.__arr.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } get arr() { return this.__arr.get(); } set arr(newValue) { this.__arr.set(newValue); } render() { } } class Child extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.updateWithValueParams(params); } updateWithValueParams(params) { } aboutToBeDeleted() { SubscriberManager.Get().delete(this.id()); } render() { Column.create(); let earlierCreatedChild_2 = this.findChildById("2"); if (earlierCreatedChild_2 == undefined) { View.create(new GrandChild("2", this, {})); } else { earlierCreatedChild_2.updateWithValueParams({}); View.create(earlierCreatedChild_2); } Column.pop(); } } class Parent extends View { constructor(compilerAssignedUniqueChildId, parent, params) { super(compilerAssignedUniqueChildId, parent); this.__arr = new ObservedPropertyObject([1, 2, 3], this, "arr"); this.addProvidedVar("provideAlias", this.__arr); this.addProvidedVar("arr", this.__arr); this.updateWithValueParams(params); } updateWithValueParams(params) { if (params.arr !== undefined) { this.arr = params.arr; } } aboutToBeDeleted() { this.__arr.aboutToBeDeleted(); SubscriberManager.Get().delete(this.id()); } get arr() { return this.__arr.get(); } set arr(newValue) { this.__arr.set(newValue); } render() { Column.create(); let earlierCreatedChild_3 = this.findChildById("3"); if (earlierCreatedChild_3 == undefined) { View.create(new Child("3", this, {})); } else { earlierCreatedChild_3.updateWithValueParams({}); if (!earlierCreatedChild_3.needsUpdate()) { earlierCreatedChild_3.markStatic(); } View.create(earlierCreatedChild_3); } Column.pop(); } } loadDocument(new Parent("1", undefined, {})); `