diff --git a/arkui-plugins/test/demo/mock/builder-lambda/simple-component.ets b/arkui-plugins/test/demo/mock/builder-lambda/simple-component.ets index 50ef19686c214c0542fc50d5ab7d290f77160bd5..79886cd636abb115db86135911840d922c0f2e79 100644 --- a/arkui-plugins/test/demo/mock/builder-lambda/simple-component.ets +++ b/arkui-plugins/test/demo/mock/builder-lambda/simple-component.ets @@ -14,7 +14,7 @@ */ import { memo } from "@ohos.arkui.stateManagement" -import { Column, UIColumnAttribute } from "arkui.component.column" +import { Column, ColumnAttribute } from "arkui.component.column" class MyStateSample { @memo build() { diff --git a/arkui-plugins/test/demo/mock/builder-lambda/style-with-receiver.ets b/arkui-plugins/test/demo/mock/builder-lambda/style-with-receiver.ets index 92d842ff54db1ec685cfce72da7df394bef82ecc..a9b81be6801d733b9d0029d84f4298ce16ed41e8 100644 --- a/arkui-plugins/test/demo/mock/builder-lambda/style-with-receiver.ets +++ b/arkui-plugins/test/demo/mock/builder-lambda/style-with-receiver.ets @@ -14,16 +14,16 @@ */ import { memo } from "@ohos.arkui.stateManagement" // should be insert by ui-plugins -import { Text, UITextAttribute, Column, Component} from "@ohos.arkui.component" +import { Text, TextAttribute, Column, Component} from "@ohos.arkui.component" import hilog from '@ohos.hilog' -@memo function cardStyle(this: UITextAttribute, num: number, str: string): this { +@memo function cardStyle(this: TextAttribute, num: number, str: string): this { this.fontSize(num); this.backgroundColor(num); return this; } -@memo function style22(this: UITextAttribute): this { +@memo function style22(this: TextAttribute): this { this.fontWeight(700); return this; } diff --git a/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-basic.ets b/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-basic.ets index 273a00f461eee3188e82f24de278f0e8e7873778..6c06a5554efece86b1f7acfcd400376fbd48bb3f 100644 --- a/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-basic.ets +++ b/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-basic.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed, ObjectLink } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-observed.ets b/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-observed.ets index 54dc8f89b6cf6e4dd5a660e4fe18b4f16835e154..73cc53cc0b59037dac3b14f09d8eb605e066520a 100644 --- a/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-observed.ets +++ b/arkui-plugins/test/demo/mock/decorators/objectlink/objectlink-observed.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry, Column, Button, ClickEvent } from "@ohos.arkui.component" import { State, ObjectLink, Observed } from "@ohos.arkui.stateManagement" @@ -10,7 +25,7 @@ class DateClass extends Date { @Observed class NewDate { - public data: DateClass; + public data: DateClass = new DateClass(11); constructor(data: DateClass) { this.data = data; @@ -42,11 +57,11 @@ struct Parent { Child({ label: 'date', data: this.newData.data }) Button(`parent update the new date`) - .onClick(() => { + .onClick((e: ClickEvent) => { this.newData.data = new DateClass('2023-07-07'); }) Button(`ViewB: this.newData = new NewDate(new DateClass('2023-08-20'))`) - .onClick(() => { + .onClick((e: ClickEvent) => { this.newData = new NewDate(new DateClass('2023-08-20')); }) } diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-only.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-only.ets index 3890ea9ecab4eab9d52cbc7ab3c671cbd9c99a01..b646f91c4207d279a79d501ba4c9dddc04c50c72 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-only.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-only.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-class-property.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-class-property.ets index 48a3cd405f001f8c617ea967feef02215bb56963..10a9ecd577221c482ab69a668951ffef56883133 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-class-property.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-class-property.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed, Track } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-complex-type.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-complex-type.ets index bf59d6d517a1b9afd425c9abed0bf66974e54bb6..a47a08b816fe9c2c221f05c75965a8ba32c1e00b 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-complex-type.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-complex-type.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" import { Observed, Track } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-extends.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-extends.ets index 66135926a24c14231dbfb442f8e3e3a2db1c8ce2..a9d102691bbf11ef993e7fb9682bdebc3adb3221 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-extends.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-extends.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed, Track } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-implements.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-implements.ets index 5be8bd871c70edeba919e09727f2bd6428ff040b..8342cd8c277e619aa2582af34fe7d9195b53d859 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-implements.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track-implements.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed } from "@ohos.arkui.stateManagement" interface PropInterface { diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track.ets index 3d15c071a043cde1cd20ab328133e032d0b9780a..98d037faab81d8617518243c6a0718daab34b54d 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/observed-track.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Observed, Track } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/observed-track/track-only.ets b/arkui-plugins/test/demo/mock/decorators/observed-track/track-only.ets index fea1df86e1bfd14eeb87a1c65eb24129337a935a..08239c86f16a9ca62d911f6188714cb23cdf4e24 100644 --- a/arkui-plugins/test/demo/mock/decorators/observed-track/track-only.ets +++ b/arkui-plugins/test/demo/mock/decorators/observed-track/track-only.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component } from "@ohos.arkui.component" import { Track } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/reusable/reusable-basic.ets b/arkui-plugins/test/demo/mock/decorators/reusable/reusable-basic.ets index bfbaaec54035bf3f5a8254b1bf95b077376427b6..547ed62ea0ace3b2aac355c254ae89cf206fd4cf 100644 --- a/arkui-plugins/test/demo/mock/decorators/reusable/reusable-basic.ets +++ b/arkui-plugins/test/demo/mock/decorators/reusable/reusable-basic.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Reusable} from "@ohos.arkui.component" import { State, Prop } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/reusable/reusable-complex.ets b/arkui-plugins/test/demo/mock/decorators/reusable/reusable-complex.ets index d66fe54519af51ebe4bae06aa87eb4bf3ed6cbf6..10bf9f803439f53758ecae5b653297554f1150d3 100644 --- a/arkui-plugins/test/demo/mock/decorators/reusable/reusable-complex.ets +++ b/arkui-plugins/test/demo/mock/decorators/reusable/reusable-complex.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry, Reusable, Column, Text, Button, ClickEvent, FontWeight} from "@ohos.arkui.component" import { State } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-appstorage.ets b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-appstorage.ets index 298dc89559f07bb094d7b5fc8a395c01ba619f62..5fc30ed4ba6bdcfb34327491c3a654f53396718b 100644 --- a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-appstorage.ets +++ b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-appstorage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry, Column, Text, ClickEvent } from "@ohos.arkui.component" import { StorageLink, AppStorage } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-complex-type.ets b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-complex-type.ets index 9aed6364d9c83a3a6865d84ef559025e14fb4cb7..bf7b42ab65af2a3c8d902dc8106dda8ea19bdace 100644 --- a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-complex-type.ets +++ b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-complex-type.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" import { StorageLink } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-primitive-type.ets b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-primitive-type.ets index e5afb4d19714d7e4e84d3eefb381e24cd376e867..a4219a46368068ad3c4c32197463fb72eb7e31ac 100644 --- a/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-primitive-type.ets +++ b/arkui-plugins/test/demo/mock/decorators/storagelink/storagelink-primitive-type.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" import { StorageLink } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-appstorage.ets b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-appstorage.ets index bff353a175509fd8080dd3390ecb86ca3ec34831..dd25eb7fb008b724d932df2a6d2ed8e03c4ea069 100644 --- a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-appstorage.ets +++ b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-appstorage.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry, Column, Text, ClickEvent } from "@ohos.arkui.component" import { StorageProp, AppStorage } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-complex-type.ets b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-complex-type.ets index 5a770cf6ee43a829be0c528003838d4a61551ad3..6136d1bd38a2eeb942fb647d8e7fafcd5d287e0c 100644 --- a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-complex-type.ets +++ b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-complex-type.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins import { StorageProp } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-primitive-type.ets b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-primitive-type.ets index d82a28552453804ec2f268b84a7baca461dc95c2..95d4ed58d42aaa7f76fbdfe8b1c6798ac2e22b6f 100644 --- a/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-primitive-type.ets +++ b/arkui-plugins/test/demo/mock/decorators/storageprop/storageprop-primitive-type.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" // TextAttribute should be insert by ui-plugins import { StorageProp } from "@ohos.arkui.stateManagement" diff --git a/arkui-plugins/test/demo/mock/decorators/watch/watch-basic.ets b/arkui-plugins/test/demo/mock/decorators/watch/watch-basic.ets index 6a85ab00ac447f337857d612b451c03e22197273..a9bb67472f9003d2f6f4025a6c3f9e100e4636d8 100644 --- a/arkui-plugins/test/demo/mock/decorators/watch/watch-basic.ets +++ b/arkui-plugins/test/demo/mock/decorators/watch/watch-basic.ets @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2025 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. + */ + import { Component, Entry } from "@ohos.arkui.component" import { State, Prop, StorageLink, StorageProp, Link, Watch, ObjectLink, Observed, Track, Provide, Consume } from "@ohos.arkui.stateManagement" @@ -12,18 +27,18 @@ class A { struct MyStateSample { @State @Watch('stateOnChange') statevar: string = 'Hello World'; @Prop @Watch('propOnChange') propvar: string = 'Hello World'; - // @Link @Watch('linkOnChange') linkvar: string; + @Link @Watch('linkOnChange') linkvar: string; @StorageLink('prop1') @Watch('storageLinkOnChange') storagelinkvar: string = 'Hello World'; @StorageProp('prop2') @Watch('storagePropOnChange') storagepropvar: string = 'Hello World'; - // @ObjectLink @Watch('objectLinkOnChange') objectlinkvar: A; + @ObjectLink @Watch('objectLinkOnChange') objectlinkvar: A; @Provide @Watch('ProvideOnChange') providevar: string = 'Hello World'; stateOnChange(propName: string) {} propOnChange(propName: string) {} - // linkOnChange(propName: string) {} + linkOnChange(propName: string) {} storageLinkOnChange(propName: string) {} storagePropOnChange(propName: string) {} - // objectLinkOnChange(propName: string) {} + objectLinkOnChange(propName: string) {} ProvideOnChange(propName: string) {} build() { @@ -33,9 +48,9 @@ struct MyStateSample { @Component struct Child { - // @Consume @Watch('ConsumeOnChange') providevar: string; + @Consume @Watch('ConsumeOnChange') providevar: string; - // ConsumeOnChange(propName: string) {} + ConsumeOnChange(propName: string) {} build() {} } \ No newline at end of file diff --git a/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts index 88322c353890de62a1fb774bfeed72504daf4382..914f3ed27646c2a841d90dc37a67dbfdb0c5a190 100644 --- a/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/animation/animation-basic.test.ts @@ -33,30 +33,36 @@ buildConfig.compileFiles = [ const animationTransform: Plugins = { name: 'animation', parsed: uiTransform().parsed, -} +}; const pluginTester = new PluginTester('test basic animation transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Text as Text, Column as Column, Component as Component, Color as Color, Curve as Curve } from "@ohos.arkui.component"; + import { Entry as Entry } from "@ohos.arkui.component"; function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class AnimatablePropertyExample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct AnimatablePropertyExample extends CustomComponent { public __initializeStruct(initializers: __Options_AnimatablePropertyExample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_AnimatablePropertyExample | undefined): void {} @memo() public _build(@memo() style: ((instance: AnimatablePropertyExample)=> AnimatablePropertyExample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_AnimatablePropertyExample | undefined): void { Column(undefined, (() => { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.animationStart({ duration: 2000, curve: Curve.Ease, @@ -95,8 +101,15 @@ class __EntryWrapper extends EntryPoint { } `; +const expectedHeader = + ` + animationStart(value: AnimateParam | undefined): this + animationStop(value: AnimateParam | undefined): this + `; + function testAnimationTransformer(this: PluginTestContext): void { expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); + expect(parseDumpSrc(this.declContexts?.['arkui.component.common']?.scriptSnapshot ?? '')).toContain(parseDumpSrc(expectedHeader)); } pluginTester.run( @@ -107,5 +120,6 @@ pluginTester.run( }, { stopAfter: 'checked', + tracing: { externalSourceNames: ['arkui.component.common'] }, } ); diff --git a/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts b/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts index 705886859ab50036c52ae457e00f5cbba2e6f39a..19cdd4ac22d13a2156fd194b8a4e2e230e61a157 100644 --- a/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/builder-lambda/custom-component/custom-component-call.test.ts @@ -48,14 +48,14 @@ const expectedParsedScript: string = ` import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; import { Text as Text, Column as Column, Component as Component, Builder as Builder, BuilderParam as BuilderParam } from "@ohos.arkui.component"; -@Component() final class CustomContainer extends CustomComponent { +@Component() final struct CustomContainer extends CustomComponent { @Builder() public closerBuilder() {} @BuilderParam() public closer: (()=> void) = this.closerBuilder; public build() {} public constructor() {} } -@Component() final class CustomContainerUser extends CustomComponent { +@Component() final struct CustomContainerUser extends CustomComponent { public build() { Column(){ CustomContainer(){ @@ -86,68 +86,84 @@ function testParedTransformer(this: PluginTestContext): void { } const expectedBuilderLambdaScript: string = ` -import { __memo_id_type as __memo_id_type } from "@ohos.arkui.stateManagement"; -import { __memo_context_type as __memo_context_type } from "@ohos.arkui.stateManagement"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UIColumnAttribute as UIColumnAttribute } from "arkui.component.column"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Text as Text, Column as Column, Component as Component, Builder as Builder, BuilderParam as BuilderParam } from "@ohos.arkui.component"; function main() {} -@Component({freezeWhenInactive:false}) final class CustomContainer extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct CustomContainer extends CustomComponent { public __initializeStruct(initializers: __Options_CustomContainer | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_closer = ((((({let gensym___38813563 = initializers; (((gensym___38813563) == (null)) ? undefined : gensym___38813563.closer)})) ?? (content))) ?? (this.closerBuilder)) } + public __updateStruct(initializers: __Options_CustomContainer | undefined): void {} + private __backing_closer?: @memo() (()=> void); + public get closer(): @memo() (()=> void) { return this.__backing_closer!; } + public set closer(@memo() value: (()=> void)) { this.__backing_closer = value; } + @memo() public closerBuilder() {} + @memo() public _build(@memo() style: ((instance: CustomContainer)=> CustomContainer) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_CustomContainer | undefined): void {} - public constructor() {} + + private constructor() {} + } -@Component({freezeWhenInactive:false}) final class CustomContainerUser extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct CustomContainerUser extends CustomComponent { public __initializeStruct(initializers: __Options_CustomContainerUser | undefined, @memo() content: (()=> void) | undefined): void {} + public __updateStruct(initializers: __Options_CustomContainerUser | undefined): void {} + @memo() public _build(@memo() style: ((instance: CustomContainerUser)=> CustomContainerUser) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_CustomContainerUser | undefined): void { Column(undefined, (() => { CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); }), (() => { Column(undefined, (() => { - Text(undefined, "hello", undefined, undefined); + Text(undefined, "hello"); })); - }), undefined); + })); CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); }), ({} as __Options_CustomContainer), (() => { Column(undefined, (() => {})); - }), undefined); + })); CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); - }), (() => {}), undefined); + }), undefined, (() => {})); CustomContainer._instantiateImpl(undefined, (() => { return new CustomContainer(); - }), undefined, undefined, undefined); + })); })); } - public constructor() {} + + private constructor() {} + } -interface __Options_CustomContainer { - set closer(closer: @memo() (()=> void) | undefined) +@Component({freezeWhenInactive:false}) export interface __Options_CustomContainer { + set closer(@memo() closer: (()=> void) | undefined) + get closer(): @memo() (()=> void) | undefined + } -interface __Options_CustomContainerUser { +@Component({freezeWhenInactive:false}) export interface __Options_CustomContainerUser { + } `; @@ -160,7 +176,7 @@ pluginTester.run( [parsedTransform, recheck, uiNoRecheck, recheck], { parsed: [testParedTransformer], - 'checked:builder-lambda-no-recheck': [testCustomComponentTransformer], + 'checked:ui-no-recheck': [testCustomComponentTransformer], }, { stopAfter: 'checked', diff --git a/arkui-plugins/test/ut/ui-plugins/builder-lambda/simple-component.test.ts b/arkui-plugins/test/ut/ui-plugins/builder-lambda/simple-component.test.ts index 48996b891ec3a19cd32c8b04329abeee45723905..52b5c7aa5636b83493bdf2a8cbef3e23a3c37270 100644 --- a/arkui-plugins/test/ut/ui-plugins/builder-lambda/simple-component.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/builder-lambda/simple-component.test.ts @@ -33,7 +33,7 @@ const pluginTester = new PluginTester('test builder-lambda simple component', bu function testBuilderLambdaTransformer(this: PluginTestContext): void { const expectedScript: string = ` import { memo as memo } from \"@ohos.arkui.stateManagement\"; -import { Column as Column, UIColumnAttribute as UIColumnAttribute } from \"arkui.component.column\"; +import { Column as Column, ColumnAttribute as ColumnAttribute } from \"arkui.component.column\"; function main() {} class MyStateSample { @memo() public build() { @@ -49,7 +49,7 @@ function testMemoTransformer(this: PluginTestContext): void { const expectedScript: string = ` import { __memo_context_type as __memo_context_type, __memo_id_type as __memo_id_type } from \"arkui.stateManagement.runtime\"; import { memo as memo } from \"@ohos.arkui.stateManagement\"; -import { Column as Column, UIColumnAttribute as UIColumnAttribute } from \"arkui.component.column\"; +import { Column as Column, ColumnAttribute as ColumnAttribute } from \"arkui.component.column\"; function main() {} class MyStateSample { public build(__memo_context: __memo_context_type, __memo_id: __memo_id_type): void { diff --git a/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts b/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts index 507986736f020e39d080152929168e2294fa0234..fecec08266d5f3ce21ca417a20da92d38481764b 100644 --- a/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/builder-lambda/style-with-receiver.test.ts @@ -38,38 +38,46 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { memo as memo } from "@ohos.arkui.stateManagement"; -import { Text as Text, UITextAttribute as UITextAttribute, Column as Column, Component as Component } from "@ohos.arkui.component"; + +import { Text as Text, TextAttribute as TextAttribute, Column as Column, Component as Component } from "@ohos.arkui.component"; + import hilog from "@ohos.hilog"; function main() {} -@memo() function cardStyle(this: UITextAttribute, num: number, str: string): UITextAttribute { + +@memo() function cardStyle(this: TextAttribute, num: number, str: string): TextAttribute { this.fontSize(num); this.backgroundColor(num); return this; } -@memo() function style22(this: UITextAttribute): UITextAttribute { +@memo() function style22(this: TextAttribute): TextAttribute { this.fontWeight(700); return this; } -@Component({freezeWhenInactive:false}) final class MM extends CustomComponent { + +@Component({freezeWhenInactive:false}) final struct MM extends CustomComponent { public __initializeStruct(initializers: __Options_MM | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MM | undefined): void {} @memo() public _build(@memo() style: ((instance: MM)=> MM) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MM | undefined): void { Column(undefined, (() => { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { style22(cardStyle(instance.height(200).fontColor("#000000"), 600, "#eeeeee").fontSize(60).fontWeight(400)).width(900); return; }), "hello world"); - Text(@memo() ((instance: UITextAttribute): void => { + Text(@memo() ((instance: TextAttribute): void => { cardStyle(instance, 600, "#eeeeee"); return; }), "hello world"); diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts index f8029becfa882b83b508e66bb570e8ddcd27614f..ee4f7e9bef3627ab90fefefc8c810ca50cfbe938 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/builder-param-passing.test.ts @@ -44,7 +44,7 @@ import { Component as Component, Entry as Entry, Builder as Builder, BuilderPara function main() {} -@Component({freezeWhenInactive:false}) final class Child extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_customBuilderParam = ((((({let gensym___169376706 = initializers; (((gensym___169376706) == (null)) ? undefined : gensym___169376706.customBuilderParam)})) ?? (content))) ?? (this.customBuilder)) @@ -72,7 +72,7 @@ function main() {} } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_Parent | undefined): void {} diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts index 9e7706330d8dfdd6e5c14d454fdba921b9971c18..13b5b6ca36990c6b68af668351f7fb0c1c7751b1 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder-param/init-with-local-builder.test.ts @@ -44,7 +44,7 @@ import { Component as Component, Builder as Builder, BuilderParam as BuilderPara function main() {} -@Component({freezeWhenInactive:false}) final class Child extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_customBuilderParam = ((((({let gensym___169376706 = initializers; (((gensym___169376706) == (null)) ? undefined : gensym___169376706.customBuilderParam)})) ?? (content))) ?? (this.doNothingBuilder)) diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts index ca9507117ff31044075f53157ff8daca3b45a436..1c1bf626e6b65a55ca02418f5bc2d0e9cdd6fd66 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder/global-builder.test.ts @@ -57,7 +57,7 @@ class Tmp { public constructor() {} } -@Component({freezeWhenInactive:false}) final class BuilderDemo extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct BuilderDemo extends CustomComponent { public __initializeStruct(initializers: __Options_BuilderDemo | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_BuilderDemo | undefined): void {} @memo() public _build(@memo() style: ((instance: BuilderDemo)=> BuilderDemo) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_BuilderDemo | undefined): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts index 54b1ae5b066bba5fea17fabc8c9d113506e9c69a..9ea291b7fb7586d1ad41731cc259313a32eacd88 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/builder/local-builder.test.ts @@ -36,35 +36,47 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Column as Column, Builder as Builder, Text as Text } from "@ohos.arkui.component"; function main() {} -@Component({freezeWhenInactive:false}) final class BuilderDemo extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct BuilderDemo extends CustomComponent { public __initializeStruct(initializers: __Options_BuilderDemo | undefined, @memo() content: (()=> void) | undefined): void {} + public __updateStruct(initializers: __Options_BuilderDemo | undefined): void {} + @memo() public showTextBuilder() { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.fontSize(30); return; }), "Hello World"); } + @memo() public showTextValueBuilder(param: string) { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.fontSize(30); return; }), param); } + @memo() public _build(@memo() style: ((instance: BuilderDemo)=> BuilderDemo) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_BuilderDemo | undefined): void { Column(undefined, @memo() (() => { this.showTextBuilder(); this.showTextValueBuilder("Hello @Builder"); })); } + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_BuilderDemo { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts index 67906db212cc2231056990028b299564858177cc..d11cd83ecc0e8d843fe7c717b4279cbe9d6ef9e3 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-basic-type.test.ts @@ -38,99 +38,141 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` -import { DecoratedV1VariableBase as DecoratedV1VariableBase } from "arkui.stateManagement.base.decoratorBase"; -import { memo as memo } from \"arkui.stateManagement.runtime\"; -import { LinkDecoratedVariable as LinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorLink"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Component as Component } from \"@ohos.arkui.component\"; -import { Link as Link } from \"@ohos.arkui.stateManagement\"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorator"; + +import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component } from "@ohos.arkui.component"; + +import { Link as Link } from "@ohos.arkui.stateManagement"; + function main() {} -@Component({freezeWhenInactive:false}) final class LinkParent extends CustomComponent { + + + +@Component({freezeWhenInactive:false}) final struct LinkParent extends CustomComponent { public __initializeStruct(initializers: __Options_LinkParent | undefined, @memo() content: (()=> void) | undefined): void { - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar1)})) { - this.__backing_linkVar1 = new LinkDecoratedVariable(\"linkVar1\", initializers!.__backing_linkVar1!); + if (({let gensym___11910109 = initializers; + (((gensym___11910109) == (null)) ? undefined : gensym___11910109.__backing_linkVar1)})) { + this.__backing_linkVar1 = STATE_MGMT_FACTORY.makeLink(this, "linkVar1", initializers!.__backing_linkVar1!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar2)})) { - this.__backing_linkVar2 = new LinkDecoratedVariable(\"linkVar2\", initializers!.__backing_linkVar2!); + if (({let gensym___181684045 = initializers; + (((gensym___181684045) == (null)) ? undefined : gensym___181684045.__backing_linkVar2)})) { + this.__backing_linkVar2 = STATE_MGMT_FACTORY.makeLink(this, "linkVar2", initializers!.__backing_linkVar2!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar3)})) { - this.__backing_linkVar3 = new LinkDecoratedVariable(\"linkVar3\", initializers!.__backing_linkVar3!); + if (({let gensym___24446313 = initializers; + (((gensym___24446313) == (null)) ? undefined : gensym___24446313.__backing_linkVar3)})) { + this.__backing_linkVar3 = STATE_MGMT_FACTORY.makeLink(this, "linkVar3", initializers!.__backing_linkVar3!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar4)})) { - this.__backing_linkVar4 = new LinkDecoratedVariable(\"linkVar4\", initializers!.__backing_linkVar4!); + if (({let gensym___167989826 = initializers; + (((gensym___167989826) == (null)) ? undefined : gensym___167989826.__backing_linkVar4)})) { + this.__backing_linkVar4 = STATE_MGMT_FACTORY.makeLink(this, "linkVar4", initializers!.__backing_linkVar4!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar5)})) { - this.__backing_linkVar5 = new LinkDecoratedVariable(\"linkVar5\", initializers!.__backing_linkVar5!); + if (({let gensym___157566097 = initializers; + (((gensym___157566097) == (null)) ? undefined : gensym___157566097.__backing_linkVar5)})) { + this.__backing_linkVar5 = STATE_MGMT_FACTORY.makeLink(this, "linkVar5", initializers!.__backing_linkVar5!); }; } + public __updateStruct(initializers: __Options_LinkParent | undefined): void {} - private __backing_linkVar1?: LinkDecoratedVariable; + + private __backing_linkVar1?: ILinkDecoratedVariable; + public get linkVar1(): string { return this.__backing_linkVar1!.get(); } + public set linkVar1(value: string) { this.__backing_linkVar1!.set(value); } - private __backing_linkVar2?: LinkDecoratedVariable; + + private __backing_linkVar2?: ILinkDecoratedVariable; + public get linkVar2(): number { return this.__backing_linkVar2!.get(); } + public set linkVar2(value: number) { this.__backing_linkVar2!.set(value); } - private __backing_linkVar3?: LinkDecoratedVariable; + + private __backing_linkVar3?: ILinkDecoratedVariable; + public get linkVar3(): boolean { return this.__backing_linkVar3!.get(); } + public set linkVar3(value: boolean) { this.__backing_linkVar3!.set(value); } - private __backing_linkVar4?: LinkDecoratedVariable; + + private __backing_linkVar4?: ILinkDecoratedVariable; + public get linkVar4(): undefined { return this.__backing_linkVar4!.get(); } + public set linkVar4(value: undefined) { this.__backing_linkVar4!.set(value); } - private __backing_linkVar5?: LinkDecoratedVariable; + + private __backing_linkVar5?: ILinkDecoratedVariable; + public get linkVar5(): null { return this.__backing_linkVar5!.get(); } + public set linkVar5(value: null) { this.__backing_linkVar5!.set(value); } + @memo() public _build(@memo() style: ((instance: LinkParent)=> LinkParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_LinkParent | undefined): void {} + private constructor() {} + } -@Retention({policy:\"SOURCE\"}) @interface __Link_intrinsic {} +@Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} @Component({freezeWhenInactive:false}) export interface __Options_LinkParent { @__Link_intrinsic() set linkVar1(linkVar1: string | undefined) + @__Link_intrinsic() get linkVar1(): string | undefined - set __backing_linkVar1(__backing_linkVar1: DecoratedV1VariableBase | undefined) - get __backing_linkVar1(): DecoratedV1VariableBase | undefined + set __backing_linkVar1(__backing_linkVar1: LinkSourceType | undefined) + + get __backing_linkVar1(): LinkSourceType | undefined @__Link_intrinsic() set linkVar2(linkVar2: number | undefined) + @__Link_intrinsic() get linkVar2(): number | undefined - set __backing_linkVar2(__backing_linkVar2: DecoratedV1VariableBase | undefined) - get __backing_linkVar2(): DecoratedV1VariableBase | undefined + set __backing_linkVar2(__backing_linkVar2: LinkSourceType | undefined) + + get __backing_linkVar2(): LinkSourceType | undefined @__Link_intrinsic() set linkVar3(linkVar3: boolean | undefined) + @__Link_intrinsic() get linkVar3(): boolean | undefined - set __backing_linkVar3(__backing_linkVar3: DecoratedV1VariableBase | undefined) - get __backing_linkVar3(): DecoratedV1VariableBase | undefined + set __backing_linkVar3(__backing_linkVar3: LinkSourceType | undefined) + + get __backing_linkVar3(): LinkSourceType | undefined @__Link_intrinsic() set linkVar4(linkVar4: undefined | undefined) + @__Link_intrinsic() get linkVar4(): undefined | undefined - set __backing_linkVar4(__backing_linkVar4: undefined | undefined) - get __backing_linkVar4(): undefined | undefined + set __backing_linkVar4(__backing_linkVar4: LinkSourceType | undefined) + + get __backing_linkVar4(): LinkSourceType | undefined @__Link_intrinsic() set linkVar5(linkVar5: null | undefined) + @__Link_intrinsic() get linkVar5(): null | undefined - set __backing_linkVar5(__backing_linkVar5: DecoratedV1VariableBase | undefined) - get __backing_linkVar5(): DecoratedV1VariableBase | undefined + set __backing_linkVar5(__backing_linkVar5: LinkSourceType | undefined) + + get __backing_linkVar5(): LinkSourceType | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts index fc1a40a2d29ab0a745ae49d41512c2cb527803e6..cd0241697f358fdce45ac573d8256ac8c1f2da06 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-complex-type.test.ts @@ -38,267 +38,358 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` -import { DecoratedV1VariableBase as DecoratedV1VariableBase } from "arkui.stateManagement.base.decoratorBase"; -import { memo as memo } from \"arkui.stateManagement.runtime\"; -import { LinkDecoratedVariable as LinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorLink"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Component as Component } from \"@ohos.arkui.component\"; -import { Link as Link } from \"@ohos.arkui.stateManagement\"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorator"; + +import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component } from "@ohos.arkui.component"; + +import { Link as Link } from "@ohos.arkui.stateManagement"; function main() {} + + class Per { public num: number; + public constructor(num: number) { this.num = num; } -} +} + final class LinkType extends BaseEnum { private readonly #ordinal: int; + private static () {} + public constructor(ordinal: int, value: int) { super(value); this.#ordinal = ordinal; } - + public static readonly TYPE1: LinkType = new LinkType(0, 0); + public static readonly TYPE2: LinkType = new LinkType(1, 1); + public static readonly TYPE3: LinkType = new LinkType(2, 3); - private static readonly #NamesArray: String[] = [\"TYPE1\", \"TYPE2\", \"TYPE3\"]; + + private static readonly #NamesArray: String[] = ["TYPE1", "TYPE2", "TYPE3"]; + private static readonly #ValuesArray: int[] = [0, 1, 3]; - private static readonly #StringValuesArray: String[] = [\"0\", \"1\", \"3\"]; + + private static readonly #StringValuesArray: String[] = ["0", "1", "3"]; + private static readonly #ItemsArray: LinkType[] = [LinkType.TYPE1, LinkType.TYPE2, LinkType.TYPE3]; - + public getName(): String { return LinkType.#NamesArray[this.#ordinal]; } - + public static getValueOf(name: String): LinkType { for (let i = 0;((i) < (LinkType.#NamesArray.length));(++i)) { if (((name) == (LinkType.#NamesArray[i]))) { return LinkType.#ItemsArray[i]; } } - throw new Error(((\"No enum constant LinkType.\") + (name))); + throw new Error((("No enum constant LinkType.") + (name))); } - + public static fromValue(value: int): LinkType { for (let i = 0;((i) < (LinkType.#ValuesArray.length));(++i)) { if (((value) == (LinkType.#ValuesArray[i]))) { return LinkType.#ItemsArray[i]; } } - throw new Error(((\"No enum LinkType with value \") + (value))); + throw new Error((("No enum LinkType with value ") + (value))); } + public valueOf(): int { return LinkType.#ValuesArray[this.#ordinal]; } + public toString(): String { return LinkType.#StringValuesArray[this.#ordinal]; } + public static values(): LinkType[] { return LinkType.#ItemsArray; } + public getOrdinal(): int { return this.#ordinal; } + public static $_get(e: LinkType): String { return e.getName(); } + } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar1)})) { - this.__backing_linkVar1 = new LinkDecoratedVariable(\"linkVar1\", initializers!.__backing_linkVar1!); + if (({let gensym___11910109 = initializers; + (((gensym___11910109) == (null)) ? undefined : gensym___11910109.__backing_linkVar1)})) { + this.__backing_linkVar1 = STATE_MGMT_FACTORY.makeLink(this, "linkVar1", initializers!.__backing_linkVar1!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar2)})) { - this.__backing_linkVar2 = new LinkDecoratedVariable>(\"linkVar2\", initializers!.__backing_linkVar2!); + if (({let gensym___181684045 = initializers; + (((gensym___181684045) == (null)) ? undefined : gensym___181684045.__backing_linkVar2)})) { + this.__backing_linkVar2 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar2", initializers!.__backing_linkVar2!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar3)})) { - this.__backing_linkVar3 = new LinkDecoratedVariable(\"linkVar3\", initializers!.__backing_linkVar3!); + if (({let gensym___24446313 = initializers; + (((gensym___24446313) == (null)) ? undefined : gensym___24446313.__backing_linkVar3)})) { + this.__backing_linkVar3 = STATE_MGMT_FACTORY.makeLink(this, "linkVar3", initializers!.__backing_linkVar3!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar4)})) { - this.__backing_linkVar4 = new LinkDecoratedVariable>(\"linkVar4\", initializers!.__backing_linkVar4!); + if (({let gensym___167989826 = initializers; + (((gensym___167989826) == (null)) ? undefined : gensym___167989826.__backing_linkVar4)})) { + this.__backing_linkVar4 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar4", initializers!.__backing_linkVar4!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar5)})) { - this.__backing_linkVar5 = new LinkDecoratedVariable>(\"linkVar5\", initializers!.__backing_linkVar5!); + if (({let gensym___157566097 = initializers; + (((gensym___157566097) == (null)) ? undefined : gensym___157566097.__backing_linkVar5)})) { + this.__backing_linkVar5 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar5", initializers!.__backing_linkVar5!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar6)})) { - this.__backing_linkVar6 = new LinkDecoratedVariable>(\"linkVar6\", initializers!.__backing_linkVar6!); + if (({let gensym___60105491 = initializers; + (((gensym___60105491) == (null)) ? undefined : gensym___60105491.__backing_linkVar6)})) { + this.__backing_linkVar6 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar6", initializers!.__backing_linkVar6!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar7)})) { - this.__backing_linkVar7 = new LinkDecoratedVariable>(\"linkVar7\", initializers!.__backing_linkVar7!); + if (({let gensym___3429048 = initializers; + (((gensym___3429048) == (null)) ? undefined : gensym___3429048.__backing_linkVar7)})) { + this.__backing_linkVar7 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar7", initializers!.__backing_linkVar7!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar8)})) { - this.__backing_linkVar8 = new LinkDecoratedVariable<((sr: string)=> void)>(\"linkVar8\", initializers!.__backing_linkVar8!); + if (({let gensym___139916435 = initializers; + (((gensym___139916435) == (null)) ? undefined : gensym___139916435.__backing_linkVar8)})) { + this.__backing_linkVar8 = STATE_MGMT_FACTORY.makeLink<((sr: string)=> void)>(this, "linkVar8", initializers!.__backing_linkVar8!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar9)})) { - this.__backing_linkVar9 = new LinkDecoratedVariable(\"linkVar9\", initializers!.__backing_linkVar9!); + if (({let gensym___145003260 = initializers; + (((gensym___145003260) == (null)) ? undefined : gensym___145003260.__backing_linkVar9)})) { + this.__backing_linkVar9 = STATE_MGMT_FACTORY.makeLink(this, "linkVar9", initializers!.__backing_linkVar9!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar10)})) { - this.__backing_linkVar10 = new LinkDecoratedVariable>(\"linkVar10\", initializers!.__backing_linkVar10!); + if (({let gensym___122643185 = initializers; + (((gensym___122643185) == (null)) ? undefined : gensym___122643185.__backing_linkVar10)})) { + this.__backing_linkVar10 = STATE_MGMT_FACTORY.makeLink>(this, "linkVar10", initializers!.__backing_linkVar10!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar11)})) { - this.__backing_linkVar11 = new LinkDecoratedVariable(\"linkVar11\", initializers!.__backing_linkVar11!); + if (({let gensym___222468503 = initializers; + (((gensym___222468503) == (null)) ? undefined : gensym___222468503.__backing_linkVar11)})) { + this.__backing_linkVar11 = STATE_MGMT_FACTORY.makeLink(this, "linkVar11", initializers!.__backing_linkVar11!); }; - if (({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.__backing_linkVar12)})) { - this.__backing_linkVar12 = new LinkDecoratedVariable | Per>(\"linkVar12\", initializers!.__backing_linkVar12!); + if (({let gensym___243301539 = initializers; + (((gensym___243301539) == (null)) ? undefined : gensym___243301539.__backing_linkVar12)})) { + this.__backing_linkVar12 = STATE_MGMT_FACTORY.makeLink | Per>(this, "linkVar12", initializers!.__backing_linkVar12!); }; } + public __updateStruct(initializers: __Options_Parent | undefined): void {} - private __backing_linkVar1?: LinkDecoratedVariable; + + private __backing_linkVar1?: ILinkDecoratedVariable; + public get linkVar1(): Per { return this.__backing_linkVar1!.get(); } + public set linkVar1(value: Per) { this.__backing_linkVar1!.set(value); } - private __backing_linkVar2?: LinkDecoratedVariable>; + + private __backing_linkVar2?: ILinkDecoratedVariable>; + public get linkVar2(): Array { return this.__backing_linkVar2!.get(); } + public set linkVar2(value: Array) { this.__backing_linkVar2!.set(value); } - private __backing_linkVar3?: LinkDecoratedVariable; + + private __backing_linkVar3?: ILinkDecoratedVariable; + public get linkVar3(): LinkType { return this.__backing_linkVar3!.get(); } + public set linkVar3(value: LinkType) { this.__backing_linkVar3!.set(value); } - private __backing_linkVar4?: LinkDecoratedVariable>; + + private __backing_linkVar4?: ILinkDecoratedVariable>; + public get linkVar4(): Set { return this.__backing_linkVar4!.get(); } + public set linkVar4(value: Set) { this.__backing_linkVar4!.set(value); } - private __backing_linkVar5?: LinkDecoratedVariable>; + + private __backing_linkVar5?: ILinkDecoratedVariable>; + public get linkVar5(): Array { return this.__backing_linkVar5!.get(); } + public set linkVar5(value: Array) { this.__backing_linkVar5!.set(value); } - private __backing_linkVar6?: LinkDecoratedVariable>; + + private __backing_linkVar6?: ILinkDecoratedVariable>; + public get linkVar6(): Array { return this.__backing_linkVar6!.get(); } + public set linkVar6(value: Array) { this.__backing_linkVar6!.set(value); } - private __backing_linkVar7?: LinkDecoratedVariable>; + + private __backing_linkVar7?: ILinkDecoratedVariable>; + public get linkVar7(): Array { return this.__backing_linkVar7!.get(); } + public set linkVar7(value: Array) { this.__backing_linkVar7!.set(value); } - private __backing_linkVar8?: LinkDecoratedVariable<((sr: string)=> void)>; + + private __backing_linkVar8?: ILinkDecoratedVariable<((sr: string)=> void)>; + public get linkVar8(): ((sr: string)=> void) { return this.__backing_linkVar8!.get(); } + public set linkVar8(value: ((sr: string)=> void)) { this.__backing_linkVar8!.set(value); } - private __backing_linkVar9?: LinkDecoratedVariable; + + private __backing_linkVar9?: ILinkDecoratedVariable; + public get linkVar9(): Date { return this.__backing_linkVar9!.get(); } + public set linkVar9(value: Date) { this.__backing_linkVar9!.set(value); } - private __backing_linkVar10?: LinkDecoratedVariable>; + + private __backing_linkVar10?: ILinkDecoratedVariable>; + public get linkVar10(): Map { return this.__backing_linkVar10!.get(); } + public set linkVar10(value: Map) { this.__backing_linkVar10!.set(value); } - private __backing_linkVar11?: LinkDecoratedVariable; + + private __backing_linkVar11?: ILinkDecoratedVariable; + public get linkVar11(): string | number { return this.__backing_linkVar11!.get(); } + public set linkVar11(value: string | number) { this.__backing_linkVar11!.set(value); } - private __backing_linkVar12?: LinkDecoratedVariable | Per>; + + private __backing_linkVar12?: ILinkDecoratedVariable | Per>; + public get linkVar12(): Set | Per { return this.__backing_linkVar12!.get(); } + public set linkVar12(value: Set | Per) { this.__backing_linkVar12!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + private constructor() {} + } -@Retention({policy:\"SOURCE\"}) @interface __Link_intrinsic {} +@Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} @Component({freezeWhenInactive:false}) export interface __Options_Parent { @__Link_intrinsic() set linkVar1(linkVar1: Per | undefined) + @__Link_intrinsic() get linkVar1(): Per | undefined - set __backing_linkVar1(__backing_linkVar1: DecoratedV1VariableBase | undefined) - get __backing_linkVar1(): DecoratedV1VariableBase | undefined + set __backing_linkVar1(__backing_linkVar1: LinkSourceType | undefined) + + get __backing_linkVar1(): LinkSourceType | undefined @__Link_intrinsic() set linkVar2(linkVar2: Array | undefined) + @__Link_intrinsic() get linkVar2(): Array | undefined - set __backing_linkVar2(__backing_linkVar2: DecoratedV1VariableBase> | undefined) - get __backing_linkVar2(): DecoratedV1VariableBase> | undefined + set __backing_linkVar2(__backing_linkVar2: LinkSourceType> | undefined) + + get __backing_linkVar2(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar3(linkVar3: LinkType | undefined) + @__Link_intrinsic() get linkVar3(): LinkType | undefined - set __backing_linkVar3(__backing_linkVar3: DecoratedV1VariableBase | undefined) - get __backing_linkVar3(): DecoratedV1VariableBase | undefined + set __backing_linkVar3(__backing_linkVar3: LinkSourceType | undefined) + + get __backing_linkVar3(): LinkSourceType | undefined @__Link_intrinsic() set linkVar4(linkVar4: Set | undefined) + @__Link_intrinsic() get linkVar4(): Set | undefined - set __backing_linkVar4(__backing_linkVar4: DecoratedV1VariableBase> | undefined) - get __backing_linkVar4(): DecoratedV1VariableBase> | undefined + set __backing_linkVar4(__backing_linkVar4: LinkSourceType> | undefined) + + get __backing_linkVar4(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar5(linkVar5: Array | undefined) + @__Link_intrinsic() get linkVar5(): Array | undefined - set __backing_linkVar5(__backing_linkVar5: DecoratedV1VariableBase> | undefined) - get __backing_linkVar5(): DecoratedV1VariableBase> | undefined + set __backing_linkVar5(__backing_linkVar5: LinkSourceType> | undefined) + + get __backing_linkVar5(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar6(linkVar6: Array | undefined) + @__Link_intrinsic() get linkVar6(): Array | undefined - set __backing_linkVar6(__backing_linkVar6: DecoratedV1VariableBase> | undefined) - get __backing_linkVar6(): DecoratedV1VariableBase> | undefined + set __backing_linkVar6(__backing_linkVar6: LinkSourceType> | undefined) + + get __backing_linkVar6(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar7(linkVar7: Array | undefined) + @__Link_intrinsic() get linkVar7(): Array | undefined - set __backing_linkVar7(__backing_linkVar7: DecoratedV1VariableBase> | undefined) - get __backing_linkVar7(): DecoratedV1VariableBase> | undefined + set __backing_linkVar7(__backing_linkVar7: LinkSourceType> | undefined) + + get __backing_linkVar7(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar8(linkVar8: ((sr: string)=> void) | undefined) + @__Link_intrinsic() get linkVar8(): ((sr: string)=> void) | undefined - set __backing_linkVar8(__backing_linkVar8: DecoratedV1VariableBase<((sr: string)=> void)> | undefined) - get __backing_linkVar8(): DecoratedV1VariableBase<((sr: string)=> void)> | undefined + set __backing_linkVar8(__backing_linkVar8: LinkSourceType<((sr: string)=> void)> | undefined) + + get __backing_linkVar8(): LinkSourceType<((sr: string)=> void)> | undefined @__Link_intrinsic() set linkVar9(linkVar9: Date | undefined) + @__Link_intrinsic() get linkVar9(): Date | undefined - set __backing_linkVar9(__backing_linkVar9: DecoratedV1VariableBase | undefined) - get __backing_linkVar9(): DecoratedV1VariableBase | undefined + set __backing_linkVar9(__backing_linkVar9: LinkSourceType | undefined) + + get __backing_linkVar9(): LinkSourceType | undefined @__Link_intrinsic() set linkVar10(linkVar10: Map | undefined) + @__Link_intrinsic() get linkVar10(): Map | undefined - set __backing_linkVar10(__backing_linkVar10: DecoratedV1VariableBase> | undefined) - get __backing_linkVar10(): DecoratedV1VariableBase> | undefined + set __backing_linkVar10(__backing_linkVar10: LinkSourceType> | undefined) + + get __backing_linkVar10(): LinkSourceType> | undefined @__Link_intrinsic() set linkVar11(linkVar11: string | number | undefined) + @__Link_intrinsic() get linkVar11(): string | number | undefined - set __backing_linkVar11(__backing_linkVar11: DecoratedV1VariableBase | DecoratedV1VariableBase | undefined) - get __backing_linkVar11(): DecoratedV1VariableBase | DecoratedV1VariableBase | undefined + set __backing_linkVar11(__backing_linkVar11: LinkSourceType | undefined) + + get __backing_linkVar11(): LinkSourceType | undefined @__Link_intrinsic() set linkVar12(linkVar12: Set | Per | undefined) + @__Link_intrinsic() get linkVar12(): Set | Per | undefined - set __backing_linkVar12(__backing_linkVar12: DecoratedV1VariableBase> | DecoratedV1VariableBase | undefined) - get __backing_linkVar12(): DecoratedV1VariableBase> | DecoratedV1VariableBase | undefined + set __backing_linkVar12(__backing_linkVar12: LinkSourceType | Per> | undefined) + + get __backing_linkVar12(): LinkSourceType | Per> | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts index bc491c7bc987154628025dba354a7a52ed21010d..14617528341d80a7214158c2a670efa6b084986c 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/link-to-link-prop-state.test.ts @@ -38,32 +38,49 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` -import { DecoratedV1VariableBase as DecoratedV1VariableBase } from "arkui.stateManagement.base.decoratorBase"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { LinkDecoratedVariable as LinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorLink"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorator"; + +import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Column as Column, TextInput as TextInput } from "@ohos.arkui.component"; + import { Link as Link, State as State, Prop as Prop } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class Parant extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct Parant extends CustomComponent { public __initializeStruct(initializers: __Options_Parant | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___10127521 = initializers; (((gensym___10127521) == (null)) ? undefined : gensym___10127521.__backing_text1)})) { - this.__backing_text1 = new LinkDecoratedVariable("text1", initializers!.__backing_text1!); + this.__backing_text1 = STATE_MGMT_FACTORY.makeLink(this, "text1", initializers!.__backing_text1!); }; } + public __updateStruct(initializers: __Options_Parant | undefined): void {} - private __backing_text1?: LinkDecoratedVariable; + + private __backing_text1?: ILinkDecoratedVariable; + public get text1(): string { return this.__backing_text1!.get(); } + public set text1(value: string) { this.__backing_text1!.set(value); } + @memo() public _build(@memo() style: ((instance: Parant)=> Parant) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parant | undefined): void { Column(undefined, (() => { TextInput(undefined, { @@ -79,21 +96,24 @@ function main() {} } as __Options_Child)); })); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) final class Child extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___161337494 = initializers; (((gensym___161337494) == (null)) ? undefined : gensym___161337494.__backing_childText)})) { - this.__backing_childText = new LinkDecoratedVariable("childText", initializers!.__backing_childText!); + this.__backing_childText = STATE_MGMT_FACTORY.makeLink(this, "childText", initializers!.__backing_childText!); }; - this.__backing_childText2 = new StateDecoratedVariable("childText2", ((({let gensym___95513066 = initializers; + this.__backing_childText2 = STATE_MGMT_FACTORY.makeState(this, "childText2", ((({let gensym___95513066 = initializers; (((gensym___95513066) == (null)) ? undefined : gensym___95513066.childText2)})) ?? ("sss"))); - this.__backing_childText3 = new PropDecoratedVariable("childText3", (initializers!.childText3 as string)); - this.__backing_childText4 = new PropDecoratedVariable("childText4", ((({let gensym___162028107 = initializers; + this.__backing_childText3 = STATE_MGMT_FACTORY.makeProp(this, "childText3", (initializers!.childText3 as string)); + this.__backing_childText4 = STATE_MGMT_FACTORY.makeProp(this, "childText4", ((({let gensym___162028107 = initializers; (((gensym___162028107) == (null)) ? undefined : gensym___162028107.childText4)})) ?? ("cc"))); } + public __updateStruct(initializers: __Options_Child | undefined): void { if (((({let gensym___77632518 = initializers; (((gensym___77632518) == (null)) ? undefined : gensym___77632518.childText3)})) !== (undefined))) { @@ -104,68 +124,95 @@ function main() {} this.__backing_childText4!.update((initializers!.childText4 as string)); } } - private __backing_childText?: LinkDecoratedVariable; + + private __backing_childText?: ILinkDecoratedVariable; + public get childText(): string { return this.__backing_childText!.get(); } + public set childText(value: string) { this.__backing_childText!.set(value); } - private __backing_childText2?: StateDecoratedVariable; + + private __backing_childText2?: IStateDecoratedVariable; + public get childText2(): string { return this.__backing_childText2!.get(); } + public set childText2(value: string) { this.__backing_childText2!.set(value); } - private __backing_childText3?: PropDecoratedVariable; + + private __backing_childText3?: IPropDecoratedVariable; + public get childText3(): string { return this.__backing_childText3!.get(); } + public set childText3(value: string) { this.__backing_childText3!.set(value); } - private __backing_childText4?: PropDecoratedVariable; + + private __backing_childText4?: IPropDecoratedVariable; + public get childText4(): string { return this.__backing_childText4!.get(); } + public set childText4(value: string) { this.__backing_childText4!.set(value); } + @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { TextInput(undefined, { text: this.childText, }); } + private constructor() {} + } @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} @Component({freezeWhenInactive:false}) export interface __Options_Parant { @__Link_intrinsic() set text1(text1: string | undefined) + @__Link_intrinsic() get text1(): string | undefined - set __backing_text1(__backing_text1: DecoratedV1VariableBase | undefined) - get __backing_text1(): DecoratedV1VariableBase | undefined + set __backing_text1(__backing_text1: LinkSourceType | undefined) + + get __backing_text1(): LinkSourceType | undefined + } @Component({freezeWhenInactive:false}) export interface __Options_Child { @__Link_intrinsic() set childText(childText: string | undefined) + @__Link_intrinsic() get childText(): string | undefined - set __backing_childText(__backing_childText: DecoratedV1VariableBase | undefined) - get __backing_childText(): DecoratedV1VariableBase | undefined + set __backing_childText(__backing_childText: LinkSourceType | undefined) + + get __backing_childText(): LinkSourceType | undefined set childText2(childText2: string | undefined) + get childText2(): string | undefined - set __backing_childText2(__backing_childText2: StateDecoratedVariable | undefined) - get __backing_childText2(): StateDecoratedVariable | undefined + set __backing_childText2(__backing_childText2: IStateDecoratedVariable | undefined) + + get __backing_childText2(): IStateDecoratedVariable | undefined set childText3(childText3: string | undefined) + get childText3(): string | undefined - set __backing_childText3(__backing_childText3: PropDecoratedVariable | undefined) - get __backing_childText3(): PropDecoratedVariable | undefined + set __backing_childText3(__backing_childText3: IPropDecoratedVariable | undefined) + + get __backing_childText3(): IPropDecoratedVariable | undefined set childText4(childText4: string | undefined) + get childText4(): string | undefined - set __backing_childText4(__backing_childText4: PropDecoratedVariable | undefined) - get __backing_childText4(): PropDecoratedVariable | undefined + set __backing_childText4(__backing_childText4: IPropDecoratedVariable | undefined) + + get __backing_childText4(): IPropDecoratedVariable | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts index 6bd6d0a594faf66a431596f63bc5b5d38cfc440d..52ac8cf9772482cf98a40e3ac87a47d96551f5d8 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/link/state-to-link.test.ts @@ -38,42 +38,60 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` -import { DecoratedV1VariableBase as DecoratedV1VariableBase } from "arkui.stateManagement.base.decoratorBase"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; -import { LinkDecoratedVariable as LinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorLink"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UIButtonAttribute as UIButtonAttribute } from "arkui.component.button"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorator"; + +import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry, Column as Column, Button as Button, DatePicker as DatePicker, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + import { Link as Link, State as State } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class DateComponent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct DateComponent extends CustomComponent { public __initializeStruct(initializers: __Options_DateComponent | undefined, @memo() content: (()=> void) | undefined): void { if (({let gensym___164314175 = initializers; (((gensym___164314175) == (null)) ? undefined : gensym___164314175.__backing_selectedDate)})) { - this.__backing_selectedDate = new LinkDecoratedVariable("selectedDate", initializers!.__backing_selectedDate!); + this.__backing_selectedDate = STATE_MGMT_FACTORY.makeLink(this, "selectedDate", initializers!.__backing_selectedDate!); }; } + public __updateStruct(initializers: __Options_DateComponent | undefined): void {} - private __backing_selectedDate?: LinkDecoratedVariable; + + private __backing_selectedDate?: ILinkDecoratedVariable; + public get selectedDate(): Date { return this.__backing_selectedDate!.get(); } + public set selectedDate(value: Date) { this.__backing_selectedDate!.set(value); } + @memo() public _build(@memo() style: ((instance: DateComponent)=> DateComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_DateComponent | undefined): void { Column(undefined, (() => { - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { this.selectedDate.setFullYear(((this.selectedDate.getFullYear()) + (1))); })); return; }), "child increase the year by 1"); - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.margin(10).onClick(((e: ClickEvent) => { this.selectedDate = new Date("2023-09-09"); })); @@ -86,32 +104,38 @@ function main() {} }); })); } + private constructor() {} } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class ParentComponent extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct ParentComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ParentComponent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_parentSelectedDate = new StateDecoratedVariable("parentSelectedDate", ((({let gensym___80922148 = initializers; + this.__backing_parentSelectedDate = STATE_MGMT_FACTORY.makeState(this, "parentSelectedDate", ((({let gensym___80922148 = initializers; (((gensym___80922148) == (null)) ? undefined : gensym___80922148.parentSelectedDate)})) ?? (new Date("2021-08-08")))); } + public __updateStruct(initializers: __Options_ParentComponent | undefined): void {} - private __backing_parentSelectedDate?: StateDecoratedVariable; + + private __backing_parentSelectedDate?: IStateDecoratedVariable; + public get parentSelectedDate(): Date { return this.__backing_parentSelectedDate!.get(); } + public set parentSelectedDate(value: Date) { this.__backing_parentSelectedDate!.set(value); } + @memo() public _build(@memo() style: ((instance: ParentComponent)=> ParentComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ParentComponent | undefined): void { Column(undefined, (() => { - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.margin(10).onClick(((e: ClickEvent) => { this.parentSelectedDate.setMonth(((this.parentSelectedDate.getMonth()) + (1))); })); return; }), "parent increase the month by 1"); - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.margin(10).onClick(((e: ClickEvent) => { this.parentSelectedDate = new Date("2023-07-07"); })); @@ -129,23 +153,31 @@ function main() {} } as __Options_DateComponent)); })); } + private constructor() {} + } @Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} @Component({freezeWhenInactive:false}) export interface __Options_DateComponent { @__Link_intrinsic() set selectedDate(selectedDate: Date | undefined) + @__Link_intrinsic() get selectedDate(): Date | undefined - set __backing_selectedDate(__backing_selectedDate: DecoratedV1VariableBase | undefined) - get __backing_selectedDate(): DecoratedV1VariableBase | undefined + set __backing_selectedDate(__backing_selectedDate: LinkSourceType | undefined) + + get __backing_selectedDate(): LinkSourceType | undefined + } @Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_ParentComponent { set parentSelectedDate(parentSelectedDate: Date | undefined) + get parentSelectedDate(): Date | undefined - set __backing_parentSelectedDate(__backing_parentSelectedDate: StateDecoratedVariable | undefined) - get __backing_parentSelectedDate(): StateDecoratedVariable | undefined + set __backing_parentSelectedDate(__backing_parentSelectedDate: IStateDecoratedVariable | undefined) + + get __backing_parentSelectedDate(): IStateDecoratedVariable | undefined + } class __EntryWrapper extends EntryPoint { @@ -154,7 +186,9 @@ class __EntryWrapper extends EntryPoint { return new ParentComponent(); })); } + public constructor() {} + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..cacaf39252d69a95c64eaae9e14a93975d0b3dd2 --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-basic.test.ts @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as path from 'path'; +import { PluginTester } from '../../../../utils/plugin-tester'; +import { mockBuildConfig } from '../../../../utils/artkts-config'; +import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../../utils/path-config'; +import { parseDumpSrc } from '../../../../utils/parse-string'; +import { recheck, uiNoRecheck } from '../../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../../utils/shared-types'; +import { uiTransform } from '../../../../../ui-plugins'; +import { Plugins } from '../../../../../common/plugin-context'; + +const OBJECTLINK_DIR_PATH: string = 'decorators/objectlink'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, OBJECTLINK_DIR_PATH, 'objectlink-basic.ets'), +]; + +const objectlinkTrackTransform: Plugins = { + name: 'objectlink', + parsed: uiTransform().parsed, +} + +const pluginTester = new PluginTester('test objectlink basic transform', buildConfig); + +const expectedScript: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { IObjectLinkDecoratedVariable as IObjectLinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component } from "@ohos.arkui.component"; + +import { Observed as Observed, ObjectLink as ObjectLink } from "@ohos.arkui.stateManagement"; + +function main() {} + + + +@Observed() class A implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + + public addWatchSubscriber(watchId: WatchIdType): void { + this.subscribedWatches.addWatchSubscriber(watchId); + } + + public removeWatchSubscriber(watchId: WatchIdType): boolean { + return this.subscribedWatches.removeWatchSubscriber(watchId); + } + + public executeOnSubscribingWatches(propertyName: string): void { + this.subscribedWatches.executeOnSubscribingWatches(propertyName); + } + + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + public constructor() {} + +} + +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { + public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_objectlinkvar = STATE_MGMT_FACTORY.makeObjectLink(this, "objectlinkvar", ({let gensym___248819442 = initializers; + (((gensym___248819442) == (null)) ? undefined : gensym___248819442.objectlinkvar)})!) + } + + public __updateStruct(initializers: __Options_MyStateSample | undefined): void { + if (((({let gensym___97362509 = initializers; + (((gensym___97362509) == (null)) ? undefined : gensym___97362509.objectlinkvar)})) !== (undefined))) { + this.__backing_objectlinkvar!.update(initializers!.objectlinkvar!); + } + } + + private __backing_objectlinkvar?: IObjectLinkDecoratedVariable; + + public get objectlinkvar(): A { + return this.__backing_objectlinkvar!.get(); + } + + @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void {} + + private constructor() {} + +} + +@Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { + set objectlinkvar(objectlinkvar: A | undefined) + + get objectlinkvar(): A | undefined + set __backing_objectlinkvar(__backing_objectlinkvar: IObjectLinkDecoratedVariable | undefined) + + get __backing_objectlinkvar(): IObjectLinkDecoratedVariable | undefined + +} +`; + +function testObjectLinkTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test objectlink basic transform', + [objectlinkTrackTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testObjectLinkTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..aeef2da0e6b96cd8ee357502c400c5b3ff1615af --- /dev/null +++ b/arkui-plugins/test/ut/ui-plugins/decorators/objectlink/objectlink-observed.test.ts @@ -0,0 +1,300 @@ +/* + * Copyright (c) 2025 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. + */ + +import * as path from 'path'; +import { PluginTester } from '../../../../utils/plugin-tester'; +import { mockBuildConfig } from '../../../../utils/artkts-config'; +import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../../utils/path-config'; +import { parseDumpSrc } from '../../../../utils/parse-string'; +import { recheck, uiNoRecheck } from '../../../../utils/plugins'; +import { BuildConfig, PluginTestContext } from '../../../../utils/shared-types'; +import { uiTransform } from '../../../../../ui-plugins'; +import { Plugins } from '../../../../../common/plugin-context'; + +const OBJECTLINK_DIR_PATH: string = 'decorators/objectlink'; + +const buildConfig: BuildConfig = mockBuildConfig(); +buildConfig.compileFiles = [ + path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, OBJECTLINK_DIR_PATH, 'objectlink-observed.ets'), +]; + +const objectlinkTrackTransform: Plugins = { + name: 'objectlink', + parsed: uiTransform().parsed, +} + +const pluginTester = new PluginTester('test objectlink observed transform', buildConfig); + +const expectedScript: string = ` + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { IObjectLinkDecoratedVariable as IObjectLinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { EntryPoint as EntryPoint } from "arkui.UserView"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Component as Component, Entry as Entry, Column as Column, Button as Button, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + +import { State as State, ObjectLink as ObjectLink, Observed as Observed } from "@ohos.arkui.stateManagement"; + +function main() {} + + + +@Observed() class DateClass extends Date implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + + public addWatchSubscriber(watchId: WatchIdType): void { + this.subscribedWatches.addWatchSubscriber(watchId); + } + + public removeWatchSubscriber(watchId: WatchIdType): boolean { + return this.subscribedWatches.removeWatchSubscriber(watchId); + } + + public executeOnSubscribingWatches(propertyName: string): void { + this.subscribedWatches.executeOnSubscribingWatches(propertyName); + } + + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + public constructor(args: number | string) { + super(args); + } + +} + +@Observed() class NewDate implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); + + public addWatchSubscriber(watchId: WatchIdType): void { + this.subscribedWatches.addWatchSubscriber(watchId); + } + + public removeWatchSubscriber(watchId: WatchIdType): boolean { + return this.subscribedWatches.removeWatchSubscriber(watchId); + } + + public executeOnSubscribingWatches(propertyName: string): void { + this.subscribedWatches.executeOnSubscribingWatches(propertyName); + } + + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); + + private __backing_data: DateClass = new DateClass(11); + + public constructor(data: DateClass) { + this.data = data; + } + + public get data(): DateClass { + this.conditionalAddRef(this.__meta); + return this.__backing_data; + } + + public set data(newValue: DateClass) { + if (((this.__backing_data) !== (newValue))) { + this.__backing_data = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("data"); + } + } + +} + +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { + public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_label = ((({let gensym___171896504 = initializers; + (((gensym___171896504) == (null)) ? undefined : gensym___171896504.label)})) ?? ("date")); + this.__backing_data = STATE_MGMT_FACTORY.makeObjectLink(this, "data", ({let gensym___209155591 = initializers; + (((gensym___209155591) == (null)) ? undefined : gensym___209155591.data)})!) + } + + public __updateStruct(initializers: __Options_Child | undefined): void { + if (((({let gensym___232946400 = initializers; + (((gensym___232946400) == (null)) ? undefined : gensym___232946400.data)})) !== (undefined))) { + this.__backing_data!.update(initializers!.data!); + } + } + + private __backing_label?: string; + + public get label(): string { + return (this.__backing_label as string); + } + + public set label(value: string) { + this.__backing_label = value; + } + + private __backing_data?: IObjectLinkDecoratedVariable; + + public get data(): DateClass { + return this.__backing_data!.get(); + } + + @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { + Column(undefined, (() => { + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + this.data.setDate(((this.data.getDate()) + (1))); + })); + return; + }), "child increase the day by 1"); + })); + } + + private constructor() {} + +} + +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { + public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_newData = STATE_MGMT_FACTORY.makeState(this, "newData", ((({let gensym___225289068 = initializers; + (((gensym___225289068) == (null)) ? undefined : gensym___225289068.newData)})) ?? (new NewDate(new DateClass("2023-1-1"))))); + } + + public __updateStruct(initializers: __Options_Parent | undefined): void {} + + private __backing_newData?: IStateDecoratedVariable; + + public get newData(): NewDate { + return this.__backing_newData!.get(); + } + + public set newData(value: NewDate) { + this.__backing_newData!.set(value); + } + + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void { + Column(undefined, (() => { + Child._instantiateImpl(undefined, (() => { + return new Child(); + }), ({ + label: "date", + data: this.newData.data, + } as __Options_Child)); + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + this.newData.data = new DateClass("2023-07-07"); + })); + return; + }), "parent update the new date"); + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => { + this.newData = new NewDate(new DateClass("2023-08-20")); + })); + return; + }), "ViewB: this.newData = new NewDate(new DateClass('2023-08-20'))"); + })); + } + + private constructor() {} + +} + +@Component({freezeWhenInactive:false}) export interface __Options_Child { + set label(label: string | undefined) + + get label(): string | undefined + set data(data: DateClass | undefined) + + get data(): DateClass | undefined + set __backing_data(__backing_data: IObjectLinkDecoratedVariable | undefined) + + get __backing_data(): IObjectLinkDecoratedVariable | undefined + +} + +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_Parent { + set newData(newData: NewDate | undefined) + + get newData(): NewDate | undefined + set __backing_newData(__backing_newData: IStateDecoratedVariable | undefined) + + get __backing_newData(): IStateDecoratedVariable | undefined + +} + +class __EntryWrapper extends EntryPoint { + @memo() public entry(): void { + Parent._instantiateImpl(undefined, (() => { + return new Parent(); + })); + } + + public constructor() {} + +} +`; + +function testObjectLinkTransformer(this: PluginTestContext): void { + expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); +} + +pluginTester.run( + 'test objectlink observed transform', + [objectlinkTrackTransform, uiNoRecheck, recheck], + { + 'checked:ui-no-recheck': [testObjectLinkTransformer], + }, + { + stopAfter: 'checked', + } +); diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts index 447548b0560a3d9a55ebe4db0eff1eaf2f5437c0..d101740ce49b33f301bd82f5bd0a108a27c199f3 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-only.test.ts @@ -38,22 +38,35 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed only transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Observed as Observed } from "@ohos.arkui.stateManagement"; function main() {} -@Observed() class A implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class A implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -67,9 +80,19 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } - private __meta: MutableStateMeta = new MutableStateMeta("@Observe properties (no @Track)"); + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_propA: number = 1; @@ -78,38 +101,34 @@ function main() {} public constructor() {} public get propA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_propA; } public set propA(newValue: number) { if (((this.__backing_propA) !== (newValue))) { this.__backing_propA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("propA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("propA"); } } public get trackA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_trackA; } public set trackA(newValue: number) { if (((this.__backing_trackA) !== (newValue))) { this.__backing_trackA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("trackA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("trackA"); } } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -123,7 +142,6 @@ function main() {} @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { } - `; function testObservedOnlyTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts index bb84161904d7b033a6e4ff5ccdeb047e396bfd81..4f629bc8041d2c061745490d4467f793a64f6857 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-class-property.test.ts @@ -38,16 +38,27 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed track transform with class property', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { setObservationDepth as setObservationDepth } from "arkui.stateManagement.base.iObservedObject"; -import { BackingValue as BackingValue } from "arkui.stateManagement.base.backingValue"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; function main() {} @@ -59,8 +70,8 @@ class Info { } -class E implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +class E implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -74,36 +85,43 @@ class E implements IObservedObject { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } public propE: Info = new Info(); - private __backing_trackE: BackingValue = new BackingValue(new Info()); + private __backing_trackE: Info = new Info(); - private __meta_trackE: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_trackE: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get trackE(): Info { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_trackE.addRef(); - } - setObservationDepth(this.__backing_trackE.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_trackE.value; + this.conditionalAddRef(this.__meta_trackE); + return this.__backing_trackE; } public set trackE(newValue: Info) { - if (((this.__backing_trackE.value) !== (newValue))) { - this.__backing_trackE.value = newValue; - this.__meta_trackE.fireChange(); - this.executeOnSubscribingWatches("trackE"); + if (((this.__backing_trackE) !== (newValue))) { + this.__backing_trackE = newValue; + this.__meta_trackE.fireChange(); + this.executeOnSubscribingWatches("trackE"); } } } -@Observed() class E1 implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class E1 implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -117,51 +135,55 @@ class E implements IObservedObject { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } - private __meta: MutableStateMeta = new MutableStateMeta("@Observe properties (no @Track)"); + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_propE1: BackingValue = new BackingValue(new Info()); + private __backing_propE1: Info = new Info(); - private __backing_trackE1: BackingValue = new BackingValue(new Info()); + private __backing_trackE1: Info = new Info(); public constructor() {} public get propE1(): Info { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_propE1.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_propE1.value; + this.conditionalAddRef(this.__meta); + return this.__backing_propE1; } public set propE1(newValue: Info) { - if (((this.__backing_propE1.value) !== (newValue))) { - this.__backing_propE1.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("propE1"); + if (((this.__backing_propE1) !== (newValue))) { + this.__backing_propE1 = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("propE1"); } } public get trackE1(): Info { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_trackE1.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_trackE1.value; + this.conditionalAddRef(this.__meta); + return this.__backing_trackE1; } public set trackE1(newValue: Info) { - if (((this.__backing_trackE1.value) !== (newValue))) { - this.__backing_trackE1.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("trackE1"); + if (((this.__backing_trackE1) !== (newValue))) { + this.__backing_trackE1 = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("trackE1"); } } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts index 182a288c9ec1fbc910408bd2ac2730a9e4de3a01..88fe01b05226784825eb62f9a8d834b5175f5aa5 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-complex-type.test.ts @@ -38,17 +38,29 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed track transform with complex type', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { setObservationDepth as setObservationDepth } from "arkui.stateManagement.base.iObservedObject"; -import { BackingValue as BackingValue } from "arkui.stateManagement.base.backingValue"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry } from "@ohos.arkui.component"; + import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; function main() {} @@ -128,8 +140,8 @@ final class Status extends BaseEnum { } -@Observed() class mixed1 implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class mixed1 implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -143,51 +155,61 @@ final class Status extends BaseEnum { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } private __backing_numA: number = 33; - private __meta_numA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_stringA: string = "AA"; - private __meta_stringA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_booleanA: boolean = true; - private __meta_booleanA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_arrayA: BackingValue> = new BackingValue>([1, 2, 3]); + private __backing_arrayA: Array = [1, 2, 3]; - private __meta_arrayA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_objectA: BackingValue = new BackingValue({}); + private __backing_objectA: Object = {}; - private __meta_objectA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_dateA: BackingValue = new BackingValue(new Date("2021-08-08")); + private __backing_dateA: Date = new Date("2021-08-08"); - private __meta_dateA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_setA: BackingValue> = new BackingValue>(new Set()); + private __backing_setA: Set = new Set(); - private __meta_setA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_mapA: BackingValue> = new BackingValue>(new Map()); + private __backing_mapA: Map = new Map(); - private __meta_mapA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_unionA: string | undefined = ""; - private __meta_unionA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_classA: BackingValue = new BackingValue(new Person()); + private __backing_classA: Person = new Person(); - private __meta_classA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_enumA: BackingValue = new BackingValue(Status.NotFound); + private __backing_enumA: Status = Status.NotFound; - private __meta_enumA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public numB: number = 33; @@ -214,181 +236,152 @@ final class Status extends BaseEnum { public constructor() {} public get numA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_numA.addRef(); - } + this.conditionalAddRef(this.__meta_numA); return this.__backing_numA; } public set numA(newValue: number) { if (((this.__backing_numA) !== (newValue))) { this.__backing_numA = newValue; - this.__meta_numA.fireChange(); - this.executeOnSubscribingWatches("numA"); + this.__meta_numA.fireChange(); + this.executeOnSubscribingWatches("numA"); } } public get stringA(): string { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_stringA.addRef(); - } + this.conditionalAddRef(this.__meta_stringA); return this.__backing_stringA; } public set stringA(newValue: string) { if (((this.__backing_stringA) !== (newValue))) { this.__backing_stringA = newValue; - this.__meta_stringA.fireChange(); - this.executeOnSubscribingWatches("stringA"); + this.__meta_stringA.fireChange(); + this.executeOnSubscribingWatches("stringA"); } } public get booleanA(): boolean { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_booleanA.addRef(); - } + this.conditionalAddRef(this.__meta_booleanA); return this.__backing_booleanA; } public set booleanA(newValue: boolean) { if (((this.__backing_booleanA) !== (newValue))) { this.__backing_booleanA = newValue; - this.__meta_booleanA.fireChange(); - this.executeOnSubscribingWatches("booleanA"); + this.__meta_booleanA.fireChange(); + this.executeOnSubscribingWatches("booleanA"); } } public get arrayA(): Array { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_arrayA.addRef(); - } - setObservationDepth(this.__backing_arrayA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_arrayA.value; + this.conditionalAddRef(this.__meta_arrayA); + return this.__backing_arrayA; } public set arrayA(newValue: Array) { - if (((this.__backing_arrayA.value) !== (newValue))) { - this.__backing_arrayA.value = newValue; - this.__meta_arrayA.fireChange(); - this.executeOnSubscribingWatches("arrayA"); + if (((this.__backing_arrayA) !== (newValue))) { + this.__backing_arrayA = newValue; + this.__meta_arrayA.fireChange(); + this.executeOnSubscribingWatches("arrayA"); } } public get objectA(): Object { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_objectA.addRef(); - } - setObservationDepth(this.__backing_objectA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_objectA.value; + this.conditionalAddRef(this.__meta_objectA); + return this.__backing_objectA; } public set objectA(newValue: Object) { - if (((this.__backing_objectA.value) !== (newValue))) { - this.__backing_objectA.value = newValue; - this.__meta_objectA.fireChange(); - this.executeOnSubscribingWatches("objectA"); + if (((this.__backing_objectA) !== (newValue))) { + this.__backing_objectA = newValue; + this.__meta_objectA.fireChange(); + this.executeOnSubscribingWatches("objectA"); } } public get dateA(): Date { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_dateA.addRef(); - } - setObservationDepth(this.__backing_dateA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_dateA.value; + this.conditionalAddRef(this.__meta_dateA); + return this.__backing_dateA; } public set dateA(newValue: Date) { - if (((this.__backing_dateA.value) !== (newValue))) { - this.__backing_dateA.value = newValue; - this.__meta_dateA.fireChange(); - this.executeOnSubscribingWatches("dateA"); + if (((this.__backing_dateA) !== (newValue))) { + this.__backing_dateA = newValue; + this.__meta_dateA.fireChange(); + this.executeOnSubscribingWatches("dateA"); } } public get setA(): Set { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_setA.addRef(); - } - setObservationDepth(this.__backing_setA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_setA.value; + this.conditionalAddRef(this.__meta_setA); + return this.__backing_setA; } public set setA(newValue: Set) { - if (((this.__backing_setA.value) !== (newValue))) { - this.__backing_setA.value = newValue; - this.__meta_setA.fireChange(); - this.executeOnSubscribingWatches("setA"); + if (((this.__backing_setA) !== (newValue))) { + this.__backing_setA = newValue; + this.__meta_setA.fireChange(); + this.executeOnSubscribingWatches("setA"); } } public get mapA(): Map { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_mapA.addRef(); - } - setObservationDepth(this.__backing_mapA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_mapA.value; + this.conditionalAddRef(this.__meta_mapA); + return this.__backing_mapA; } public set mapA(newValue: Map) { - if (((this.__backing_mapA.value) !== (newValue))) { - this.__backing_mapA.value = newValue; - this.__meta_mapA.fireChange(); - this.executeOnSubscribingWatches("mapA"); + if (((this.__backing_mapA) !== (newValue))) { + this.__backing_mapA = newValue; + this.__meta_mapA.fireChange(); + this.executeOnSubscribingWatches("mapA"); } } public get unionA(): string | undefined { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_unionA.addRef(); - } + this.conditionalAddRef(this.__meta_unionA); return this.__backing_unionA; } public set unionA(newValue: string | undefined) { if (((this.__backing_unionA) !== (newValue))) { this.__backing_unionA = newValue; - this.__meta_unionA.fireChange(); - this.executeOnSubscribingWatches("unionA"); + this.__meta_unionA.fireChange(); + this.executeOnSubscribingWatches("unionA"); } } public get classA(): Person { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_classA.addRef(); - } - setObservationDepth(this.__backing_classA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_classA.value; + this.conditionalAddRef(this.__meta_classA); + return this.__backing_classA; } public set classA(newValue: Person) { - if (((this.__backing_classA.value) !== (newValue))) { - this.__backing_classA.value = newValue; - this.__meta_classA.fireChange(); - this.executeOnSubscribingWatches("classA"); + if (((this.__backing_classA) !== (newValue))) { + this.__backing_classA = newValue; + this.__meta_classA.fireChange(); + this.executeOnSubscribingWatches("classA"); } } public get enumA(): Status { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_enumA.addRef(); - } - setObservationDepth(this.__backing_enumA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_enumA.value; + this.conditionalAddRef(this.__meta_enumA); + return this.__backing_enumA; } public set enumA(newValue: Status) { - if (((this.__backing_enumA.value) !== (newValue))) { - this.__backing_enumA.value = newValue; - this.__meta_enumA.fireChange(); - this.executeOnSubscribingWatches("enumA"); + if (((this.__backing_enumA) !== (newValue))) { + this.__backing_enumA = newValue; + this.__meta_enumA.fireChange(); + this.executeOnSubscribingWatches("enumA"); } } } -@Observed() class mixed2 implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class mixed2 implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -402,9 +395,19 @@ final class Status extends BaseEnum { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } - private __meta: MutableStateMeta = new MutableStateMeta("@Observe properties (no @Track)"); + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_numA: number = 33; @@ -412,200 +415,171 @@ final class Status extends BaseEnum { private __backing_booleanA: boolean = true; - private __backing_arrayA: BackingValue> = new BackingValue>([1, 2, 3]); + private __backing_arrayA: Array = [1, 2, 3]; - private __backing_objectA: BackingValue = new BackingValue({}); + private __backing_objectA: Object = {}; - private __backing_dateA: BackingValue = new BackingValue(new Date("2021-08-08")); + private __backing_dateA: Date = new Date("2021-08-08"); - private __backing_setA: BackingValue> = new BackingValue>(new Set()); + private __backing_setA: Set = new Set(); - private __backing_mapA: BackingValue> = new BackingValue>(new Map()); + private __backing_mapA: Map = new Map(); private __backing_unionA: string | undefined = ""; - private __backing_classA: BackingValue = new BackingValue(new Person()); + private __backing_classA: Person = new Person(); - private __backing_enumA: BackingValue = new BackingValue(Status.NotFound); + private __backing_enumA: Status = Status.NotFound; public constructor() {} public get numA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_numA; } public set numA(newValue: number) { if (((this.__backing_numA) !== (newValue))) { this.__backing_numA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("numA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("numA"); } } public get stringA(): string { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_stringA; } public set stringA(newValue: string) { if (((this.__backing_stringA) !== (newValue))) { this.__backing_stringA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("stringA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("stringA"); } } public get booleanA(): boolean { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_booleanA; } public set booleanA(newValue: boolean) { if (((this.__backing_booleanA) !== (newValue))) { this.__backing_booleanA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("booleanA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("booleanA"); } } public get arrayA(): Array { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_arrayA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_arrayA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_arrayA; } public set arrayA(newValue: Array) { - if (((this.__backing_arrayA.value) !== (newValue))) { - this.__backing_arrayA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("arrayA"); + if (((this.__backing_arrayA) !== (newValue))) { + this.__backing_arrayA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("arrayA"); } } public get objectA(): Object { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_objectA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_objectA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_objectA; } public set objectA(newValue: Object) { - if (((this.__backing_objectA.value) !== (newValue))) { - this.__backing_objectA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("objectA"); + if (((this.__backing_objectA) !== (newValue))) { + this.__backing_objectA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("objectA"); } } public get dateA(): Date { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_dateA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_dateA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_dateA; } public set dateA(newValue: Date) { - if (((this.__backing_dateA.value) !== (newValue))) { - this.__backing_dateA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("dateA"); + if (((this.__backing_dateA) !== (newValue))) { + this.__backing_dateA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("dateA"); } } public get setA(): Set { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_setA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_setA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_setA; } public set setA(newValue: Set) { - if (((this.__backing_setA.value) !== (newValue))) { - this.__backing_setA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("setA"); + if (((this.__backing_setA) !== (newValue))) { + this.__backing_setA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("setA"); } } public get mapA(): Map { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_mapA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_mapA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_mapA; } public set mapA(newValue: Map) { - if (((this.__backing_mapA.value) !== (newValue))) { - this.__backing_mapA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("mapA"); + if (((this.__backing_mapA) !== (newValue))) { + this.__backing_mapA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("mapA"); } } public get unionA(): string | undefined { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_unionA; } public set unionA(newValue: string | undefined) { if (((this.__backing_unionA) !== (newValue))) { this.__backing_unionA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("unionA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("unionA"); } } public get classA(): Person { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_classA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_classA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_classA; } public set classA(newValue: Person) { - if (((this.__backing_classA.value) !== (newValue))) { - this.__backing_classA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("classA"); + if (((this.__backing_classA) !== (newValue))) { + this.__backing_classA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("classA"); } } public get enumA(): Status { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } - setObservationDepth(this.__backing_enumA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_enumA.value; + this.conditionalAddRef(this.__meta); + return this.__backing_enumA; } public set enumA(newValue: Status) { - if (((this.__backing_enumA.value) !== (newValue))) { - this.__backing_enumA.value = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("enumA"); + if (((this.__backing_enumA) !== (newValue))) { + this.__backing_enumA = newValue; + this.__meta.fireChange(); + this.executeOnSubscribingWatches("enumA"); } } } -class mixed3 implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +class mixed3 implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -619,229 +593,210 @@ class mixed3 implements IObservedObject { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } private __backing_numA: number = 33; - private __meta_numA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_numA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_stringA: string = "AA"; - private __meta_stringA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_stringA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_booleanA: boolean = true; - private __meta_booleanA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_booleanA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_arrayA: BackingValue> = new BackingValue>([1, 2, 3]); + private __backing_arrayA: Array = [1, 2, 3]; - private __meta_arrayA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_arrayA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_objectA: BackingValue = new BackingValue({}); + private __backing_objectA: Object = {}; - private __meta_objectA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_objectA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_dateA: BackingValue = new BackingValue(new Date("2021-08-08")); + private __backing_dateA: Date = new Date("2021-08-08"); - private __meta_dateA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_dateA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_setA: BackingValue> = new BackingValue>(new Set()); + private __backing_setA: Set = new Set(); - private __meta_setA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_setA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_mapA: BackingValue> = new BackingValue>(new Map()); + private __backing_mapA: Map = new Map(); - private __meta_mapA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_mapA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_unionA: string | undefined = ""; - private __meta_unionA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_unionA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_classA: BackingValue = new BackingValue(new Person()); + private __backing_classA: Person = new Person(); - private __meta_classA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_classA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); - private __backing_enumA: BackingValue = new BackingValue(Status.NotFound); + private __backing_enumA: Status = Status.NotFound; - private __meta_enumA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_enumA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get numA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_numA.addRef(); - } + this.conditionalAddRef(this.__meta_numA); return this.__backing_numA; } public set numA(newValue: number) { if (((this.__backing_numA) !== (newValue))) { this.__backing_numA = newValue; - this.__meta_numA.fireChange(); - this.executeOnSubscribingWatches("numA"); + this.__meta_numA.fireChange(); + this.executeOnSubscribingWatches("numA"); } } public get stringA(): string { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_stringA.addRef(); - } + this.conditionalAddRef(this.__meta_stringA); return this.__backing_stringA; } public set stringA(newValue: string) { if (((this.__backing_stringA) !== (newValue))) { this.__backing_stringA = newValue; - this.__meta_stringA.fireChange(); - this.executeOnSubscribingWatches("stringA"); + this.__meta_stringA.fireChange(); + this.executeOnSubscribingWatches("stringA"); } } public get booleanA(): boolean { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_booleanA.addRef(); - } + this.conditionalAddRef(this.__meta_booleanA); return this.__backing_booleanA; } public set booleanA(newValue: boolean) { if (((this.__backing_booleanA) !== (newValue))) { this.__backing_booleanA = newValue; - this.__meta_booleanA.fireChange(); - this.executeOnSubscribingWatches("booleanA"); + this.__meta_booleanA.fireChange(); + this.executeOnSubscribingWatches("booleanA"); } } public get arrayA(): Array { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_arrayA.addRef(); - } - setObservationDepth(this.__backing_arrayA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_arrayA.value; + this.conditionalAddRef(this.__meta_arrayA); + return this.__backing_arrayA; } public set arrayA(newValue: Array) { - if (((this.__backing_arrayA.value) !== (newValue))) { - this.__backing_arrayA.value = newValue; - this.__meta_arrayA.fireChange(); - this.executeOnSubscribingWatches("arrayA"); + if (((this.__backing_arrayA) !== (newValue))) { + this.__backing_arrayA = newValue; + this.__meta_arrayA.fireChange(); + this.executeOnSubscribingWatches("arrayA"); } } public get objectA(): Object { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_objectA.addRef(); - } - setObservationDepth(this.__backing_objectA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_objectA.value; + this.conditionalAddRef(this.__meta_objectA); + return this.__backing_objectA; } public set objectA(newValue: Object) { - if (((this.__backing_objectA.value) !== (newValue))) { - this.__backing_objectA.value = newValue; - this.__meta_objectA.fireChange(); - this.executeOnSubscribingWatches("objectA"); + if (((this.__backing_objectA) !== (newValue))) { + this.__backing_objectA = newValue; + this.__meta_objectA.fireChange(); + this.executeOnSubscribingWatches("objectA"); } } public get dateA(): Date { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_dateA.addRef(); - } - setObservationDepth(this.__backing_dateA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_dateA.value; + this.conditionalAddRef(this.__meta_dateA); + return this.__backing_dateA; } public set dateA(newValue: Date) { - if (((this.__backing_dateA.value) !== (newValue))) { - this.__backing_dateA.value = newValue; - this.__meta_dateA.fireChange(); - this.executeOnSubscribingWatches("dateA"); + if (((this.__backing_dateA) !== (newValue))) { + this.__backing_dateA = newValue; + this.__meta_dateA.fireChange(); + this.executeOnSubscribingWatches("dateA"); } } public get setA(): Set { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_setA.addRef(); - } - setObservationDepth(this.__backing_setA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_setA.value; + this.conditionalAddRef(this.__meta_setA); + return this.__backing_setA; } public set setA(newValue: Set) { - if (((this.__backing_setA.value) !== (newValue))) { - this.__backing_setA.value = newValue; - this.__meta_setA.fireChange(); - this.executeOnSubscribingWatches("setA"); + if (((this.__backing_setA) !== (newValue))) { + this.__backing_setA = newValue; + this.__meta_setA.fireChange(); + this.executeOnSubscribingWatches("setA"); } } public get mapA(): Map { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_mapA.addRef(); - } - setObservationDepth(this.__backing_mapA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_mapA.value; + this.conditionalAddRef(this.__meta_mapA); + return this.__backing_mapA; } public set mapA(newValue: Map) { - if (((this.__backing_mapA.value) !== (newValue))) { - this.__backing_mapA.value = newValue; - this.__meta_mapA.fireChange(); - this.executeOnSubscribingWatches("mapA"); + if (((this.__backing_mapA) !== (newValue))) { + this.__backing_mapA = newValue; + this.__meta_mapA.fireChange(); + this.executeOnSubscribingWatches("mapA"); } } public get unionA(): string | undefined { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_unionA.addRef(); - } + this.conditionalAddRef(this.__meta_unionA); return this.__backing_unionA; } public set unionA(newValue: string | undefined) { if (((this.__backing_unionA) !== (newValue))) { this.__backing_unionA = newValue; - this.__meta_unionA.fireChange(); - this.executeOnSubscribingWatches("unionA"); + this.__meta_unionA.fireChange(); + this.executeOnSubscribingWatches("unionA"); } } public get classA(): Person { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_classA.addRef(); - } - setObservationDepth(this.__backing_classA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_classA.value; + this.conditionalAddRef(this.__meta_classA); + return this.__backing_classA; } public set classA(newValue: Person) { - if (((this.__backing_classA.value) !== (newValue))) { - this.__backing_classA.value = newValue; - this.__meta_classA.fireChange(); - this.executeOnSubscribingWatches("classA"); + if (((this.__backing_classA) !== (newValue))) { + this.__backing_classA = newValue; + this.__meta_classA.fireChange(); + this.executeOnSubscribingWatches("classA"); } } public get enumA(): Status { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_enumA.addRef(); - } - setObservationDepth(this.__backing_enumA.value, ((this._permissibleAddRefDepth) - (1))); - return this.__backing_enumA.value; + this.conditionalAddRef(this.__meta_enumA); + return this.__backing_enumA; } public set enumA(newValue: Status) { - if (((this.__backing_enumA.value) !== (newValue))) { - this.__backing_enumA.value = newValue; - this.__meta_enumA.fireChange(); - this.executeOnSubscribingWatches("enumA"); + if (((this.__backing_enumA) !== (newValue))) { + this.__backing_enumA = newValue; + this.__meta_enumA.fireChange(); + this.executeOnSubscribingWatches("enumA"); } } } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts index dc566ba3252918034fc4299bfb7d4e2c9dff118f..468efab24c5f92c134fac7118a6d588736e20c6d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-extends.test.ts @@ -38,22 +38,35 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed track transform with extends', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; function main() {} -@Observed() class A implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class A implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -67,9 +80,19 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; - private __meta: MutableStateMeta = new MutableStateMeta("@Observe properties (no @Track)"); + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_propA: number = 1; @@ -78,32 +101,28 @@ function main() {} public constructor() {} public get propA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_propA; } public set propA(newValue: number) { if (((this.__backing_propA) !== (newValue))) { this.__backing_propA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("propA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("propA"); } } public get trackA(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_trackA; } public set trackA(newValue: number) { if (((this.__backing_trackA) !== (newValue))) { this.__backing_trackA = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("trackA"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("trackA"); } } @@ -116,8 +135,8 @@ class G extends A { } -@Observed() class H extends G implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class H extends G implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -131,32 +150,40 @@ class G extends A { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } private __backing_propG: number = 1; - private __meta_propG: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_propG: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get propG(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_propG.addRef(); - } + this.conditionalAddRef(this.__meta_propG); return this.__backing_propG; } public set propG(newValue: number) { if (((this.__backing_propG) !== (newValue))) { this.__backing_propG = newValue; - this.__meta_propG.fireChange(); - this.executeOnSubscribingWatches("propG"); + this.__meta_propG.fireChange(); + this.executeOnSubscribingWatches("propG"); } } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -170,7 +197,6 @@ class G extends A { @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { } - `; function testObservedOnlyTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts index 5525cb1ae4c7274a66ba56455b2799a193f9074b..8b0a9b8ef20f4b2e804df937e904b98548c9b142 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track-implements.test.ts @@ -38,14 +38,27 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed track transform with implements', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Observed as Observed } from "@ohos.arkui.stateManagement"; function main() {} @@ -66,8 +79,8 @@ interface trackInterface { } -@Observed() class F implements PropInterface, trackInterface, IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class F implements PropInterface, trackInterface, IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -81,9 +94,19 @@ interface trackInterface { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } - private __meta: MutableStateMeta = new MutableStateMeta("@Observe properties (no @Track)"); + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } + + private __meta: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); private __backing_propF: number = 1; @@ -91,39 +114,35 @@ interface trackInterface { public constructor() {} - public set propF(newValue: number) { + set propF(newValue: number) { if (((this.__backing_propF) !== (newValue))) { this.__backing_propF = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("propF"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("propF"); } } public get propF(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_propF; } - public set trackF(newValue: number) { + set trackF(newValue: number) { if (((this.__backing_trackF) !== (newValue))) { this.__backing_trackF = newValue; - this.__meta.fireChange(); - this.executeOnSubscribingWatches("trackF"); + this.__meta.fireChange(); + this.executeOnSubscribingWatches("trackF"); } } public get trackF(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta.addRef(); - } + this.conditionalAddRef(this.__meta); return this.__backing_trackF; } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -137,7 +156,6 @@ interface trackInterface { @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { } - `; function testObservedOnlyTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts index 997dffc13407fc49df5f780fe5b951cd6ce40346..88b006aed741645eca49bdb61c2849680df71b57 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/observed-track.test.ts @@ -38,22 +38,35 @@ const observedTrackTransform: Plugins = { const pluginTester = new PluginTester('test observed with track transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Observed as Observed, Track as Track } from "@ohos.arkui.stateManagement"; function main() {} -@Observed() class B implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class B implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -67,34 +80,42 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } public propB: number = 1; private __backing_trackB: number = 2; - private __meta_trackB: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_trackB: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get trackB(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_trackB.addRef(); - } + this.conditionalAddRef(this.__meta_trackB); return this.__backing_trackB; } public set trackB(newValue: number) { if (((this.__backing_trackB) !== (newValue))) { this.__backing_trackB = newValue; - this.__meta_trackB.fireChange(); - this.executeOnSubscribingWatches("trackB"); + this.__meta_trackB.fireChange(); + this.executeOnSubscribingWatches("trackB"); } } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -108,7 +129,6 @@ function main() {} @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { } - `; function testObservedOnlyTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts index c6ce73cb76e8267844d253a822bf2e620ca96e98..0aa8d19beadb0c688d5e703b74bf1dbe77e0bec4 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/observed-track/track-only.test.ts @@ -39,21 +39,33 @@ const pluginTester = new PluginTester('test track only transform', buildConfig); const expectedScript: string = ` import { memo as memo } from "arkui.stateManagement.runtime"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Track as Track } from "@ohos.arkui.stateManagement"; function main() {} -class C implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +class C implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -67,34 +79,42 @@ class C implements IObservedObject { this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } public propC: number = 1; private __backing_trackC: number = 2; - private __meta_trackC: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_trackC: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get trackC(): number { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_trackC.addRef(); - } + this.conditionalAddRef(this.__meta_trackC); return this.__backing_trackC; } public set trackC(newValue: number) { if (((this.__backing_trackC) !== (newValue))) { this.__backing_trackC = newValue; - this.__meta_trackC.fireChange(); - this.executeOnSubscribingWatches("trackC"); + this.__meta_trackC.fireChange(); + this.executeOnSubscribingWatches("trackC"); } } } -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -108,7 +128,6 @@ class C implements IObservedObject { @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { } - `; function testObservedOnlyTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts index 9d1b1849abc1ecc6f838aec81388039f60733f3d..6343a35d04ec90f2cfd7f0504ae3cfc6cdfc0809 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-basic-type.test.ts @@ -38,27 +38,37 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Prop as Prop } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class PropParent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct PropParent extends CustomComponent { public __initializeStruct(initializers: __Options_PropParent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_propVar1 = new PropDecoratedVariable("propVar1", ((({let gensym___95172135 = initializers; + this.__backing_propVar1 = STATE_MGMT_FACTORY.makeProp(this, "propVar1", ((({let gensym___95172135 = initializers; (((gensym___95172135) == (null)) ? undefined : gensym___95172135.propVar1)})) ?? ("propVar1"))); - this.__backing_propVar2 = new PropDecoratedVariable("propVar2", ((({let gensym___222490386 = initializers; + this.__backing_propVar2 = STATE_MGMT_FACTORY.makeProp(this, "propVar2", ((({let gensym___222490386 = initializers; (((gensym___222490386) == (null)) ? undefined : gensym___222490386.propVar2)})) ?? (50))); - this.__backing_propVar3 = new PropDecoratedVariable("propVar3", ((({let gensym___201781257 = initializers; + this.__backing_propVar3 = STATE_MGMT_FACTORY.makeProp(this, "propVar3", ((({let gensym___201781257 = initializers; (((gensym___201781257) == (null)) ? undefined : gensym___201781257.propVar3)})) ?? (true))); - this.__backing_propVar4 = new PropDecoratedVariable("propVar4", ((({let gensym___22028950 = initializers; + this.__backing_propVar4 = STATE_MGMT_FACTORY.makeProp(this, "propVar4", ((({let gensym___22028950 = initializers; (((gensym___22028950) == (null)) ? undefined : gensym___22028950.propVar4)})) ?? (undefined))); - this.__backing_propVar5 = new PropDecoratedVariable("propVar5", ((({let gensym___54872258 = initializers; + this.__backing_propVar5 = STATE_MGMT_FACTORY.makeProp(this, "propVar5", ((({let gensym___54872258 = initializers; (((gensym___54872258) == (null)) ? undefined : gensym___54872258.propVar5)})) ?? (null))); } + public __updateStruct(initializers: __Options_PropParent | undefined): void { if (((({let gensym___67969738 = initializers; (((gensym___67969738) == (null)) ? undefined : gensym___67969738.propVar1)})) !== (undefined))) { @@ -81,66 +91,95 @@ function main() {} this.__backing_propVar5!.update((initializers!.propVar5 as null)); } } - private __backing_propVar1?: PropDecoratedVariable; + + private __backing_propVar1?: IPropDecoratedVariable; + public get propVar1(): string { return this.__backing_propVar1!.get(); } + public set propVar1(value: string) { this.__backing_propVar1!.set(value); } - private __backing_propVar2?: PropDecoratedVariable; + + private __backing_propVar2?: IPropDecoratedVariable; + public get propVar2(): number { return this.__backing_propVar2!.get(); } + public set propVar2(value: number) { this.__backing_propVar2!.set(value); } - private __backing_propVar3?: PropDecoratedVariable; + + private __backing_propVar3?: IPropDecoratedVariable; + public get propVar3(): boolean { return this.__backing_propVar3!.get(); } + public set propVar3(value: boolean) { this.__backing_propVar3!.set(value); } - private __backing_propVar4?: PropDecoratedVariable; + + private __backing_propVar4?: IPropDecoratedVariable; + public get propVar4(): undefined { return this.__backing_propVar4!.get(); } + public set propVar4(value: undefined) { this.__backing_propVar4!.set(value); } - private __backing_propVar5?: PropDecoratedVariable; + + private __backing_propVar5?: IPropDecoratedVariable; + public get propVar5(): null { return this.__backing_propVar5!.get(); } + public set propVar5(value: null) { this.__backing_propVar5!.set(value); } + @memo() public _build(@memo() style: ((instance: PropParent)=> PropParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_PropParent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_PropParent { set propVar1(propVar1: string | undefined) + get propVar1(): string | undefined - set __backing_propVar1(__backing_propVar1: PropDecoratedVariable | undefined) - get __backing_propVar1(): PropDecoratedVariable | undefined + set __backing_propVar1(__backing_propVar1: IPropDecoratedVariable | undefined) + + get __backing_propVar1(): IPropDecoratedVariable | undefined set propVar2(propVar2: number | undefined) + get propVar2(): number | undefined - set __backing_propVar2(__backing_propVar2: PropDecoratedVariable | undefined) - get __backing_propVar2(): PropDecoratedVariable | undefined + set __backing_propVar2(__backing_propVar2: IPropDecoratedVariable | undefined) + + get __backing_propVar2(): IPropDecoratedVariable | undefined set propVar3(propVar3: boolean | undefined) + get propVar3(): boolean | undefined - set __backing_propVar3(__backing_propVar3: PropDecoratedVariable | undefined) - get __backing_propVar3(): PropDecoratedVariable | undefined + set __backing_propVar3(__backing_propVar3: IPropDecoratedVariable | undefined) + + get __backing_propVar3(): IPropDecoratedVariable | undefined set propVar4(propVar4: undefined | undefined) + get propVar4(): undefined | undefined - set __backing_propVar4(__backing_propVar4: undefined | undefined) - get __backing_propVar4(): undefined | undefined + set __backing_propVar4(__backing_propVar4: IPropDecoratedVariable | undefined) + + get __backing_propVar4(): IPropDecoratedVariable | undefined set propVar5(propVar5: null | undefined) + get propVar5(): null | undefined - set __backing_propVar5(__backing_propVar5: PropDecoratedVariable | undefined) - get __backing_propVar5(): PropDecoratedVariable | undefined + set __backing_propVar5(__backing_propVar5: IPropDecoratedVariable | undefined) + + get __backing_propVar5(): IPropDecoratedVariable | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts index 7555db6af820999bb823463235c2d5739d498606..b21363d41b922108c6700eb27d24be59cc258cd0 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/prop-complex-type.test.ts @@ -38,38 +38,60 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Prop as Prop } from "@ohos.arkui.stateManagement"; function main() {} + + class Per { public num: number; + public constructor(num: number) { this.num = num; } + } final class PropType extends BaseEnum { private readonly #ordinal: int; + private static () {} + public constructor(ordinal: int, value: int) { super(value); this.#ordinal = ordinal; } + public static readonly TYPE1: PropType = new PropType(0, 0); + public static readonly TYPE2: PropType = new PropType(1, 1); + public static readonly TYPE3: PropType = new PropType(2, 3); + private static readonly #NamesArray: String[] = ["TYPE1", "TYPE2", "TYPE3"]; + private static readonly #ValuesArray: int[] = [0, 1, 3]; + private static readonly #StringValuesArray: String[] = ["0", "1", "3"]; + private static readonly #ItemsArray: PropType[] = [PropType.TYPE1, PropType.TYPE2, PropType.TYPE3]; + public getName(): String { return PropType.#NamesArray[this.#ordinal]; } + public static getValueOf(name: String): PropType { for (let i = 0;((i) < (PropType.#NamesArray.length));(++i)) { if (((name) == (PropType.#NamesArray[i]))) { @@ -78,6 +100,7 @@ final class PropType extends BaseEnum { } throw new Error((("No enum constant PropType.") + (name))); } + public static fromValue(value: int): PropType { for (let i = 0;((i) < (PropType.#ValuesArray.length));(++i)) { if (((value) == (PropType.#ValuesArray[i]))) { @@ -86,50 +109,57 @@ final class PropType extends BaseEnum { } throw new Error((("No enum PropType with value ") + (value))); } + public valueOf(): int { return PropType.#ValuesArray[this.#ordinal]; } + public toString(): String { return PropType.#StringValuesArray[this.#ordinal]; } + public static values(): PropType[] { return PropType.#ItemsArray; } + public getOrdinal(): int { return this.#ordinal; } + public static $_get(e: PropType): String { return e.getName(); } + } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_propVar1 = new PropDecoratedVariable("propVar1", ((({let gensym___95172135 = initializers; + this.__backing_propVar1 = STATE_MGMT_FACTORY.makeProp(this, "propVar1", ((({let gensym___95172135 = initializers; (((gensym___95172135) == (null)) ? undefined : gensym___95172135.propVar1)})) ?? (new Per(6)))); - this.__backing_propVar2 = new PropDecoratedVariable>("propVar2", ((({let gensym___222490386 = initializers; + this.__backing_propVar2 = STATE_MGMT_FACTORY.makeProp>(this, "propVar2", ((({let gensym___222490386 = initializers; (((gensym___222490386) == (null)) ? undefined : gensym___222490386.propVar2)})) ?? (new Array(3, 6, 8)))); - this.__backing_propVar3 = new PropDecoratedVariable("propVar3", ((({let gensym___201781257 = initializers; + this.__backing_propVar3 = STATE_MGMT_FACTORY.makeProp(this, "propVar3", ((({let gensym___201781257 = initializers; (((gensym___201781257) == (null)) ? undefined : gensym___201781257.propVar3)})) ?? (PropType.TYPE3))); - this.__backing_propVar4 = new PropDecoratedVariable>("propVar4", ((({let gensym___22028950 = initializers; + this.__backing_propVar4 = STATE_MGMT_FACTORY.makeProp>(this, "propVar4", ((({let gensym___22028950 = initializers; (((gensym___22028950) == (null)) ? undefined : gensym___22028950.propVar4)})) ?? (new Set(new Array("aa", "bb"))))); - this.__backing_propVar5 = new PropDecoratedVariable>("propVar5", ((({let gensym___54872258 = initializers; + this.__backing_propVar5 = STATE_MGMT_FACTORY.makeProp>(this, "propVar5", ((({let gensym___54872258 = initializers; (((gensym___54872258) == (null)) ? undefined : gensym___54872258.propVar5)})) ?? ([true, false]))); - this.__backing_propVar6 = new PropDecoratedVariable>("propVar6", ((({let gensym___128760941 = initializers; + this.__backing_propVar6 = STATE_MGMT_FACTORY.makeProp>(this, "propVar6", ((({let gensym___128760941 = initializers; (((gensym___128760941) == (null)) ? undefined : gensym___128760941.propVar6)})) ?? (new Array(new Per(7), new Per(11))))); - this.__backing_propVar7 = new PropDecoratedVariable>("propVar7", ((({let gensym___30534085 = initializers; + this.__backing_propVar7 = STATE_MGMT_FACTORY.makeProp>(this, "propVar7", ((({let gensym___30534085 = initializers; (((gensym___30534085) == (null)) ? undefined : gensym___30534085.propVar7)})) ?? ([new Per(7), new Per(11)]))); - this.__backing_propVar8 = new PropDecoratedVariable<((sr: string)=> void)>("propVar8", ((({let gensym___12471776 = initializers; + this.__backing_propVar8 = STATE_MGMT_FACTORY.makeProp<((sr: string)=> void)>(this, "propVar8", ((({let gensym___12471776 = initializers; (((gensym___12471776) == (null)) ? undefined : gensym___12471776.propVar8)})) ?? (((sr: string) => {})))); - this.__backing_propVar9 = new PropDecoratedVariable("propVar9", ((({let gensym___123472108 = initializers; + this.__backing_propVar9 = STATE_MGMT_FACTORY.makeProp(this, "propVar9", ((({let gensym___123472108 = initializers; (((gensym___123472108) == (null)) ? undefined : gensym___123472108.propVar9)})) ?? (new Date("2025-4-23")))); - this.__backing_propVar10 = new PropDecoratedVariable>("propVar10", ((({let gensym___147847012 = initializers; + this.__backing_propVar10 = STATE_MGMT_FACTORY.makeProp>(this, "propVar10", ((({let gensym___147847012 = initializers; (((gensym___147847012) == (null)) ? undefined : gensym___147847012.propVar10)})) ?? (new Map([[0, new Per(7)], [1, new Per(10)]])))); - this.__backing_propVar11 = new PropDecoratedVariable("propVar11", ((({let gensym___117026760 = initializers; + this.__backing_propVar11 = STATE_MGMT_FACTORY.makeProp(this, "propVar11", ((({let gensym___117026760 = initializers; (((gensym___117026760) == (null)) ? undefined : gensym___117026760.propVar11)})) ?? (0.0))); - this.__backing_propVar12 = new PropDecoratedVariable | Per>("propVar12", ((({let gensym___220245132 = initializers; + this.__backing_propVar12 = STATE_MGMT_FACTORY.makeProp | Per>(this, "propVar12", ((({let gensym___220245132 = initializers; (((gensym___220245132) == (null)) ? undefined : gensym___220245132.propVar12)})) ?? (new Per(6)))); } + public __updateStruct(initializers: __Options_Parent | undefined): void { if (((({let gensym___67969738 = initializers; (((gensym___67969738) == (null)) ? undefined : gensym___67969738.propVar1)})) !== (undefined))) { @@ -180,143 +210,207 @@ final class PropType extends BaseEnum { this.__backing_propVar12!.update((initializers!.propVar12 as Set | Per)); } } - private __backing_propVar1?: PropDecoratedVariable; + + private __backing_propVar1?: IPropDecoratedVariable; + public get propVar1(): Per { return this.__backing_propVar1!.get(); } + public set propVar1(value: Per) { this.__backing_propVar1!.set(value); } - private __backing_propVar2?: PropDecoratedVariable>; + + private __backing_propVar2?: IPropDecoratedVariable>; + public get propVar2(): Array { return this.__backing_propVar2!.get(); } + public set propVar2(value: Array) { this.__backing_propVar2!.set(value); } - private __backing_propVar3?: PropDecoratedVariable; + + private __backing_propVar3?: IPropDecoratedVariable; + public get propVar3(): PropType { return this.__backing_propVar3!.get(); } + public set propVar3(value: PropType) { this.__backing_propVar3!.set(value); } - private __backing_propVar4?: PropDecoratedVariable>; + + private __backing_propVar4?: IPropDecoratedVariable>; + public get propVar4(): Set { return this.__backing_propVar4!.get(); } + public set propVar4(value: Set) { this.__backing_propVar4!.set(value); } - private __backing_propVar5?: PropDecoratedVariable>; + + private __backing_propVar5?: IPropDecoratedVariable>; + public get propVar5(): Array { return this.__backing_propVar5!.get(); } + public set propVar5(value: Array) { this.__backing_propVar5!.set(value); } - private __backing_propVar6?: PropDecoratedVariable>; + + private __backing_propVar6?: IPropDecoratedVariable>; + public get propVar6(): Array { return this.__backing_propVar6!.get(); } + public set propVar6(value: Array) { this.__backing_propVar6!.set(value); } - private __backing_propVar7?: PropDecoratedVariable>; + + private __backing_propVar7?: IPropDecoratedVariable>; + public get propVar7(): Array { return this.__backing_propVar7!.get(); } + public set propVar7(value: Array) { this.__backing_propVar7!.set(value); } - private __backing_propVar8?: PropDecoratedVariable<((sr: string)=> void)>; + + private __backing_propVar8?: IPropDecoratedVariable<((sr: string)=> void)>; + public get propVar8(): ((sr: string)=> void) { return this.__backing_propVar8!.get(); } + public set propVar8(value: ((sr: string)=> void)) { this.__backing_propVar8!.set(value); } - private __backing_propVar9?: PropDecoratedVariable; + + private __backing_propVar9?: IPropDecoratedVariable; + public get propVar9(): Date { return this.__backing_propVar9!.get(); } + public set propVar9(value: Date) { this.__backing_propVar9!.set(value); } - private __backing_propVar10?: PropDecoratedVariable>; + + private __backing_propVar10?: IPropDecoratedVariable>; + public get propVar10(): Map { return this.__backing_propVar10!.get(); } + public set propVar10(value: Map) { this.__backing_propVar10!.set(value); } - private __backing_propVar11?: PropDecoratedVariable; + + private __backing_propVar11?: IPropDecoratedVariable; + public get propVar11(): string | number { return this.__backing_propVar11!.get(); } + public set propVar11(value: string | number) { this.__backing_propVar11!.set(value); } - private __backing_propVar12?: PropDecoratedVariable | Per>; + + private __backing_propVar12?: IPropDecoratedVariable | Per>; + public get propVar12(): Set | Per { return this.__backing_propVar12!.get(); } + public set propVar12(value: Set | Per) { this.__backing_propVar12!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_Parent { set propVar1(propVar1: Per | undefined) + get propVar1(): Per | undefined - set __backing_propVar1(__backing_propVar1: PropDecoratedVariable | undefined) - get __backing_propVar1(): PropDecoratedVariable | undefined + set __backing_propVar1(__backing_propVar1: IPropDecoratedVariable | undefined) + + get __backing_propVar1(): IPropDecoratedVariable | undefined set propVar2(propVar2: Array | undefined) + get propVar2(): Array | undefined - set __backing_propVar2(__backing_propVar2: PropDecoratedVariable> | undefined) - get __backing_propVar2(): PropDecoratedVariable> | undefined + set __backing_propVar2(__backing_propVar2: IPropDecoratedVariable> | undefined) + + get __backing_propVar2(): IPropDecoratedVariable> | undefined set propVar3(propVar3: PropType | undefined) + get propVar3(): PropType | undefined - set __backing_propVar3(__backing_propVar3: PropDecoratedVariable | undefined) - get __backing_propVar3(): PropDecoratedVariable | undefined + set __backing_propVar3(__backing_propVar3: IPropDecoratedVariable | undefined) + + get __backing_propVar3(): IPropDecoratedVariable | undefined set propVar4(propVar4: Set | undefined) + get propVar4(): Set | undefined - set __backing_propVar4(__backing_propVar4: PropDecoratedVariable> | undefined) - get __backing_propVar4(): PropDecoratedVariable> | undefined + set __backing_propVar4(__backing_propVar4: IPropDecoratedVariable> | undefined) + + get __backing_propVar4(): IPropDecoratedVariable> | undefined set propVar5(propVar5: Array | undefined) + get propVar5(): Array | undefined - set __backing_propVar5(__backing_propVar5: PropDecoratedVariable> | undefined) - get __backing_propVar5(): PropDecoratedVariable> | undefined + set __backing_propVar5(__backing_propVar5: IPropDecoratedVariable> | undefined) + + get __backing_propVar5(): IPropDecoratedVariable> | undefined set propVar6(propVar6: Array | undefined) + get propVar6(): Array | undefined - set __backing_propVar6(__backing_propVar6: PropDecoratedVariable> | undefined) - get __backing_propVar6(): PropDecoratedVariable> | undefined + set __backing_propVar6(__backing_propVar6: IPropDecoratedVariable> | undefined) + + get __backing_propVar6(): IPropDecoratedVariable> | undefined set propVar7(propVar7: Array | undefined) + get propVar7(): Array | undefined - set __backing_propVar7(__backing_propVar7: PropDecoratedVariable> | undefined) - get __backing_propVar7(): PropDecoratedVariable> | undefined + set __backing_propVar7(__backing_propVar7: IPropDecoratedVariable> | undefined) + + get __backing_propVar7(): IPropDecoratedVariable> | undefined set propVar8(propVar8: ((sr: string)=> void) | undefined) + get propVar8(): ((sr: string)=> void) | undefined - set __backing_propVar8(__backing_propVar8: PropDecoratedVariable<((sr: string)=> void)> | undefined) - get __backing_propVar8(): PropDecoratedVariable<((sr: string)=> void)> | undefined + set __backing_propVar8(__backing_propVar8: IPropDecoratedVariable<((sr: string)=> void)> | undefined) + + get __backing_propVar8(): IPropDecoratedVariable<((sr: string)=> void)> | undefined set propVar9(propVar9: Date | undefined) + get propVar9(): Date | undefined - set __backing_propVar9(__backing_propVar9: PropDecoratedVariable | undefined) - get __backing_propVar9(): PropDecoratedVariable | undefined + set __backing_propVar9(__backing_propVar9: IPropDecoratedVariable | undefined) + + get __backing_propVar9(): IPropDecoratedVariable | undefined set propVar10(propVar10: Map | undefined) + get propVar10(): Map | undefined - set __backing_propVar10(__backing_propVar10: PropDecoratedVariable> | undefined) - get __backing_propVar10(): PropDecoratedVariable> | undefined + set __backing_propVar10(__backing_propVar10: IPropDecoratedVariable> | undefined) + + get __backing_propVar10(): IPropDecoratedVariable> | undefined set propVar11(propVar11: string | number | undefined) + get propVar11(): string | number | undefined - set __backing_propVar11(__backing_propVar11: PropDecoratedVariable | PropDecoratedVariable | undefined) - get __backing_propVar11(): PropDecoratedVariable | PropDecoratedVariable | undefined + set __backing_propVar11(__backing_propVar11: IPropDecoratedVariable | undefined) + + get __backing_propVar11(): IPropDecoratedVariable | undefined set propVar12(propVar12: Set | Per | undefined) + get propVar12(): Set | Per | undefined - set __backing_propVar12(__backing_propVar12: PropDecoratedVariable> | PropDecoratedVariable | undefined) - get __backing_propVar12(): PropDecoratedVariable> | PropDecoratedVariable | undefined + set __backing_propVar12(__backing_propVar12: IPropDecoratedVariable | Per> | undefined) + + get __backing_propVar12(): IPropDecoratedVariable | Per> | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts index a08c3589d383e29b5c0b07ad0e148f1033696bf7..e9ed8c7b66e725c818b04ed44b17f07f90d2e415 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/prop/state-to-prop.test.ts @@ -38,40 +38,58 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UIButtonAttribute as UIButtonAttribute } from "arkui.component.button"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Text as Text, Button as Button, Column as Column, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + import { Prop as Prop, State as State } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class CountDownComponent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct CountDownComponent extends CustomComponent { public __initializeStruct(initializers: __Options_CountDownComponent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_count = new PropDecoratedVariable("count", ((({let gensym___58710805 = initializers; + this.__backing_count = STATE_MGMT_FACTORY.makeProp(this, "count", ((({let gensym___58710805 = initializers; (((gensym___58710805) == (null)) ? undefined : gensym___58710805.count)})) ?? (0))); this.__backing_costOfOneAttempt = ((({let gensym___88948111 = initializers; (((gensym___88948111) == (null)) ? undefined : gensym___88948111.costOfOneAttempt)})) ?? (1)); } + public __updateStruct(initializers: __Options_CountDownComponent | undefined): void { if (((({let gensym___188547633 = initializers; (((gensym___188547633) == (null)) ? undefined : gensym___188547633.count)})) !== (undefined))) { this.__backing_count!.update((initializers!.count as number)); } } - private __backing_count?: PropDecoratedVariable; + + private __backing_count?: IPropDecoratedVariable; + public get count(): number { return this.__backing_count!.get(); } + public set count(value: number) { this.__backing_count!.set(value); } + private __backing_costOfOneAttempt?: number; + public get costOfOneAttempt(): number { return (this.__backing_costOfOneAttempt as number); } + public set costOfOneAttempt(value: number) { this.__backing_costOfOneAttempt = value; } @@ -83,7 +101,7 @@ function main() {} } else { Text(undefined, "Game over!"); } - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { this.count -= this.costOfOneAttempt; })); @@ -91,32 +109,39 @@ function main() {} }), "Try again"); })); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) final class ParentComponent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct ParentComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ParentComponent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_countDownStartValue = new StateDecoratedVariable("countDownStartValue", ((({let gensym___249912438 = initializers; + this.__backing_countDownStartValue = STATE_MGMT_FACTORY.makeState(this, "countDownStartValue", ((({let gensym___249912438 = initializers; (((gensym___249912438) == (null)) ? undefined : gensym___249912438.countDownStartValue)})) ?? (10))); } + public __updateStruct(initializers: __Options_ParentComponent | undefined): void {} - private __backing_countDownStartValue?: StateDecoratedVariable; + + private __backing_countDownStartValue?: IStateDecoratedVariable; + public get countDownStartValue(): number { return this.__backing_countDownStartValue!.get(); } + public set countDownStartValue(value: number) { this.__backing_countDownStartValue!.set(value); } + @memo() public _build(@memo() style: ((instance: ParentComponent)=> ParentComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ParentComponent | undefined): void { Column(undefined, (() => { Text(undefined, (((("Grant") + (this.countDownStartValue))) + ("nuggets to play."))); - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { this.countDownStartValue += 1; })); return; }), "+1 - Nuggets in New Game"); - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.onClick(((e: ClickEvent) => { this.countDownStartValue -= 1; })); @@ -130,23 +155,32 @@ function main() {} } as __Options_CountDownComponent)); })); } + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_CountDownComponent { set count(count: number | undefined) + get count(): number | undefined - set __backing_count(__backing_count: PropDecoratedVariable | undefined) - get __backing_count(): PropDecoratedVariable | undefined + set __backing_count(__backing_count: IPropDecoratedVariable | undefined) + + get __backing_count(): IPropDecoratedVariable | undefined set costOfOneAttempt(costOfOneAttempt: number | undefined) + get costOfOneAttempt(): number | undefined + } @Component({freezeWhenInactive:false}) export interface __Options_ParentComponent { set countDownStartValue(countDownStartValue: number | undefined) + get countDownStartValue(): number | undefined - set __backing_countDownStartValue(__backing_countDownStartValue: StateDecoratedVariable | undefined) - get __backing_countDownStartValue(): StateDecoratedVariable | undefined + set __backing_countDownStartValue(__backing_countDownStartValue: IStateDecoratedVariable | undefined) + + get __backing_countDownStartValue(): IStateDecoratedVariable | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts index 963774e69a66a9d34ae79769a870d9311a100cdf..0fde11b93065d2225284f011c4cc04b687f30dac 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-annotation-usage.test.ts @@ -38,127 +38,181 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { ProvideDecoratedVariable as ProvideDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProvide"; + +import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Provide as Provide } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class Ancestors extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct Ancestors extends CustomComponent { public __initializeStruct(initializers: __Options_Ancestors | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_count = this.addProvidedVar("count", "count", ((({let gensym___58710805 = initializers; + this.__backing_count = STATE_MGMT_FACTORY.makeProvide(this, "count", "count", ((({let gensym___58710805 = initializers; (((gensym___58710805) == (null)) ? undefined : gensym___58710805.count)})) ?? ("Child0")), false); - this.__backing_count1 = this.addProvidedVar("count1", "prov1", ((({let gensym___84874570 = initializers; + this.__backing_count1 = STATE_MGMT_FACTORY.makeProvide(this, "count1", "prov1", ((({let gensym___84874570 = initializers; (((gensym___84874570) == (null)) ? undefined : gensym___84874570.count1)})) ?? ("Child1")), false); - this.__backing_count2 = this.addProvidedVar("count2", "prov2", ((({let gensym___124037738 = initializers; + this.__backing_count2 = STATE_MGMT_FACTORY.makeProvide(this, "count2", "prov2", ((({let gensym___124037738 = initializers; (((gensym___124037738) == (null)) ? undefined : gensym___124037738.count2)})) ?? ("Child2")), false); - this.__backing_count3 = this.addProvidedVar("count3", "prov3", ((({let gensym___199202238 = initializers; + this.__backing_count3 = STATE_MGMT_FACTORY.makeProvide(this, "count3", "prov3", ((({let gensym___199202238 = initializers; (((gensym___199202238) == (null)) ? undefined : gensym___199202238.count3)})) ?? ("Child3")), true); - this.__backing_count4 = this.addProvidedVar("count4", "count4", ((({let gensym___4359740 = initializers; + this.__backing_count4 = STATE_MGMT_FACTORY.makeProvide(this, "count4", "count4", ((({let gensym___4359740 = initializers; (((gensym___4359740) == (null)) ? undefined : gensym___4359740.count4)})) ?? ("Child4")), false); - this.__backing_count5 = this.addProvidedVar("count5", "count5", ((({let gensym___208755050 = initializers; + this.__backing_count5 = STATE_MGMT_FACTORY.makeProvide(this, "count5", "count5", ((({let gensym___208755050 = initializers; (((gensym___208755050) == (null)) ? undefined : gensym___208755050.count5)})) ?? ("Child5")), true); - this.__backing_count6 = this.addProvidedVar("count6", "", ((({let gensym___37571585 = initializers; + this.__backing_count6 = STATE_MGMT_FACTORY.makeProvide(this, "count6", "", ((({let gensym___37571585 = initializers; (((gensym___37571585) == (null)) ? undefined : gensym___37571585.count6)})) ?? ("Child6")), true); - this.__backing_count7 = this.addProvidedVar("count7", "", ((({let gensym___2162781 = initializers; + this.__backing_count7 = STATE_MGMT_FACTORY.makeProvide(this, "count7", "", ((({let gensym___2162781 = initializers; (((gensym___2162781) == (null)) ? undefined : gensym___2162781.count7)})) ?? ("Child7")), false); } + public __updateStruct(initializers: __Options_Ancestors | undefined): void {} - private __backing_count?: ProvideDecoratedVariable; + + private __backing_count?: IProvideDecoratedVariable; + public get count(): string | undefined { return this.__backing_count!.get(); } + public set count(value: string | undefined) { this.__backing_count!.set(value); } - private __backing_count1?: ProvideDecoratedVariable; + + private __backing_count1?: IProvideDecoratedVariable; + public get count1(): string | undefined { return this.__backing_count1!.get(); } + public set count1(value: string | undefined) { this.__backing_count1!.set(value); } - private __backing_count2?: ProvideDecoratedVariable; + + private __backing_count2?: IProvideDecoratedVariable; + public get count2(): string | undefined { return this.__backing_count2!.get(); } + public set count2(value: string | undefined) { this.__backing_count2!.set(value); } - private __backing_count3?: ProvideDecoratedVariable; + + private __backing_count3?: IProvideDecoratedVariable; + public get count3(): string | undefined { return this.__backing_count3!.get(); } + public set count3(value: string | undefined) { this.__backing_count3!.set(value); } - private __backing_count4?: ProvideDecoratedVariable; + + private __backing_count4?: IProvideDecoratedVariable; + public get count4(): string | undefined { return this.__backing_count4!.get(); } + public set count4(value: string | undefined) { this.__backing_count4!.set(value); } - private __backing_count5?: ProvideDecoratedVariable; + + private __backing_count5?: IProvideDecoratedVariable; + public get count5(): string | undefined { return this.__backing_count5!.get(); } + public set count5(value: string | undefined) { this.__backing_count5!.set(value); } - private __backing_count6?: ProvideDecoratedVariable; + + private __backing_count6?: IProvideDecoratedVariable; + public get count6(): string | undefined { return this.__backing_count6!.get(); } + public set count6(value: string | undefined) { this.__backing_count6!.set(value); } - private __backing_count7?: ProvideDecoratedVariable; + + private __backing_count7?: IProvideDecoratedVariable; + public get count7(): string | undefined { return this.__backing_count7!.get(); } + public set count7(value: string | undefined) { this.__backing_count7!.set(value); } + @memo() public _build(@memo() style: ((instance: Ancestors)=> Ancestors) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Ancestors | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_Ancestors { set count(count: string | undefined | undefined) + get count(): string | undefined | undefined - set __backing_count(__backing_count: ProvideDecoratedVariable | undefined | undefined) - get __backing_count(): ProvideDecoratedVariable | undefined | undefined + set __backing_count(__backing_count: IProvideDecoratedVariable | undefined) + + get __backing_count(): IProvideDecoratedVariable | undefined set count1(count1: string | undefined | undefined) + get count1(): string | undefined | undefined - set __backing_count1(__backing_count1: ProvideDecoratedVariable | undefined | undefined) - get __backing_count1(): ProvideDecoratedVariable | undefined | undefined + set __backing_count1(__backing_count1: IProvideDecoratedVariable | undefined) + + get __backing_count1(): IProvideDecoratedVariable | undefined set count2(count2: string | undefined | undefined) + get count2(): string | undefined | undefined - set __backing_count2(__backing_count2: ProvideDecoratedVariable | undefined | undefined) - get __backing_count2(): ProvideDecoratedVariable | undefined | undefined + set __backing_count2(__backing_count2: IProvideDecoratedVariable | undefined) + + get __backing_count2(): IProvideDecoratedVariable | undefined set count3(count3: string | undefined | undefined) + get count3(): string | undefined | undefined - set __backing_count3(__backing_count3: ProvideDecoratedVariable | undefined | undefined) - get __backing_count3(): ProvideDecoratedVariable | undefined | undefined + set __backing_count3(__backing_count3: IProvideDecoratedVariable | undefined) + + get __backing_count3(): IProvideDecoratedVariable | undefined set count4(count4: string | undefined | undefined) + get count4(): string | undefined | undefined - set __backing_count4(__backing_count4: ProvideDecoratedVariable | undefined | undefined) - get __backing_count4(): ProvideDecoratedVariable | undefined | undefined + set __backing_count4(__backing_count4: IProvideDecoratedVariable | undefined) + + get __backing_count4(): IProvideDecoratedVariable | undefined set count5(count5: string | undefined | undefined) + get count5(): string | undefined | undefined - set __backing_count5(__backing_count5: ProvideDecoratedVariable | undefined | undefined) - get __backing_count5(): ProvideDecoratedVariable | undefined | undefined + set __backing_count5(__backing_count5: IProvideDecoratedVariable | undefined) + + get __backing_count5(): IProvideDecoratedVariable | undefined set count6(count6: string | undefined | undefined) + get count6(): string | undefined | undefined - set __backing_count6(__backing_count6: ProvideDecoratedVariable | undefined | undefined) - get __backing_count6(): ProvideDecoratedVariable | undefined | undefined + set __backing_count6(__backing_count6: IProvideDecoratedVariable | undefined) + + get __backing_count6(): IProvideDecoratedVariable | undefined set count7(count7: string | undefined | undefined) + get count7(): string | undefined | undefined - set __backing_count7(__backing_count7: ProvideDecoratedVariable | undefined | undefined) - get __backing_count7(): ProvideDecoratedVariable | undefined | undefined + set __backing_count7(__backing_count7: IProvideDecoratedVariable | undefined) + + get __backing_count7(): IProvideDecoratedVariable | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts index 86e4942f14152967e7ff8ef61e69bd51a16c38a0..880a40dc2822652957d68d86f53c5e20663dbcea 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-basic-type.test.ts @@ -38,88 +38,127 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { ProvideDecoratedVariable as ProvideDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProvide"; + +import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Provide as Provide } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class PropParent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct PropParent extends CustomComponent { public __initializeStruct(initializers: __Options_PropParent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_provideVar1 = this.addProvidedVar("provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; + this.__backing_provideVar1 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; (((gensym___181030638) == (null)) ? undefined : gensym___181030638.provideVar1)})) ?? ("propVar1")), false); - this.__backing_provideVar2 = this.addProvidedVar("provideVar2", "provideVar2", ((({let gensym___143944235 = initializers; + this.__backing_provideVar2 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar2", "provideVar2", ((({let gensym___143944235 = initializers; (((gensym___143944235) == (null)) ? undefined : gensym___143944235.provideVar2)})) ?? (50)), false); - this.__backing_provideVar3 = this.addProvidedVar("provideVar3", "provideVar3", ((({let gensym___262195977 = initializers; + this.__backing_provideVar3 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar3", "provideVar3", ((({let gensym___262195977 = initializers; (((gensym___262195977) == (null)) ? undefined : gensym___262195977.provideVar3)})) ?? (true)), false); - this.__backing_provideVar4 = this.addProvidedVar("provideVar4", "provideVar4", ((({let gensym___85711435 = initializers; + this.__backing_provideVar4 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar4", "provideVar4", ((({let gensym___85711435 = initializers; (((gensym___85711435) == (null)) ? undefined : gensym___85711435.provideVar4)})) ?? (undefined)), false); - this.__backing_provideVar5 = this.addProvidedVar("provideVar5", "provideVar5", ((({let gensym___139253630 = initializers; + this.__backing_provideVar5 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar5", "provideVar5", ((({let gensym___139253630 = initializers; (((gensym___139253630) == (null)) ? undefined : gensym___139253630.provideVar5)})) ?? (null)), false); } + public __updateStruct(initializers: __Options_PropParent | undefined): void {} - private __backing_provideVar1?: ProvideDecoratedVariable; + + private __backing_provideVar1?: IProvideDecoratedVariable; + public get provideVar1(): string { return this.__backing_provideVar1!.get(); } + public set provideVar1(value: string) { this.__backing_provideVar1!.set(value); } - private __backing_provideVar2?: ProvideDecoratedVariable; + + private __backing_provideVar2?: IProvideDecoratedVariable; + public get provideVar2(): number { return this.__backing_provideVar2!.get(); } + public set provideVar2(value: number) { this.__backing_provideVar2!.set(value); } - private __backing_provideVar3?: ProvideDecoratedVariable; + + private __backing_provideVar3?: IProvideDecoratedVariable; + public get provideVar3(): boolean { return this.__backing_provideVar3!.get(); } + public set provideVar3(value: boolean) { this.__backing_provideVar3!.set(value); } - private __backing_provideVar4?: ProvideDecoratedVariable; + + private __backing_provideVar4?: IProvideDecoratedVariable; + public get provideVar4(): undefined { return this.__backing_provideVar4!.get(); } + public set provideVar4(value: undefined) { this.__backing_provideVar4!.set(value); } - private __backing_provideVar5?: ProvideDecoratedVariable; + + private __backing_provideVar5?: IProvideDecoratedVariable; + public get provideVar5(): null { return this.__backing_provideVar5!.get(); } + public set provideVar5(value: null) { this.__backing_provideVar5!.set(value); } + @memo() public _build(@memo() style: ((instance: PropParent)=> PropParent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_PropParent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_PropParent { set provideVar1(provideVar1: string | undefined) + get provideVar1(): string | undefined - set __backing_provideVar1(__backing_provideVar1: ProvideDecoratedVariable | undefined) - get __backing_provideVar1(): ProvideDecoratedVariable | undefined + set __backing_provideVar1(__backing_provideVar1: IProvideDecoratedVariable | undefined) + + get __backing_provideVar1(): IProvideDecoratedVariable | undefined set provideVar2(provideVar2: number | undefined) + get provideVar2(): number | undefined - set __backing_provideVar2(__backing_provideVar2: ProvideDecoratedVariable | undefined) - get __backing_provideVar2(): ProvideDecoratedVariable | undefined + set __backing_provideVar2(__backing_provideVar2: IProvideDecoratedVariable | undefined) + + get __backing_provideVar2(): IProvideDecoratedVariable | undefined set provideVar3(provideVar3: boolean | undefined) + get provideVar3(): boolean | undefined - set __backing_provideVar3(__backing_provideVar3: ProvideDecoratedVariable | undefined) - get __backing_provideVar3(): ProvideDecoratedVariable | undefined + set __backing_provideVar3(__backing_provideVar3: IProvideDecoratedVariable | undefined) + + get __backing_provideVar3(): IProvideDecoratedVariable | undefined set provideVar4(provideVar4: undefined | undefined) + get provideVar4(): undefined | undefined - set __backing_provideVar4(__backing_provideVar4: undefined | undefined) - get __backing_provideVar4(): undefined | undefined + set __backing_provideVar4(__backing_provideVar4: IProvideDecoratedVariable | undefined) + + get __backing_provideVar4(): IProvideDecoratedVariable | undefined set provideVar5(provideVar5: null | undefined) + get provideVar5(): null | undefined - set __backing_provideVar5(__backing_provideVar5: ProvideDecoratedVariable | undefined) - get __backing_provideVar5(): ProvideDecoratedVariable | undefined + set __backing_provideVar5(__backing_provideVar5: IProvideDecoratedVariable | undefined) + + get __backing_provideVar5(): IProvideDecoratedVariable | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts index 33d6fc204c1223dc9f7f576e89f9a4e74f346201..df078fa4ff42e92145de377787fb6f20e40cbff9 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/provide-and-consume/provide-complex-type.test.ts @@ -38,38 +38,60 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { ProvideDecoratedVariable as ProvideDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProvide"; + +import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { Provide as Provide } from "@ohos.arkui.stateManagement"; function main() {} + + class Per { public num: number; + public constructor(num: number) { this.num = num; } + } final class PropType extends BaseEnum { private readonly #ordinal: int; + private static () {} + public constructor(ordinal: int, value: int) { super(value); this.#ordinal = ordinal; } + public static readonly TYPE1: PropType = new PropType(0, 0); + public static readonly TYPE2: PropType = new PropType(1, 1); + public static readonly TYPE3: PropType = new PropType(2, 3); + private static readonly #NamesArray: String[] = ["TYPE1", "TYPE2", "TYPE3"]; + private static readonly #ValuesArray: int[] = [0, 1, 3]; + private static readonly #StringValuesArray: String[] = ["0", "1", "3"]; + private static readonly #ItemsArray: PropType[] = [PropType.TYPE1, PropType.TYPE2, PropType.TYPE3]; + public getName(): String { return PropType.#NamesArray[this.#ordinal]; } + public static getValueOf(name: String): PropType { for (let i = 0;((i) < (PropType.#NamesArray.length));(++i)) { if (((name) == (PropType.#NamesArray[i]))) { @@ -78,6 +100,7 @@ final class PropType extends BaseEnum { } throw new Error((("No enum constant PropType.") + (name))); } + public static fromValue(value: int): PropType { for (let i = 0;((i) < (PropType.#ValuesArray.length));(++i)) { if (((value) == (PropType.#ValuesArray[i]))) { @@ -86,188 +109,259 @@ final class PropType extends BaseEnum { } throw new Error((("No enum PropType with value ") + (value))); } + public valueOf(): int { return PropType.#ValuesArray[this.#ordinal]; } + public toString(): String { return PropType.#StringValuesArray[this.#ordinal]; } + public static values(): PropType[] { return PropType.#ItemsArray; } + public getOrdinal(): int { return this.#ordinal; } + public static $_get(e: PropType): String { return e.getName(); } + } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_provideVar1 = this.addProvidedVar("provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; + this.__backing_provideVar1 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar1", "provideVar1", ((({let gensym___181030638 = initializers; (((gensym___181030638) == (null)) ? undefined : gensym___181030638.provideVar1)})) ?? (new Per(6))), false); - this.__backing_provideVar2 = this.addProvidedVar>("provideVar2", "provideVar2", ((({let gensym___143944235 = initializers; + this.__backing_provideVar2 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar2", "provideVar2", ((({let gensym___143944235 = initializers; (((gensym___143944235) == (null)) ? undefined : gensym___143944235.provideVar2)})) ?? (new Array(3, 6, 8))), false); - this.__backing_provideVar3 = this.addProvidedVar("provideVar3", "provideVar3", ((({let gensym___262195977 = initializers; + this.__backing_provideVar3 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar3", "provideVar3", ((({let gensym___262195977 = initializers; (((gensym___262195977) == (null)) ? undefined : gensym___262195977.provideVar3)})) ?? (PropType.TYPE3)), false); - this.__backing_provideVar4 = this.addProvidedVar>("provideVar4", "provideVar4", ((({let gensym___85711435 = initializers; + this.__backing_provideVar4 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar4", "provideVar4", ((({let gensym___85711435 = initializers; (((gensym___85711435) == (null)) ? undefined : gensym___85711435.provideVar4)})) ?? (new Set(new Array("aa", "bb")))), false); - this.__backing_provideVar5 = this.addProvidedVar>("provideVar5", "provideVar5", ((({let gensym___139253630 = initializers; + this.__backing_provideVar5 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar5", "provideVar5", ((({let gensym___139253630 = initializers; (((gensym___139253630) == (null)) ? undefined : gensym___139253630.provideVar5)})) ?? ([true, false])), false); - this.__backing_provideVar6 = this.addProvidedVar>("provideVar6", "provideVar6", ((({let gensym___146872112 = initializers; + this.__backing_provideVar6 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar6", "provideVar6", ((({let gensym___146872112 = initializers; (((gensym___146872112) == (null)) ? undefined : gensym___146872112.provideVar6)})) ?? (new Array(new Per(7), new Per(11)))), false); - this.__backing_provideVar7 = this.addProvidedVar>("provideVar7", "provideVar7", ((({let gensym___174412117 = initializers; + this.__backing_provideVar7 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar7", "provideVar7", ((({let gensym___174412117 = initializers; (((gensym___174412117) == (null)) ? undefined : gensym___174412117.provideVar7)})) ?? ([new Per(7), new Per(11)])), false); - this.__backing_provideVar8 = this.addProvidedVar<((sr: string)=> void)>("provideVar8", "provideVar8", ((({let gensym___253467853 = initializers; + this.__backing_provideVar8 = STATE_MGMT_FACTORY.makeProvide<((sr: string)=> void)>(this, "provideVar8", "provideVar8", ((({let gensym___253467853 = initializers; (((gensym___253467853) == (null)) ? undefined : gensym___253467853.provideVar8)})) ?? (((sr: string) => {}))), false); - this.__backing_provideVar9 = this.addProvidedVar("provideVar9", "provideVar9", ((({let gensym___179115605 = initializers; + this.__backing_provideVar9 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar9", "provideVar9", ((({let gensym___179115605 = initializers; (((gensym___179115605) == (null)) ? undefined : gensym___179115605.provideVar9)})) ?? (new Date("2025-4-23"))), false); - this.__backing_provideVar10 = this.addProvidedVar>("provideVar10", "provideVar10", ((({let gensym___209671248 = initializers; + this.__backing_provideVar10 = STATE_MGMT_FACTORY.makeProvide>(this, "provideVar10", "provideVar10", ((({let gensym___209671248 = initializers; (((gensym___209671248) == (null)) ? undefined : gensym___209671248.provideVar10)})) ?? (new Map([[0, new Per(7)], [1, new Per(10)]]))), false); - this.__backing_provideVar11 = this.addProvidedVar("provideVar11", "provideVar11", ((({let gensym___150211849 = initializers; + this.__backing_provideVar11 = STATE_MGMT_FACTORY.makeProvide(this, "provideVar11", "provideVar11", ((({let gensym___150211849 = initializers; (((gensym___150211849) == (null)) ? undefined : gensym___150211849.provideVar11)})) ?? (0.0)), false); - this.__backing_provideVar12 = this.addProvidedVar | Per>("provideVar12", "provideVar12", ((({let gensym___256025818 = initializers; + this.__backing_provideVar12 = STATE_MGMT_FACTORY.makeProvide | Per>(this, "provideVar12", "provideVar12", ((({let gensym___256025818 = initializers; (((gensym___256025818) == (null)) ? undefined : gensym___256025818.provideVar12)})) ?? (new Per(6))), false); } + public __updateStruct(initializers: __Options_Parent | undefined): void {} - private __backing_provideVar1?: ProvideDecoratedVariable; + + private __backing_provideVar1?: IProvideDecoratedVariable; + public get provideVar1(): Per { return this.__backing_provideVar1!.get(); } + public set provideVar1(value: Per) { this.__backing_provideVar1!.set(value); } - private __backing_provideVar2?: ProvideDecoratedVariable>; + + private __backing_provideVar2?: IProvideDecoratedVariable>; + public get provideVar2(): Array { return this.__backing_provideVar2!.get(); } + public set provideVar2(value: Array) { this.__backing_provideVar2!.set(value); } - private __backing_provideVar3?: ProvideDecoratedVariable; + + private __backing_provideVar3?: IProvideDecoratedVariable; + public get provideVar3(): PropType { return this.__backing_provideVar3!.get(); } + public set provideVar3(value: PropType) { this.__backing_provideVar3!.set(value); } - private __backing_provideVar4?: ProvideDecoratedVariable>; + + private __backing_provideVar4?: IProvideDecoratedVariable>; + public get provideVar4(): Set { return this.__backing_provideVar4!.get(); } + public set provideVar4(value: Set) { this.__backing_provideVar4!.set(value); } - private __backing_provideVar5?: ProvideDecoratedVariable>; + + private __backing_provideVar5?: IProvideDecoratedVariable>; + public get provideVar5(): Array { return this.__backing_provideVar5!.get(); } + public set provideVar5(value: Array) { this.__backing_provideVar5!.set(value); } - private __backing_provideVar6?: ProvideDecoratedVariable>; + + private __backing_provideVar6?: IProvideDecoratedVariable>; + public get provideVar6(): Array { return this.__backing_provideVar6!.get(); } + public set provideVar6(value: Array) { this.__backing_provideVar6!.set(value); } - private __backing_provideVar7?: ProvideDecoratedVariable>; + + private __backing_provideVar7?: IProvideDecoratedVariable>; + public get provideVar7(): Array { return this.__backing_provideVar7!.get(); } + public set provideVar7(value: Array) { this.__backing_provideVar7!.set(value); } - private __backing_provideVar8?: ProvideDecoratedVariable<((sr: string)=> void)>; + + private __backing_provideVar8?: IProvideDecoratedVariable<((sr: string)=> void)>; + public get provideVar8(): ((sr: string)=> void) { return this.__backing_provideVar8!.get(); } + public set provideVar8(value: ((sr: string)=> void)) { this.__backing_provideVar8!.set(value); } - private __backing_provideVar9?: ProvideDecoratedVariable; + + private __backing_provideVar9?: IProvideDecoratedVariable; + public get provideVar9(): Date { return this.__backing_provideVar9!.get(); } + public set provideVar9(value: Date) { this.__backing_provideVar9!.set(value); } - private __backing_provideVar10?: ProvideDecoratedVariable>; + + private __backing_provideVar10?: IProvideDecoratedVariable>; + public get provideVar10(): Map { return this.__backing_provideVar10!.get(); } + public set provideVar10(value: Map) { this.__backing_provideVar10!.set(value); } - private __backing_provideVar11?: ProvideDecoratedVariable; + + private __backing_provideVar11?: IProvideDecoratedVariable; + public get provideVar11(): string | number { return this.__backing_provideVar11!.get(); } + public set provideVar11(value: string | number) { this.__backing_provideVar11!.set(value); } - private __backing_provideVar12?: ProvideDecoratedVariable | Per>; + + private __backing_provideVar12?: IProvideDecoratedVariable | Per>; + public get provideVar12(): Set | Per { return this.__backing_provideVar12!.get(); } + public set provideVar12(value: Set | Per) { this.__backing_provideVar12!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_Parent { set provideVar1(provideVar1: Per | undefined) + get provideVar1(): Per | undefined - set __backing_provideVar1(__backing_provideVar1: ProvideDecoratedVariable | undefined) - get __backing_provideVar1(): ProvideDecoratedVariable | undefined + set __backing_provideVar1(__backing_provideVar1: IProvideDecoratedVariable | undefined) + + get __backing_provideVar1(): IProvideDecoratedVariable | undefined set provideVar2(provideVar2: Array | undefined) + get provideVar2(): Array | undefined - set __backing_provideVar2(__backing_provideVar2: ProvideDecoratedVariable> | undefined) - get __backing_provideVar2(): ProvideDecoratedVariable> | undefined + set __backing_provideVar2(__backing_provideVar2: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar2(): IProvideDecoratedVariable> | undefined set provideVar3(provideVar3: PropType | undefined) + get provideVar3(): PropType | undefined - set __backing_provideVar3(__backing_provideVar3: ProvideDecoratedVariable | undefined) - get __backing_provideVar3(): ProvideDecoratedVariable | undefined + set __backing_provideVar3(__backing_provideVar3: IProvideDecoratedVariable | undefined) + + get __backing_provideVar3(): IProvideDecoratedVariable | undefined set provideVar4(provideVar4: Set | undefined) + get provideVar4(): Set | undefined - set __backing_provideVar4(__backing_provideVar4: ProvideDecoratedVariable> | undefined) - get __backing_provideVar4(): ProvideDecoratedVariable> | undefined + set __backing_provideVar4(__backing_provideVar4: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar4(): IProvideDecoratedVariable> | undefined set provideVar5(provideVar5: Array | undefined) + get provideVar5(): Array | undefined - set __backing_provideVar5(__backing_provideVar5: ProvideDecoratedVariable> | undefined) - get __backing_provideVar5(): ProvideDecoratedVariable> | undefined + set __backing_provideVar5(__backing_provideVar5: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar5(): IProvideDecoratedVariable> | undefined set provideVar6(provideVar6: Array | undefined) + get provideVar6(): Array | undefined - set __backing_provideVar6(__backing_provideVar6: ProvideDecoratedVariable> | undefined) - get __backing_provideVar6(): ProvideDecoratedVariable> | undefined + set __backing_provideVar6(__backing_provideVar6: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar6(): IProvideDecoratedVariable> | undefined set provideVar7(provideVar7: Array | undefined) + get provideVar7(): Array | undefined - set __backing_provideVar7(__backing_provideVar7: ProvideDecoratedVariable> | undefined) - get __backing_provideVar7(): ProvideDecoratedVariable> | undefined + set __backing_provideVar7(__backing_provideVar7: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar7(): IProvideDecoratedVariable> | undefined set provideVar8(provideVar8: ((sr: string)=> void) | undefined) + get provideVar8(): ((sr: string)=> void) | undefined - set __backing_provideVar8(__backing_provideVar8: ProvideDecoratedVariable<((sr: string)=> void)> | undefined) - get __backing_provideVar8(): ProvideDecoratedVariable<((sr: string)=> void)> | undefined + set __backing_provideVar8(__backing_provideVar8: IProvideDecoratedVariable<((sr: string)=> void)> | undefined) + + get __backing_provideVar8(): IProvideDecoratedVariable<((sr: string)=> void)> | undefined set provideVar9(provideVar9: Date | undefined) + get provideVar9(): Date | undefined - set __backing_provideVar9(__backing_provideVar9: ProvideDecoratedVariable | undefined) - get __backing_provideVar9(): ProvideDecoratedVariable | undefined + set __backing_provideVar9(__backing_provideVar9: IProvideDecoratedVariable | undefined) + + get __backing_provideVar9(): IProvideDecoratedVariable | undefined set provideVar10(provideVar10: Map | undefined) + get provideVar10(): Map | undefined - set __backing_provideVar10(__backing_provideVar10: ProvideDecoratedVariable> | undefined) - get __backing_provideVar10(): ProvideDecoratedVariable> | undefined + set __backing_provideVar10(__backing_provideVar10: IProvideDecoratedVariable> | undefined) + + get __backing_provideVar10(): IProvideDecoratedVariable> | undefined set provideVar11(provideVar11: string | number | undefined) + get provideVar11(): string | number | undefined - set __backing_provideVar11(__backing_provideVar11: ProvideDecoratedVariable | ProvideDecoratedVariable | undefined) - get __backing_provideVar11(): ProvideDecoratedVariable | ProvideDecoratedVariable | undefined + set __backing_provideVar11(__backing_provideVar11: IProvideDecoratedVariable | undefined) + + get __backing_provideVar11(): IProvideDecoratedVariable | undefined set provideVar12(provideVar12: Set | Per | undefined) + get provideVar12(): Set | Per | undefined - set __backing_provideVar12(__backing_provideVar12: ProvideDecoratedVariable> | ProvideDecoratedVariable | undefined) - get __backing_provideVar12(): ProvideDecoratedVariable> | ProvideDecoratedVariable | undefined + set __backing_provideVar12(__backing_provideVar12: IProvideDecoratedVariable | Per> | undefined) + + get __backing_provideVar12(): IProvideDecoratedVariable | Per> | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts index d9e4c80c5f202d6524e0e964d2345f4b0eb19bfa..b194c8cea669d4b349fb4d55df8a3c455df8af33 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-build.test.ts @@ -38,35 +38,51 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; + import { _rawfile as _rawfile } from "arkui.component.resources"; + import { _r as _r } from "arkui.component.resources"; -import { UIImageAnimatorAttribute as UIImageAnimatorAttribute } from "arkui.component.imageAnimator"; -import { UIImageAttribute as UIImageAttribute } from "arkui.component.image"; + +import { ImageAnimatorAttribute as ImageAnimatorAttribute } from "arkui.component.imageAnimator"; + +import { ImageAttribute as ImageAttribute } from "arkui.component.image"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, TextInput as TextInput, Select as Select, SelectOption as SelectOption, Margin as Margin, ImageAnimator as ImageAnimator } from "@ohos.arkui.component"; function main() {} -@Component({freezeWhenInactive:false}) final class ResourceComponent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct ResourceComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_str1 = ((({let gensym___147578113 = initializers; (((gensym___147578113) == (null)) ? undefined : gensym___147578113.str1)})) ?? ("app.media.ri")); this.__backing_str2 = ((({let gensym___220149772 = initializers; (((gensym___220149772) == (null)) ? undefined : gensym___220149772.str2)})) ?? ("app.photo2.png")); } + public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} + private __backing_str1?: string; + public get str1(): string { return (this.__backing_str1 as string); } + public set str1(value: string) { this.__backing_str1 = value; } + private __backing_str2?: string; + public get str2(): string { return (this.__backing_str2 as string); } + public set str2(value: string) { this.__backing_str2 = value; } @@ -93,14 +109,14 @@ function main() {} value: "ddd", icon: _r("", "", "app.media.selection"), })); - Image(@memo() ((instance: UIImageAttribute): void => { + Image(((instance: ImageAttribute): void => { instance.margin(({ top: _r("", "", "app.float.elements_margin_horizontal_m"), bottom: _r("", "", "app.float.elements_margin_horizontal_l"), } as Margin)); return; }), _r("", "", "app.media.app_icon")); - ImageAnimator(@memo() ((instance: UIImageAnimatorAttribute): void => { + ImageAnimator(((instance: ImageAnimatorAttribute): void => { instance.images([{ src: _r("", "", "app.media.aaa"), }, { @@ -110,14 +126,19 @@ function main() {} })); })); } + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_ResourceComponent { set str1(str1: string | undefined) + get str1(): string | undefined set str2(str2: string | undefined) + get str2(): string | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts index 323eb124a49dd71a2aa03e04fd6cddbda9a95775..3a394627112872717358a50315b7fdeca289c16c 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/resource/resource-in-property.test.ts @@ -38,38 +38,53 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; + import { _rawfile as _rawfile } from "arkui.component.resources"; + import { _r as _r } from "arkui.component.resources"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, $r as $r, $rawfile as $rawfile, Column as Column, Text as Text, Image as Image, Resource as Resource } from "@ohos.arkui.component"; let i: Resource; + function main() {} + i = _r("", "", "app.string.app_name"); -@Component({freezeWhenInactive:false}) final class ResourceComponent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct ResourceComponent extends CustomComponent { public __initializeStruct(initializers: __Options_ResourceComponent | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_str = ((({let gensym___42103502 = initializers; (((gensym___42103502) == (null)) ? undefined : gensym___42103502.str)})) ?? (_r("", "", "app.string.app_name"))); this.__backing_icon = ((({let gensym___38135554 = initializers; (((gensym___38135554) == (null)) ? undefined : gensym___38135554.icon)})) ?? (_rawfile("", "", "app.photo.png"))); } + public __updateStruct(initializers: __Options_ResourceComponent | undefined): void {} + private __backing_str?: Resource; + public get str(): Resource { return (this.__backing_str as Resource); } + public set str(value: Resource) { this.__backing_str = value; } + private __backing_icon?: Resource; + public get icon(): Resource { return (this.__backing_icon as Resource); } + public set icon(value: Resource) { this.__backing_icon = value; } + @memo() public _build(@memo() style: ((instance: ResourceComponent)=> ResourceComponent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ResourceComponent | undefined): void { Column(undefined, (() => { Text(undefined, this.str); @@ -77,14 +92,19 @@ i = _r("", "", "app.string.app_name"); Image(undefined, this.icon); })); } + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_ResourceComponent { set str(str: Resource | undefined) + get str(): Resource | undefined set icon(icon: Resource | undefined) + get icon(): Resource | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts index c7e19d0d3b87a1c88ea97f2bbb531cba3cd933b5..46669ad5595791c79ef5aff6bd81dd0117e1ae29 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-basic.test.ts @@ -38,18 +38,26 @@ const reusableTransform: Plugins = { const pluginTester = new PluginTester('test basic reusable', buildConfig); const expectedScript: string = ` -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + import { memo as memo } from "arkui.stateManagement.runtime"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Reusable as Reusable } from "@ohos.arkui.component"; + import { State as State, Prop as Prop } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -66,12 +74,12 @@ function main() {} } -@Component({freezeWhenInactive:false}) @Reusable() final class Child extends CustomComponent { +@Component({freezeWhenInactive:false}) @Reusable() final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_num = new PropDecoratedVariable("num", ((({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.num)})) ?? (1))); - this.__backing_num1 = new StateDecoratedVariable("num1", ((({let gensym___33833641 = initializers; - (((gensym___33833641) == (null)) ? undefined : gensym___33833641.num1)})) ?? (2))); + this.__backing_num = STATE_MGMT_FACTORY.makeProp(this, "num", ((({let gensym___83257243 = initializers; + (((gensym___83257243) == (null)) ? undefined : gensym___83257243.num)})) ?? (1))); + this.__backing_num1 = STATE_MGMT_FACTORY.makeState(this, "num1", ((({let gensym___24398512 = initializers; + (((gensym___24398512) == (null)) ? undefined : gensym___24398512.num1)})) ?? (2))); } public __updateStruct(initializers: __Options_Child | undefined): void { @@ -89,7 +97,7 @@ function main() {} }; } - private __backing_num?: PropDecoratedVariable; + private __backing_num?: IPropDecoratedVariable; public get num(): number { return this.__backing_num!.get(); @@ -99,7 +107,7 @@ function main() {} this.__backing_num!.set(value); } - private __backing_num1?: StateDecoratedVariable; + private __backing_num1?: IStateDecoratedVariable; public get num1(): number { return this.__backing_num1!.get(); @@ -123,15 +131,15 @@ function main() {} set num(num: number | undefined) get num(): number | undefined - set __backing_num(__backing_num: PropDecoratedVariable | undefined) + set __backing_num(__backing_num: IPropDecoratedVariable | undefined) - get __backing_num(): PropDecoratedVariable | undefined + get __backing_num(): IPropDecoratedVariable | undefined set num1(num1: number | undefined) get num1(): number | undefined - set __backing_num1(__backing_num1: StateDecoratedVariable | undefined) + set __backing_num1(__backing_num1: IStateDecoratedVariable | undefined) - get __backing_num1(): StateDecoratedVariable | undefined + get __backing_num1(): IStateDecoratedVariable | undefined } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts index 84d208c71e5aaca417fcb4ef0d5684c13407863d..08e3af89ed1b093b00f78f4328c18811abc3ea64 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/reusable/reusable-complex.test.ts @@ -38,14 +38,25 @@ const reusableTransform: Plugins = { const pluginTester = new PluginTester('test complex reusable', buildConfig); const expectedScript: string = ` -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UIButtonAttribute as UIButtonAttribute } from "arkui.component.button"; -import { UIColumnAttribute as UIColumnAttribute } from "arkui.component.column"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { ColumnAttribute as ColumnAttribute } from "arkui.component.column"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry, Reusable as Reusable, Column as Column, Text as Text, Button as Button, ClickEvent as ClickEvent, FontWeight as FontWeight } from "@ohos.arkui.component"; + import { State as State } from "@ohos.arkui.stateManagement"; function main() {} @@ -61,15 +72,15 @@ class Message { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class Index extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_display = new StateDecoratedVariable("display", ((({let gensym___83835842 = initializers; + this.__backing_display = STATE_MGMT_FACTORY.makeState(this, "display", ((({let gensym___83835842 = initializers; (((gensym___83835842) == (null)) ? undefined : gensym___83835842.display)})) ?? (true))); } public __updateStruct(initializers: __Options_Index | undefined): void {} - private __backing_display?: StateDecoratedVariable; + private __backing_display?: IStateDecoratedVariable; public get display(): boolean { return this.__backing_display!.get(); @@ -80,11 +91,11 @@ class Message { } @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { - Column(@memo() ((instance: UIColumnAttribute): void => { + Column(((instance: ColumnAttribute): void => { instance.height("100%").width("100%"); return; }), (() => { - Button(@memo() ((instance: UIButtonAttribute): void => { + Button(((instance: ButtonAttribute): void => { instance.fontSize(30).fontWeight(FontWeight.Bold).onClick(((e: ClickEvent) => { this.display = !(this.display); })); @@ -92,10 +103,10 @@ class Message { }), "Hello"); if (this.display) { Child._instantiateImpl(undefined, (() => { - return new Child(); - }), ({ - message: new Message("Child"), - } as __Options_Child), "Child", undefined); + return new Child(); + }), ({ + message: new Message("Child"), + } as __Options_Child), "Child", undefined); } })); } @@ -104,9 +115,9 @@ class Message { } -@Reusable() @Component({freezeWhenInactive:false}) final class Child extends CustomComponent { +@Reusable() @Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_message = new StateDecoratedVariable("message", ((({let gensym___91869411 = initializers; + this.__backing_message = STATE_MGMT_FACTORY.makeState(this, "message", ((({let gensym___91869411 = initializers; (((gensym___91869411) == (null)) ? undefined : gensym___91869411.message)})) ?? (new Message("AboutToReuse")))); } @@ -119,7 +130,7 @@ class Message { }; } - private __backing_message?: StateDecoratedVariable; + private __backing_message?: IStateDecoratedVariable; public get message(): Message { return this.__backing_message!.get(); @@ -134,11 +145,11 @@ class Message { } @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { - Column(@memo() ((instance: UIColumnAttribute): void => { + Column(((instance: ColumnAttribute): void => { instance.borderWidth(1).height(100); return; }), (() => { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.fontSize(30); return; }), this.message.value); @@ -153,9 +164,9 @@ class Message { set display(display: boolean | undefined) get display(): boolean | undefined - set __backing_display(__backing_display: StateDecoratedVariable | undefined) + set __backing_display(__backing_display: IStateDecoratedVariable | undefined) - get __backing_display(): StateDecoratedVariable | undefined + get __backing_display(): IStateDecoratedVariable | undefined } @@ -163,9 +174,9 @@ class Message { set message(message: Message | undefined) get message(): Message | undefined - set __backing_message(__backing_message: StateDecoratedVariable | undefined) + set __backing_message(__backing_message: IStateDecoratedVariable | undefined) - get __backing_message(): StateDecoratedVariable | undefined + get __backing_message(): IStateDecoratedVariable | undefined } @@ -179,7 +190,6 @@ class __EntryWrapper extends EntryPoint { public constructor() {} } - `; function testReusableTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts index b23bdec21b44e4e441089b91daf256b2e9b8c1bb..d595b5a3a951988d724c9d47cee803c54a5cbccd 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-basic-type.test.ts @@ -38,89 +38,128 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { State as State } from "@ohos.arkui.stateManagement"; function main() {} -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { + + +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_stateVar1 = new StateDecoratedVariable("stateVar1", ((({let gensym___213853607 = initializers; + this.__backing_stateVar1 = STATE_MGMT_FACTORY.makeState(this, "stateVar1", ((({let gensym___213853607 = initializers; (((gensym___213853607) == (null)) ? undefined : gensym___213853607.stateVar1)})) ?? ("stateVar1"))); - this.__backing_stateVar2 = new StateDecoratedVariable("stateVar2", ((({let gensym___113574154 = initializers; + this.__backing_stateVar2 = STATE_MGMT_FACTORY.makeState(this, "stateVar2", ((({let gensym___113574154 = initializers; (((gensym___113574154) == (null)) ? undefined : gensym___113574154.stateVar2)})) ?? (50))); - this.__backing_stateVar3 = new StateDecoratedVariable("stateVar3", ((({let gensym___166994972 = initializers; + this.__backing_stateVar3 = STATE_MGMT_FACTORY.makeState(this, "stateVar3", ((({let gensym___166994972 = initializers; (((gensym___166994972) == (null)) ? undefined : gensym___166994972.stateVar3)})) ?? (true))); - this.__backing_stateVar4 = new StateDecoratedVariable("stateVar4", ((({let gensym___148024261 = initializers; + this.__backing_stateVar4 = STATE_MGMT_FACTORY.makeState(this, "stateVar4", ((({let gensym___148024261 = initializers; (((gensym___148024261) == (null)) ? undefined : gensym___148024261.stateVar4)})) ?? (undefined))); - this.__backing_stateVar5 = new StateDecoratedVariable("stateVar5", ((({let gensym___99384342 = initializers; + this.__backing_stateVar5 = STATE_MGMT_FACTORY.makeState(this, "stateVar5", ((({let gensym___99384342 = initializers; (((gensym___99384342) == (null)) ? undefined : gensym___99384342.stateVar5)})) ?? (null))); } + public __updateStruct(initializers: __Options_Parent | undefined): void {} - private __backing_stateVar1?: StateDecoratedVariable; + + private __backing_stateVar1?: IStateDecoratedVariable; + public get stateVar1(): string { return this.__backing_stateVar1!.get(); } + public set stateVar1(value: string) { this.__backing_stateVar1!.set(value); } - private __backing_stateVar2?: StateDecoratedVariable; + + private __backing_stateVar2?: IStateDecoratedVariable; + public get stateVar2(): number { return this.__backing_stateVar2!.get(); } + public set stateVar2(value: number) { this.__backing_stateVar2!.set(value); } - private __backing_stateVar3?: StateDecoratedVariable; + + private __backing_stateVar3?: IStateDecoratedVariable; + public get stateVar3(): boolean { return this.__backing_stateVar3!.get(); } + public set stateVar3(value: boolean) { this.__backing_stateVar3!.set(value); } - private __backing_stateVar4?: StateDecoratedVariable; + + private __backing_stateVar4?: IStateDecoratedVariable; + public get stateVar4(): undefined { return this.__backing_stateVar4!.get(); } + public set stateVar4(value: undefined) { this.__backing_stateVar4!.set(value); } - private __backing_stateVar5?: StateDecoratedVariable; + + private __backing_stateVar5?: IStateDecoratedVariable; + public get stateVar5(): null { return this.__backing_stateVar5!.get(); } + public set stateVar5(value: null) { this.__backing_stateVar5!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_Parent { set stateVar1(stateVar1: string | undefined) + get stateVar1(): string | undefined - set __backing_stateVar1(__backing_stateVar1: StateDecoratedVariable | undefined) - get __backing_stateVar1(): StateDecoratedVariable | undefined + set __backing_stateVar1(__backing_stateVar1: IStateDecoratedVariable | undefined) + + get __backing_stateVar1(): IStateDecoratedVariable | undefined set stateVar2(stateVar2: number | undefined) + get stateVar2(): number | undefined - set __backing_stateVar2(__backing_stateVar2: StateDecoratedVariable | undefined) - get __backing_stateVar2(): StateDecoratedVariable | undefined + set __backing_stateVar2(__backing_stateVar2: IStateDecoratedVariable | undefined) + + get __backing_stateVar2(): IStateDecoratedVariable | undefined set stateVar3(stateVar3: boolean | undefined) + get stateVar3(): boolean | undefined - set __backing_stateVar3(__backing_stateVar3: StateDecoratedVariable | undefined) - get __backing_stateVar3(): StateDecoratedVariable | undefined + set __backing_stateVar3(__backing_stateVar3: IStateDecoratedVariable | undefined) + + get __backing_stateVar3(): IStateDecoratedVariable | undefined set stateVar4(stateVar4: undefined | undefined) + get stateVar4(): undefined | undefined - set __backing_stateVar4(__backing_stateVar4: undefined | undefined) - get __backing_stateVar4(): undefined | undefined + set __backing_stateVar4(__backing_stateVar4: IStateDecoratedVariable | undefined) + + get __backing_stateVar4(): IStateDecoratedVariable | undefined set stateVar5(stateVar5: null | undefined) + get stateVar5(): null | undefined - set __backing_stateVar5(__backing_stateVar5: StateDecoratedVariable | undefined) - get __backing_stateVar5(): StateDecoratedVariable | undefined -} + set __backing_stateVar5(__backing_stateVar5: IStateDecoratedVariable | undefined) + + get __backing_stateVar5(): IStateDecoratedVariable | undefined + +} `; function testParsedAndCheckedTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts index bfc4bf3343120615dce9b1c3ce4a7255f0372101..f7c74a3e7a579a14fa5322cefec85d095e37b636 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-complex-type.test.ts @@ -38,38 +38,60 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component } from "@ohos.arkui.component"; + import { State as State } from "@ohos.arkui.stateManagement"; function main() {} + + class Per { public num: number; + public constructor(num: number) { this.num = num; } + } final class StateType extends BaseEnum { private readonly #ordinal: int; + private static () {} + public constructor(ordinal: int, value: int) { super(value); this.#ordinal = ordinal; } + public static readonly TYPE1: StateType = new StateType(0, 0); + public static readonly TYPE2: StateType = new StateType(1, 1); + public static readonly TYPE3: StateType = new StateType(2, 3); + private static readonly #NamesArray: String[] = ["TYPE1", "TYPE2", "TYPE3"]; + private static readonly #ValuesArray: int[] = [0, 1, 3]; + private static readonly #StringValuesArray: String[] = ["0", "1", "3"]; + private static readonly #ItemsArray: StateType[] = [StateType.TYPE1, StateType.TYPE2, StateType.TYPE3]; + public getName(): String { return StateType.#NamesArray[this.#ordinal]; } + public static getValueOf(name: String): StateType { for (let i = 0;((i) < (StateType.#NamesArray.length));(++i)) { if (((name) == (StateType.#NamesArray[i]))) { @@ -78,6 +100,7 @@ final class StateType extends BaseEnum { } throw new Error((("No enum constant StateType.") + (name))); } + public static fromValue(value: int): StateType { for (let i = 0;((i) < (StateType.#ValuesArray.length));(++i)) { if (((value) == (StateType.#ValuesArray[i]))) { @@ -86,188 +109,259 @@ final class StateType extends BaseEnum { } throw new Error((("No enum StateType with value ") + (value))); } + public valueOf(): int { return StateType.#ValuesArray[this.#ordinal]; } + public toString(): String { return StateType.#StringValuesArray[this.#ordinal]; } + public static values(): StateType[] { return StateType.#ItemsArray; } + public getOrdinal(): int { return this.#ordinal; } + public static $_get(e: StateType): String { return e.getName(); } + } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_stateVar1 = new StateDecoratedVariable("stateVar1", ((({let gensym___213853607 = initializers; + this.__backing_stateVar1 = STATE_MGMT_FACTORY.makeState(this, "stateVar1", ((({let gensym___213853607 = initializers; (((gensym___213853607) == (null)) ? undefined : gensym___213853607.stateVar1)})) ?? (new Per(6)))); - this.__backing_stateVar2 = new StateDecoratedVariable>("stateVar2", ((({let gensym___113574154 = initializers; + this.__backing_stateVar2 = STATE_MGMT_FACTORY.makeState>(this, "stateVar2", ((({let gensym___113574154 = initializers; (((gensym___113574154) == (null)) ? undefined : gensym___113574154.stateVar2)})) ?? (new Array(3, 6, 8)))); - this.__backing_stateVar3 = new StateDecoratedVariable("stateVar3", ((({let gensym___166994972 = initializers; + this.__backing_stateVar3 = STATE_MGMT_FACTORY.makeState(this, "stateVar3", ((({let gensym___166994972 = initializers; (((gensym___166994972) == (null)) ? undefined : gensym___166994972.stateVar3)})) ?? (StateType.TYPE3))); - this.__backing_stateVar4 = new StateDecoratedVariable>("stateVar4", ((({let gensym___148024261 = initializers; + this.__backing_stateVar4 = STATE_MGMT_FACTORY.makeState>(this, "stateVar4", ((({let gensym___148024261 = initializers; (((gensym___148024261) == (null)) ? undefined : gensym___148024261.stateVar4)})) ?? (new Set(new Array("aa", "bb"))))); - this.__backing_stateVar5 = new StateDecoratedVariable>("stateVar5", ((({let gensym___99384342 = initializers; + this.__backing_stateVar5 = STATE_MGMT_FACTORY.makeState>(this, "stateVar5", ((({let gensym___99384342 = initializers; (((gensym___99384342) == (null)) ? undefined : gensym___99384342.stateVar5)})) ?? ([true, false]))); - this.__backing_stateVar6 = new StateDecoratedVariable>("stateVar6", ((({let gensym___133364871 = initializers; + this.__backing_stateVar6 = STATE_MGMT_FACTORY.makeState>(this, "stateVar6", ((({let gensym___133364871 = initializers; (((gensym___133364871) == (null)) ? undefined : gensym___133364871.stateVar6)})) ?? (new Array(new Per(7), new Per(11))))); - this.__backing_stateVar7 = new StateDecoratedVariable>("stateVar7", ((({let gensym___69403028 = initializers; + this.__backing_stateVar7 = STATE_MGMT_FACTORY.makeState>(this, "stateVar7", ((({let gensym___69403028 = initializers; (((gensym___69403028) == (null)) ? undefined : gensym___69403028.stateVar7)})) ?? ([new Per(7), new Per(11)]))); - this.__backing_stateVar8 = new StateDecoratedVariable<((sr: string)=> void)>("stateVar8", ((({let gensym___219403122 = initializers; + this.__backing_stateVar8 = STATE_MGMT_FACTORY.makeState<((sr: string)=> void)>(this, "stateVar8", ((({let gensym___219403122 = initializers; (((gensym___219403122) == (null)) ? undefined : gensym___219403122.stateVar8)})) ?? (((sr: string) => {})))); - this.__backing_stateVar9 = new StateDecoratedVariable("stateVar9", ((({let gensym___171171899 = initializers; + this.__backing_stateVar9 = STATE_MGMT_FACTORY.makeState(this, "stateVar9", ((({let gensym___171171899 = initializers; (((gensym___171171899) == (null)) ? undefined : gensym___171171899.stateVar9)})) ?? (new Date("2025-4-23")))); - this.__backing_stateVar10 = new StateDecoratedVariable>("stateVar10", ((({let gensym___91651348 = initializers; + this.__backing_stateVar10 = STATE_MGMT_FACTORY.makeState>(this, "stateVar10", ((({let gensym___91651348 = initializers; (((gensym___91651348) == (null)) ? undefined : gensym___91651348.stateVar10)})) ?? (new Map([[0, new Per(7)], [1, new Per(10)]])))); - this.__backing_stateVar11 = new StateDecoratedVariable("stateVar11", ((({let gensym___56045278 = initializers; + this.__backing_stateVar11 = STATE_MGMT_FACTORY.makeState(this, "stateVar11", ((({let gensym___56045278 = initializers; (((gensym___56045278) == (null)) ? undefined : gensym___56045278.stateVar11)})) ?? (0.0))); - this.__backing_stateVar12 = new StateDecoratedVariable | Per>("stateVar12", ((({let gensym___164759887 = initializers; + this.__backing_stateVar12 = STATE_MGMT_FACTORY.makeState | Per>(this, "stateVar12", ((({let gensym___164759887 = initializers; (((gensym___164759887) == (null)) ? undefined : gensym___164759887.stateVar12)})) ?? (new Per(6)))); } + public __updateStruct(initializers: __Options_Parent | undefined): void {} - private __backing_stateVar1?: StateDecoratedVariable; + + private __backing_stateVar1?: IStateDecoratedVariable; + public get stateVar1(): Per { return this.__backing_stateVar1!.get(); } + public set stateVar1(value: Per) { this.__backing_stateVar1!.set(value); } - private __backing_stateVar2?: StateDecoratedVariable>; + + private __backing_stateVar2?: IStateDecoratedVariable>; + public get stateVar2(): Array { return this.__backing_stateVar2!.get(); } + public set stateVar2(value: Array) { this.__backing_stateVar2!.set(value); } - private __backing_stateVar3?: StateDecoratedVariable; + + private __backing_stateVar3?: IStateDecoratedVariable; + public get stateVar3(): StateType { return this.__backing_stateVar3!.get(); } + public set stateVar3(value: StateType) { this.__backing_stateVar3!.set(value); } - private __backing_stateVar4?: StateDecoratedVariable>; + + private __backing_stateVar4?: IStateDecoratedVariable>; + public get stateVar4(): Set { return this.__backing_stateVar4!.get(); } + public set stateVar4(value: Set) { this.__backing_stateVar4!.set(value); } - private __backing_stateVar5?: StateDecoratedVariable>; + + private __backing_stateVar5?: IStateDecoratedVariable>; + public get stateVar5(): Array { return this.__backing_stateVar5!.get(); } + public set stateVar5(value: Array) { this.__backing_stateVar5!.set(value); } - private __backing_stateVar6?: StateDecoratedVariable>; + + private __backing_stateVar6?: IStateDecoratedVariable>; + public get stateVar6(): Array { return this.__backing_stateVar6!.get(); } + public set stateVar6(value: Array) { this.__backing_stateVar6!.set(value); } - private __backing_stateVar7?: StateDecoratedVariable>; + + private __backing_stateVar7?: IStateDecoratedVariable>; + public get stateVar7(): Array { return this.__backing_stateVar7!.get(); } + public set stateVar7(value: Array) { this.__backing_stateVar7!.set(value); } - private __backing_stateVar8?: StateDecoratedVariable<((sr: string)=> void)>; + + private __backing_stateVar8?: IStateDecoratedVariable<((sr: string)=> void)>; + public get stateVar8(): ((sr: string)=> void) { return this.__backing_stateVar8!.get(); } + public set stateVar8(value: ((sr: string)=> void)) { this.__backing_stateVar8!.set(value); } - private __backing_stateVar9?: StateDecoratedVariable; + + private __backing_stateVar9?: IStateDecoratedVariable; + public get stateVar9(): Date { return this.__backing_stateVar9!.get(); } + public set stateVar9(value: Date) { this.__backing_stateVar9!.set(value); } - private __backing_stateVar10?: StateDecoratedVariable>; + + private __backing_stateVar10?: IStateDecoratedVariable>; + public get stateVar10(): Map { return this.__backing_stateVar10!.get(); } + public set stateVar10(value: Map) { this.__backing_stateVar10!.set(value); } - private __backing_stateVar11?: StateDecoratedVariable; + + private __backing_stateVar11?: IStateDecoratedVariable; + public get stateVar11(): string | number { return this.__backing_stateVar11!.get(); } + public set stateVar11(value: string | number) { this.__backing_stateVar11!.set(value); } - private __backing_stateVar12?: StateDecoratedVariable | Per>; + + private __backing_stateVar12?: IStateDecoratedVariable | Per>; + public get stateVar12(): Set | Per { return this.__backing_stateVar12!.get(); } + public set stateVar12(value: Set | Per) { this.__backing_stateVar12!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void {} + private constructor() {} + } @Component({freezeWhenInactive:false}) export interface __Options_Parent { set stateVar1(stateVar1: Per | undefined) + get stateVar1(): Per | undefined - set __backing_stateVar1(__backing_stateVar1: StateDecoratedVariable | undefined) - get __backing_stateVar1(): StateDecoratedVariable | undefined + set __backing_stateVar1(__backing_stateVar1: IStateDecoratedVariable | undefined) + + get __backing_stateVar1(): IStateDecoratedVariable | undefined set stateVar2(stateVar2: Array | undefined) + get stateVar2(): Array | undefined - set __backing_stateVar2(__backing_stateVar2: StateDecoratedVariable> | undefined) - get __backing_stateVar2(): StateDecoratedVariable> | undefined + set __backing_stateVar2(__backing_stateVar2: IStateDecoratedVariable> | undefined) + + get __backing_stateVar2(): IStateDecoratedVariable> | undefined set stateVar3(stateVar3: StateType | undefined) + get stateVar3(): StateType | undefined - set __backing_stateVar3(__backing_stateVar3: StateDecoratedVariable | undefined) - get __backing_stateVar3(): StateDecoratedVariable | undefined + set __backing_stateVar3(__backing_stateVar3: IStateDecoratedVariable | undefined) + + get __backing_stateVar3(): IStateDecoratedVariable | undefined set stateVar4(stateVar4: Set | undefined) + get stateVar4(): Set | undefined - set __backing_stateVar4(__backing_stateVar4: StateDecoratedVariable> | undefined) - get __backing_stateVar4(): StateDecoratedVariable> | undefined + set __backing_stateVar4(__backing_stateVar4: IStateDecoratedVariable> | undefined) + + get __backing_stateVar4(): IStateDecoratedVariable> | undefined set stateVar5(stateVar5: Array | undefined) + get stateVar5(): Array | undefined - set __backing_stateVar5(__backing_stateVar5: StateDecoratedVariable> | undefined) - get __backing_stateVar5(): StateDecoratedVariable> | undefined + set __backing_stateVar5(__backing_stateVar5: IStateDecoratedVariable> | undefined) + + get __backing_stateVar5(): IStateDecoratedVariable> | undefined set stateVar6(stateVar6: Array | undefined) + get stateVar6(): Array | undefined - set __backing_stateVar6(__backing_stateVar6: StateDecoratedVariable> | undefined) - get __backing_stateVar6(): StateDecoratedVariable> | undefined + set __backing_stateVar6(__backing_stateVar6: IStateDecoratedVariable> | undefined) + + get __backing_stateVar6(): IStateDecoratedVariable> | undefined set stateVar7(stateVar7: Array | undefined) + get stateVar7(): Array | undefined - set __backing_stateVar7(__backing_stateVar7: StateDecoratedVariable> | undefined) - get __backing_stateVar7(): StateDecoratedVariable> | undefined + set __backing_stateVar7(__backing_stateVar7: IStateDecoratedVariable> | undefined) + + get __backing_stateVar7(): IStateDecoratedVariable> | undefined set stateVar8(stateVar8: ((sr: string)=> void) | undefined) + get stateVar8(): ((sr: string)=> void) | undefined - set __backing_stateVar8(__backing_stateVar8: StateDecoratedVariable<((sr: string)=> void)> | undefined) - get __backing_stateVar8(): StateDecoratedVariable<((sr: string)=> void)> | undefined + set __backing_stateVar8(__backing_stateVar8: IStateDecoratedVariable<((sr: string)=> void)> | undefined) + + get __backing_stateVar8(): IStateDecoratedVariable<((sr: string)=> void)> | undefined set stateVar9(stateVar9: Date | undefined) + get stateVar9(): Date | undefined - set __backing_stateVar9(__backing_stateVar9: StateDecoratedVariable | undefined) - get __backing_stateVar9(): StateDecoratedVariable | undefined + set __backing_stateVar9(__backing_stateVar9: IStateDecoratedVariable | undefined) + + get __backing_stateVar9(): IStateDecoratedVariable | undefined set stateVar10(stateVar10: Map | undefined) + get stateVar10(): Map | undefined - set __backing_stateVar10(__backing_stateVar10: StateDecoratedVariable> | undefined) - get __backing_stateVar10(): StateDecoratedVariable> | undefined + set __backing_stateVar10(__backing_stateVar10: IStateDecoratedVariable> | undefined) + + get __backing_stateVar10(): IStateDecoratedVariable> | undefined set stateVar11(stateVar11: string | number | undefined) + get stateVar11(): string | number | undefined - set __backing_stateVar11(__backing_stateVar11: StateDecoratedVariable | StateDecoratedVariable | undefined) - get __backing_stateVar11(): StateDecoratedVariable | StateDecoratedVariable | undefined + set __backing_stateVar11(__backing_stateVar11: IStateDecoratedVariable | undefined) + + get __backing_stateVar11(): IStateDecoratedVariable | undefined set stateVar12(stateVar12: Set | Per | undefined) + get stateVar12(): Set | Per | undefined - set __backing_stateVar12(__backing_stateVar12: StateDecoratedVariable> | StateDecoratedVariable | undefined) - get __backing_stateVar12(): StateDecoratedVariable> | StateDecoratedVariable | undefined + set __backing_stateVar12(__backing_stateVar12: IStateDecoratedVariable | Per> | undefined) + + get __backing_stateVar12(): IStateDecoratedVariable | Per> | undefined + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts index c9caf1b0a66cbc42c652118030c19d2f0e78fc46..f3f46a093ba17f44a7d89d44b58c9ad922faca7f 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/state/state-to-state.test.ts @@ -38,34 +38,50 @@ const parsedTransform: Plugins = { }; const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Column as Column, Text as Text } from "@ohos.arkui.component"; + import { State as State } from "@ohos.arkui.stateManagement"; function main() {} + + class Per { public str: string; + public constructor(str: string) { this.str = str; } + } -@Component({freezeWhenInactive:false}) final class Parent extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Parent extends CustomComponent { public __initializeStruct(initializers: __Options_Parent | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_parentVar1 = new StateDecoratedVariable("parentVar1", ((({let gensym___247315634 = initializers; + this.__backing_parentVar1 = STATE_MGMT_FACTORY.makeState(this, "parentVar1", ((({let gensym___247315634 = initializers; (((gensym___247315634) == (null)) ? undefined : gensym___247315634.parentVar1)})) ?? (new Per("hello")))); } + public __updateStruct(initializers: __Options_Parent | undefined): void {} - private __backing_parentVar1?: StateDecoratedVariable; + + private __backing_parentVar1?: IStateDecoratedVariable; + public get parentVar1(): Per { return this.__backing_parentVar1!.get(); } + public set parentVar1(value: Per) { this.__backing_parentVar1!.set(value); } + @memo() public _build(@memo() style: ((instance: Parent)=> Parent) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Parent | undefined): void { Column(undefined, (() => { Child._instantiateImpl(undefined, (() => { @@ -75,42 +91,56 @@ class Per { } as __Options_Child)); })); } + private constructor() {} + } -@Component({freezeWhenInactive:false}) final class Child extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_childVar1 = new StateDecoratedVariable("childVar1", ((({let gensym___218939886 = initializers; + this.__backing_childVar1 = STATE_MGMT_FACTORY.makeState(this, "childVar1", ((({let gensym___218939886 = initializers; (((gensym___218939886) == (null)) ? undefined : gensym___218939886.childVar1)})) ?? (new Per("ccc")))); } + public __updateStruct(initializers: __Options_Child | undefined): void {} - private __backing_childVar1?: StateDecoratedVariable; + + private __backing_childVar1?: IStateDecoratedVariable; + public get childVar1(): Per { return this.__backing_childVar1!.get(); } + public set childVar1(value: Per) { this.__backing_childVar1!.set(value); } + @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void { Text(undefined, this.childVar1.str); } + private constructor() {} } @Component({freezeWhenInactive:false}) export interface __Options_Parent { set parentVar1(parentVar1: Per | undefined) + get parentVar1(): Per | undefined - set __backing_parentVar1(__backing_parentVar1: StateDecoratedVariable | undefined) - get __backing_parentVar1(): StateDecoratedVariable | undefined + set __backing_parentVar1(__backing_parentVar1: IStateDecoratedVariable | undefined) + + get __backing_parentVar1(): IStateDecoratedVariable | undefined + } @Component({freezeWhenInactive:false}) export interface __Options_Child { set childVar1(childVar1: Per | undefined) + get childVar1(): Per | undefined - set __backing_childVar1(__backing_childVar1: StateDecoratedVariable | undefined) - get __backing_childVar1(): StateDecoratedVariable | undefined -} + set __backing_childVar1(__backing_childVar1: IStateDecoratedVariable | undefined) + + get __backing_childVar1(): IStateDecoratedVariable | undefined + +} `; function testParsedAndCheckedTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts index eedfa0a432eca350fcb0f6f88c81154ae86395d4..34827c4997715c13722da6a49e0fcf68fc6214ad 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-appstorage.test.ts @@ -38,12 +38,21 @@ const storageLinkTransform: Plugins = { const pluginTester = new PluginTester('test storagelink with appstorage', buildConfig); const expectedScript: string = ` -import { StorageLinkDecoratedVariable as StorageLinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageLink"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry, Column as Column, Text as Text, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + import { StorageLink as StorageLink, AppStorage as AppStorage } from "@ohos.arkui.stateManagement"; function main() {} @@ -60,15 +69,15 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class Index extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_storageLink = new StorageLinkDecoratedVariable("PropA", "storageLink", 1) - this.__backing_storageLinkObject = new StorageLinkDecoratedVariable("PropB", "storageLinkObject", new Data(1)) + this.__backing_storageLink = STATE_MGMT_FACTORY.makeStorageLink(this, "PropA", "storageLink", 1) + this.__backing_storageLinkObject = STATE_MGMT_FACTORY.makeStorageLink(this, "PropB", "storageLinkObject", new Data(1)) } public __updateStruct(initializers: __Options_Index | undefined): void {} - private __backing_storageLink?: StorageLinkDecoratedVariable; + private __backing_storageLink?: IStorageLinkDecoratedVariable; public get storageLink(): number { return this.__backing_storageLink!.get(); @@ -78,7 +87,7 @@ class Data { this.__backing_storageLink!.set(value); } - private __backing_storageLinkObject?: StorageLinkDecoratedVariable; + private __backing_storageLinkObject?: IStorageLinkDecoratedVariable; public get storageLinkObject(): Data { return this.__backing_storageLinkObject!.get(); @@ -90,13 +99,13 @@ class Data { @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { Column(undefined, (() => { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { this.storageLink += 1; })); return; }), \`From AppStorage \${this.storageLink}\`); - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { this.storageLinkObject.code += 1; })); @@ -113,15 +122,15 @@ class Data { set storageLink(storageLink: number | undefined) get storageLink(): number | undefined - set __backing_storageLink(__backing_storageLink: StorageLinkDecoratedVariable | undefined) + set __backing_storageLink(__backing_storageLink: IStorageLinkDecoratedVariable | undefined) - get __backing_storageLink(): StorageLinkDecoratedVariable | undefined + get __backing_storageLink(): IStorageLinkDecoratedVariable | undefined set storageLinkObject(storageLinkObject: Data | undefined) get storageLinkObject(): Data | undefined - set __backing_storageLinkObject(__backing_storageLinkObject: StorageLinkDecoratedVariable | undefined) + set __backing_storageLinkObject(__backing_storageLinkObject: IStorageLinkDecoratedVariable | undefined) - get __backing_storageLinkObject(): StorageLinkDecoratedVariable | undefined + get __backing_storageLinkObject(): IStorageLinkDecoratedVariable | undefined } diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts index 6ce66a065902566ff95340ed32825e9847b1495e..0dc4a318ed768a8921313b71e974dc82ff437e59 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-complex-type.test.ts @@ -38,9 +38,12 @@ const storageLinkTransform: Plugins = { const pluginTester = new PluginTester('test storagelink complex type transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StorageLinkDecoratedVariable as StorageLinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageLink"; +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; import { EntryPoint as EntryPoint } from "arkui.UserView"; @@ -129,21 +132,21 @@ final class Status extends BaseEnum { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_arrayA = new StorageLinkDecoratedVariable>("Prop1", "arrayA", [1, 2, 3]) - this.__backing_objectA = new StorageLinkDecoratedVariable("Prop2", "objectA", {}) - this.__backing_dateA = new StorageLinkDecoratedVariable("Prop3", "dateA", new Date("2021-08-08")) - this.__backing_setA = new StorageLinkDecoratedVariable>("Prop4", "setA", new Set()) - this.__backing_mapA = new StorageLinkDecoratedVariable>("Prop5", "mapA", new Map()) - this.__backing_unionA = new StorageLinkDecoratedVariable("Prop6", "unionA", "") - this.__backing_classA = new StorageLinkDecoratedVariable("Prop7", "classA", new Person("John")) - this.__backing_enumA = new StorageLinkDecoratedVariable("Prop8", "enumA", Status.NotFound) + this.__backing_arrayA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop1", "arrayA", [1, 2, 3]) + this.__backing_objectA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "objectA", {}) + this.__backing_dateA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop3", "dateA", new Date("2021-08-08")) + this.__backing_setA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop4", "setA", new Set()) + this.__backing_mapA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop5", "mapA", new Map()) + this.__backing_unionA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop6", "unionA", "") + this.__backing_classA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop7", "classA", new Person("John")) + this.__backing_enumA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop8", "enumA", Status.NotFound) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_arrayA?: StorageLinkDecoratedVariable>; + private __backing_arrayA?: IStorageLinkDecoratedVariable>; public get arrayA(): Array { return this.__backing_arrayA!.get(); @@ -153,7 +156,7 @@ final class Status extends BaseEnum { this.__backing_arrayA!.set(value); } - private __backing_objectA?: StorageLinkDecoratedVariable; + private __backing_objectA?: IStorageLinkDecoratedVariable; public get objectA(): Object { return this.__backing_objectA!.get(); @@ -163,7 +166,7 @@ final class Status extends BaseEnum { this.__backing_objectA!.set(value); } - private __backing_dateA?: StorageLinkDecoratedVariable; + private __backing_dateA?: IStorageLinkDecoratedVariable; public get dateA(): Date { return this.__backing_dateA!.get(); @@ -173,7 +176,7 @@ final class Status extends BaseEnum { this.__backing_dateA!.set(value); } - private __backing_setA?: StorageLinkDecoratedVariable>; + private __backing_setA?: IStorageLinkDecoratedVariable>; public get setA(): Set { return this.__backing_setA!.get(); @@ -183,7 +186,7 @@ final class Status extends BaseEnum { this.__backing_setA!.set(value); } - private __backing_mapA?: StorageLinkDecoratedVariable>; + private __backing_mapA?: IStorageLinkDecoratedVariable>; public get mapA(): Map { return this.__backing_mapA!.get(); @@ -193,7 +196,7 @@ final class Status extends BaseEnum { this.__backing_mapA!.set(value); } - private __backing_unionA?: StorageLinkDecoratedVariable; + private __backing_unionA?: IStorageLinkDecoratedVariable; public get unionA(): string | undefined { return this.__backing_unionA!.get(); @@ -203,7 +206,7 @@ final class Status extends BaseEnum { this.__backing_unionA!.set(value); } - private __backing_classA?: StorageLinkDecoratedVariable; + private __backing_classA?: IStorageLinkDecoratedVariable; public get classA(): Person { return this.__backing_classA!.get(); @@ -213,7 +216,7 @@ final class Status extends BaseEnum { this.__backing_classA!.set(value); } - private __backing_enumA?: StorageLinkDecoratedVariable; + private __backing_enumA?: IStorageLinkDecoratedVariable; public get enumA(): Status { return this.__backing_enumA!.get(); @@ -233,51 +236,51 @@ final class Status extends BaseEnum { set arrayA(arrayA: Array | undefined) get arrayA(): Array | undefined - set __backing_arrayA(__backing_arrayA: StorageLinkDecoratedVariable> | undefined) + set __backing_arrayA(__backing_arrayA: IStorageLinkDecoratedVariable> | undefined) - get __backing_arrayA(): StorageLinkDecoratedVariable> | undefined + get __backing_arrayA(): IStorageLinkDecoratedVariable> | undefined set objectA(objectA: Object | undefined) get objectA(): Object | undefined - set __backing_objectA(__backing_objectA: StorageLinkDecoratedVariable | undefined) + set __backing_objectA(__backing_objectA: IStorageLinkDecoratedVariable | undefined) - get __backing_objectA(): StorageLinkDecoratedVariable | undefined + get __backing_objectA(): IStorageLinkDecoratedVariable | undefined set dateA(dateA: Date | undefined) get dateA(): Date | undefined - set __backing_dateA(__backing_dateA: StorageLinkDecoratedVariable | undefined) + set __backing_dateA(__backing_dateA: IStorageLinkDecoratedVariable | undefined) - get __backing_dateA(): StorageLinkDecoratedVariable | undefined + get __backing_dateA(): IStorageLinkDecoratedVariable | undefined set setA(setA: Set | undefined) get setA(): Set | undefined - set __backing_setA(__backing_setA: StorageLinkDecoratedVariable> | undefined) + set __backing_setA(__backing_setA: IStorageLinkDecoratedVariable> | undefined) - get __backing_setA(): StorageLinkDecoratedVariable> | undefined + get __backing_setA(): IStorageLinkDecoratedVariable> | undefined set mapA(mapA: Map | undefined) get mapA(): Map | undefined - set __backing_mapA(__backing_mapA: StorageLinkDecoratedVariable> | undefined) + set __backing_mapA(__backing_mapA: IStorageLinkDecoratedVariable> | undefined) - get __backing_mapA(): StorageLinkDecoratedVariable> | undefined + get __backing_mapA(): IStorageLinkDecoratedVariable> | undefined set unionA(unionA: string | undefined | undefined) get unionA(): string | undefined | undefined - set __backing_unionA(__backing_unionA: StorageLinkDecoratedVariable | undefined | undefined) + set __backing_unionA(__backing_unionA: IStorageLinkDecoratedVariable | undefined) - get __backing_unionA(): StorageLinkDecoratedVariable | undefined | undefined + get __backing_unionA(): IStorageLinkDecoratedVariable | undefined set classA(classA: Person | undefined) get classA(): Person | undefined - set __backing_classA(__backing_classA: StorageLinkDecoratedVariable | undefined) + set __backing_classA(__backing_classA: IStorageLinkDecoratedVariable | undefined) - get __backing_classA(): StorageLinkDecoratedVariable | undefined + get __backing_classA(): IStorageLinkDecoratedVariable | undefined set enumA(enumA: Status | undefined) get enumA(): Status | undefined - set __backing_enumA(__backing_enumA: StorageLinkDecoratedVariable | undefined) + set __backing_enumA(__backing_enumA: IStorageLinkDecoratedVariable | undefined) - get __backing_enumA(): StorageLinkDecoratedVariable | undefined + get __backing_enumA(): IStorageLinkDecoratedVariable | undefined } @@ -291,7 +294,6 @@ class __EntryWrapper extends EntryPoint { public constructor() {} } - `; function testStorageLinkTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts index 1d0c605c329fc2877f1782312b155c9d9be3d30d..b5c5f0004852723563f19f1eae9c65baa6432d02 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storagelink/storagelink-primitive-type.test.ts @@ -38,9 +38,12 @@ const storageLinkTransform: Plugins = { const pluginTester = new PluginTester('test storagelink primitive type transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StorageLinkDecoratedVariable as StorageLinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageLink"; +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; import { EntryPoint as EntryPoint } from "arkui.UserView"; @@ -54,16 +57,16 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_numA = new StorageLinkDecoratedVariable("Prop1", "numA", 33) - this.__backing_stringA = new StorageLinkDecoratedVariable("Prop2", "stringA", "AA") - this.__backing_booleanA = new StorageLinkDecoratedVariable("Prop3", "booleanA", true) + this.__backing_numA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop1", "numA", 33) + this.__backing_stringA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "stringA", "AA") + this.__backing_booleanA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop3", "booleanA", true) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_numA?: StorageLinkDecoratedVariable; + private __backing_numA?: IStorageLinkDecoratedVariable; public get numA(): number { return this.__backing_numA!.get(); @@ -73,7 +76,7 @@ function main() {} this.__backing_numA!.set(value); } - private __backing_stringA?: StorageLinkDecoratedVariable; + private __backing_stringA?: IStorageLinkDecoratedVariable; public get stringA(): string { return this.__backing_stringA!.get(); @@ -83,7 +86,7 @@ function main() {} this.__backing_stringA!.set(value); } - private __backing_booleanA?: StorageLinkDecoratedVariable; + private __backing_booleanA?: IStorageLinkDecoratedVariable; public get booleanA(): boolean { return this.__backing_booleanA!.get(); @@ -103,21 +106,21 @@ function main() {} set numA(numA: number | undefined) get numA(): number | undefined - set __backing_numA(__backing_numA: StorageLinkDecoratedVariable | undefined) + set __backing_numA(__backing_numA: IStorageLinkDecoratedVariable | undefined) - get __backing_numA(): StorageLinkDecoratedVariable | undefined + get __backing_numA(): IStorageLinkDecoratedVariable | undefined set stringA(stringA: string | undefined) get stringA(): string | undefined - set __backing_stringA(__backing_stringA: StorageLinkDecoratedVariable | undefined) + set __backing_stringA(__backing_stringA: IStorageLinkDecoratedVariable | undefined) - get __backing_stringA(): StorageLinkDecoratedVariable | undefined + get __backing_stringA(): IStorageLinkDecoratedVariable | undefined set booleanA(booleanA: boolean | undefined) get booleanA(): boolean | undefined - set __backing_booleanA(__backing_booleanA: StorageLinkDecoratedVariable | undefined) + set __backing_booleanA(__backing_booleanA: IStorageLinkDecoratedVariable | undefined) - get __backing_booleanA(): StorageLinkDecoratedVariable | undefined + get __backing_booleanA(): IStorageLinkDecoratedVariable | undefined } @@ -131,7 +134,6 @@ class __EntryWrapper extends EntryPoint { public constructor() {} } - `; function testStorageLinkTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts index e36e4f899073182ca0a5fe46610befe3e52869d6..cb445a245e5855c2d4087521cd4d44bd8017047d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-appstorage.test.ts @@ -38,12 +38,21 @@ const storagePropTransform: Plugins = { const pluginTester = new PluginTester('test storageprop with appstorage', buildConfig); const expectedScript: string = ` -import { StoragePropDecoratedVariable as StoragePropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageProp"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UITextAttribute as UITextAttribute } from "arkui.component.text"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry, Column as Column, Text as Text, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + import { StorageProp as StorageProp, AppStorage as AppStorage } from "@ohos.arkui.stateManagement"; function main() {} @@ -60,15 +69,15 @@ class Data { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class Index extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_storageProp = new StoragePropDecoratedVariable("PropA", "storageProp", 1) - this.__backing_storagePropObject = new StoragePropDecoratedVariable("PropB", "storagePropObject", new Data(1)) + this.__backing_storageProp = STATE_MGMT_FACTORY.makeStorageProp(this, "PropA", "storageProp", 1) + this.__backing_storagePropObject = STATE_MGMT_FACTORY.makeStorageProp(this, "PropB", "storagePropObject", new Data(1)) } public __updateStruct(initializers: __Options_Index | undefined): void {} - private __backing_storageProp?: StoragePropDecoratedVariable; + private __backing_storageProp?: IStoragePropDecoratedVariable; public get storageProp(): number { return this.__backing_storageProp!.get(); @@ -78,7 +87,7 @@ class Data { this.__backing_storageProp!.set(value); } - private __backing_storagePropObject?: StoragePropDecoratedVariable; + private __backing_storagePropObject?: IStoragePropDecoratedVariable; public get storagePropObject(): Data { return this.__backing_storagePropObject!.get(); @@ -90,13 +99,13 @@ class Data { @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { Column(undefined, (() => { - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { this.storageProp += 1; })); return; }), \`From AppStorage \${this.storageProp}\`); - Text(@memo() ((instance: UITextAttribute): void => { + Text(((instance: TextAttribute): void => { instance.onClick(((e: ClickEvent) => { this.storagePropObject.code += 1; })); @@ -113,15 +122,15 @@ class Data { set storageProp(storageProp: number | undefined) get storageProp(): number | undefined - set __backing_storageProp(__backing_storageProp: StoragePropDecoratedVariable | undefined) + set __backing_storageProp(__backing_storageProp: IStoragePropDecoratedVariable | undefined) - get __backing_storageProp(): StoragePropDecoratedVariable | undefined + get __backing_storageProp(): IStoragePropDecoratedVariable | undefined set storagePropObject(storagePropObject: Data | undefined) get storagePropObject(): Data | undefined - set __backing_storagePropObject(__backing_storagePropObject: StoragePropDecoratedVariable | undefined) + set __backing_storagePropObject(__backing_storagePropObject: IStoragePropDecoratedVariable | undefined) - get __backing_storagePropObject(): StoragePropDecoratedVariable | undefined + get __backing_storagePropObject(): IStoragePropDecoratedVariable | undefined } @@ -135,7 +144,6 @@ class __EntryWrapper extends EntryPoint { public constructor() {} } - `; function testStoragePropTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts index cdc384aa9ccf864f78eeef866a32918eb5482452..fc31881378e315c49a38455829f968a1b9beb4fc 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-complex-type.test.ts @@ -38,9 +38,12 @@ const storagePropTransform: Plugins = { const pluginTester = new PluginTester('test storageprop complex type transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StoragePropDecoratedVariable as StoragePropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageProp"; +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; import { EntryPoint as EntryPoint } from "arkui.UserView"; @@ -129,21 +132,21 @@ final class Status extends BaseEnum { } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_arrayB = new StoragePropDecoratedVariable>("Prop1", "arrayB", [1, 2, 3]) - this.__backing_objectB = new StoragePropDecoratedVariable("Prop2", "objectB", {}) - this.__backing_dateB = new StoragePropDecoratedVariable("Prop3", "dateB", new Date("2021-09-09")) - this.__backing_setB = new StoragePropDecoratedVariable>("Prop4", "setB", new Set()) - this.__backing_mapB = new StoragePropDecoratedVariable>("Prop5", "mapB", new Map()) - this.__backing_unionB = new StoragePropDecoratedVariable("Prop6", "unionB", "") - this.__backing_classB = new StoragePropDecoratedVariable("Prop7", "classB", new Person("Kevin")) - this.__backing_enumB = new StoragePropDecoratedVariable("Prop8", "enumB", Status.NotFound) + this.__backing_arrayB = STATE_MGMT_FACTORY.makeStorageProp>(this, "Prop1", "arrayB", [1, 2, 3]) + this.__backing_objectB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop2", "objectB", {}) + this.__backing_dateB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop3", "dateB", new Date("2021-09-09")) + this.__backing_setB = STATE_MGMT_FACTORY.makeStorageProp>(this, "Prop4", "setB", new Set()) + this.__backing_mapB = STATE_MGMT_FACTORY.makeStorageProp>(this, "Prop5", "mapB", new Map()) + this.__backing_unionB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop6", "unionB", "") + this.__backing_classB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop7", "classB", new Person("Kevin")) + this.__backing_enumB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop8", "enumB", Status.NotFound) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_arrayB?: StoragePropDecoratedVariable>; + private __backing_arrayB?: IStoragePropDecoratedVariable>; public get arrayB(): Array { return this.__backing_arrayB!.get(); @@ -153,7 +156,7 @@ final class Status extends BaseEnum { this.__backing_arrayB!.set(value); } - private __backing_objectB?: StoragePropDecoratedVariable; + private __backing_objectB?: IStoragePropDecoratedVariable; public get objectB(): Object { return this.__backing_objectB!.get(); @@ -163,7 +166,7 @@ final class Status extends BaseEnum { this.__backing_objectB!.set(value); } - private __backing_dateB?: StoragePropDecoratedVariable; + private __backing_dateB?: IStoragePropDecoratedVariable; public get dateB(): Date { return this.__backing_dateB!.get(); @@ -173,7 +176,7 @@ final class Status extends BaseEnum { this.__backing_dateB!.set(value); } - private __backing_setB?: StoragePropDecoratedVariable>; + private __backing_setB?: IStoragePropDecoratedVariable>; public get setB(): Set { return this.__backing_setB!.get(); @@ -183,7 +186,7 @@ final class Status extends BaseEnum { this.__backing_setB!.set(value); } - private __backing_mapB?: StoragePropDecoratedVariable>; + private __backing_mapB?: IStoragePropDecoratedVariable>; public get mapB(): Map { return this.__backing_mapB!.get(); @@ -193,7 +196,7 @@ final class Status extends BaseEnum { this.__backing_mapB!.set(value); } - private __backing_unionB?: StoragePropDecoratedVariable; + private __backing_unionB?: IStoragePropDecoratedVariable; public get unionB(): string | undefined { return this.__backing_unionB!.get(); @@ -203,7 +206,7 @@ final class Status extends BaseEnum { this.__backing_unionB!.set(value); } - private __backing_classB?: StoragePropDecoratedVariable; + private __backing_classB?: IStoragePropDecoratedVariable; public get classB(): Person { return this.__backing_classB!.get(); @@ -213,7 +216,7 @@ final class Status extends BaseEnum { this.__backing_classB!.set(value); } - private __backing_enumB?: StoragePropDecoratedVariable; + private __backing_enumB?: IStoragePropDecoratedVariable; public get enumB(): Status { return this.__backing_enumB!.get(); @@ -233,51 +236,51 @@ final class Status extends BaseEnum { set arrayB(arrayB: Array | undefined) get arrayB(): Array | undefined - set __backing_arrayB(__backing_arrayB: StoragePropDecoratedVariable> | undefined) + set __backing_arrayB(__backing_arrayB: IStoragePropDecoratedVariable> | undefined) - get __backing_arrayB(): StoragePropDecoratedVariable> | undefined + get __backing_arrayB(): IStoragePropDecoratedVariable> | undefined set objectB(objectB: Object | undefined) get objectB(): Object | undefined - set __backing_objectB(__backing_objectB: StoragePropDecoratedVariable | undefined) + set __backing_objectB(__backing_objectB: IStoragePropDecoratedVariable | undefined) - get __backing_objectB(): StoragePropDecoratedVariable | undefined + get __backing_objectB(): IStoragePropDecoratedVariable | undefined set dateB(dateB: Date | undefined) get dateB(): Date | undefined - set __backing_dateB(__backing_dateB: StoragePropDecoratedVariable | undefined) + set __backing_dateB(__backing_dateB: IStoragePropDecoratedVariable | undefined) - get __backing_dateB(): StoragePropDecoratedVariable | undefined + get __backing_dateB(): IStoragePropDecoratedVariable | undefined set setB(setB: Set | undefined) get setB(): Set | undefined - set __backing_setB(__backing_setB: StoragePropDecoratedVariable> | undefined) + set __backing_setB(__backing_setB: IStoragePropDecoratedVariable> | undefined) - get __backing_setB(): StoragePropDecoratedVariable> | undefined + get __backing_setB(): IStoragePropDecoratedVariable> | undefined set mapB(mapB: Map | undefined) get mapB(): Map | undefined - set __backing_mapB(__backing_mapB: StoragePropDecoratedVariable> | undefined) + set __backing_mapB(__backing_mapB: IStoragePropDecoratedVariable> | undefined) - get __backing_mapB(): StoragePropDecoratedVariable> | undefined + get __backing_mapB(): IStoragePropDecoratedVariable> | undefined set unionB(unionB: string | undefined | undefined) get unionB(): string | undefined | undefined - set __backing_unionB(__backing_unionB: StoragePropDecoratedVariable | undefined | undefined) + set __backing_unionB(__backing_unionB: IStoragePropDecoratedVariable | undefined) - get __backing_unionB(): StoragePropDecoratedVariable | undefined | undefined + get __backing_unionB(): IStoragePropDecoratedVariable | undefined set classB(classB: Person | undefined) get classB(): Person | undefined - set __backing_classB(__backing_classB: StoragePropDecoratedVariable | undefined) + set __backing_classB(__backing_classB: IStoragePropDecoratedVariable | undefined) - get __backing_classB(): StoragePropDecoratedVariable | undefined + get __backing_classB(): IStoragePropDecoratedVariable | undefined set enumB(enumB: Status | undefined) get enumB(): Status | undefined - set __backing_enumB(__backing_enumB: StoragePropDecoratedVariable | undefined) + set __backing_enumB(__backing_enumB: IStoragePropDecoratedVariable | undefined) - get __backing_enumB(): StoragePropDecoratedVariable | undefined + get __backing_enumB(): IStoragePropDecoratedVariable | undefined } diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts index a346288beaa8840c21dbcd3aefa1b69887f85b99..ae362590aeb471758c0b306b19d4469913fa938d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/storageprop/storageprop-primitive-type.test.ts @@ -38,9 +38,12 @@ const storagePropTransform: Plugins = { const pluginTester = new PluginTester('test storageprop primitive type transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { StoragePropDecoratedVariable as StoragePropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageProp"; +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; import { EntryPoint as EntryPoint } from "arkui.UserView"; @@ -54,16 +57,16 @@ function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_numB = new StoragePropDecoratedVariable("Prop1", "numB", 43) - this.__backing_stringB = new StoragePropDecoratedVariable("Prop2", "stringB", "BB") - this.__backing_booleanB = new StoragePropDecoratedVariable("Prop3", "booleanB", false) + this.__backing_numB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop1", "numB", 43) + this.__backing_stringB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop2", "stringB", "BB") + this.__backing_booleanB = STATE_MGMT_FACTORY.makeStorageProp(this, "Prop3", "booleanB", false) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_numB?: StoragePropDecoratedVariable; + private __backing_numB?: IStoragePropDecoratedVariable; public get numB(): number { return this.__backing_numB!.get(); @@ -73,7 +76,7 @@ function main() {} this.__backing_numB!.set(value); } - private __backing_stringB?: StoragePropDecoratedVariable; + private __backing_stringB?: IStoragePropDecoratedVariable; public get stringB(): string { return this.__backing_stringB!.get(); @@ -83,7 +86,7 @@ function main() {} this.__backing_stringB!.set(value); } - private __backing_booleanB?: StoragePropDecoratedVariable; + private __backing_booleanB?: IStoragePropDecoratedVariable; public get booleanB(): boolean { return this.__backing_booleanB!.get(); @@ -103,21 +106,21 @@ function main() {} set numB(numB: number | undefined) get numB(): number | undefined - set __backing_numB(__backing_numB: StoragePropDecoratedVariable | undefined) + set __backing_numB(__backing_numB: IStoragePropDecoratedVariable | undefined) - get __backing_numB(): StoragePropDecoratedVariable | undefined + get __backing_numB(): IStoragePropDecoratedVariable | undefined set stringB(stringB: string | undefined) get stringB(): string | undefined - set __backing_stringB(__backing_stringB: StoragePropDecoratedVariable | undefined) + set __backing_stringB(__backing_stringB: IStoragePropDecoratedVariable | undefined) - get __backing_stringB(): StoragePropDecoratedVariable | undefined + get __backing_stringB(): IStoragePropDecoratedVariable | undefined set booleanB(booleanB: boolean | undefined) get booleanB(): boolean | undefined - set __backing_booleanB(__backing_booleanB: StoragePropDecoratedVariable | undefined) + set __backing_booleanB(__backing_booleanB: IStoragePropDecoratedVariable | undefined) - get __backing_booleanB(): StoragePropDecoratedVariable | undefined + get __backing_booleanB(): IStoragePropDecoratedVariable | undefined } diff --git a/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts index f28e43d82eac2fa602c8f7d727e30634ee2a3158..46e1fe9438992c8ed952bcd0139af28735fe609d 100644 --- a/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/decorators/watch/watch-basic.test.ts @@ -38,28 +38,55 @@ const watchTransform: Plugins = { const pluginTester = new PluginTester('test basic watch transform', buildConfig); const expectedScript: string = ` + +import { IConsumeDecoratedVariable as IConsumeDecoratedVariable } from "arkui.stateManagement.decorator"; + import { memo as memo } from "arkui.stateManagement.runtime"; -import { ProvideDecoratedVariable as ProvideDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProvide"; -import { StoragePropDecoratedVariable as StoragePropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageProp"; -import { StorageLinkDecoratedVariable as StorageLinkDecoratedVariable } from "arkui.stateManagement.decorators.decoratorStorageLink"; -import { PropDecoratedVariable as PropDecoratedVariable } from "arkui.stateManagement.decorators.decoratorProp"; -import { StateDecoratedVariable as StateDecoratedVariable } from "arkui.stateManagement.decorators.decoratorState"; -import { IObservedObject as IObservedObject } from "arkui.stateManagement.base.iObservedObject"; -import { MutableStateMeta as MutableStateMeta } from "arkui.stateManagement.base.mutableStateMeta"; -import { int32 as int32 } from "@koalaui.runtime.common"; -import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorators.decoratorWatch"; -import { SubscribedWatches as SubscribedWatches } from "arkui.stateManagement.decorators.decoratorWatch"; + +import { IProvideDecoratedVariable as IProvideDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IObjectLinkDecoratedVariable as IObjectLinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { LinkSourceType as LinkSourceType } from "arkui.stateManagement.decorator"; + +import { ILinkDecoratedVariable as ILinkDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { IObservedObject as IObservedObject } from "arkui.stateManagement.decorator"; + +import { OBSERVE as OBSERVE } from "arkui.stateManagement.decorator"; + +import { IMutableStateMeta as IMutableStateMeta } from "arkui.stateManagement.decorator"; + +import { RenderIdType as RenderIdType } from "arkui.stateManagement.decorator"; + +import { WatchIdType as WatchIdType } from "arkui.stateManagement.decorator"; + +import { ISubscribedWatches as ISubscribedWatches } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Entry as Entry } from "@ohos.arkui.component"; + import { State as State, Prop as Prop, StorageLink as StorageLink, StorageProp as StorageProp, Link as Link, Watch as Watch, ObjectLink as ObjectLink, Observed as Observed, Track as Track, Provide as Provide, Consume as Consume } from "@ohos.arkui.stateManagement"; function main() {} -@Observed() class A implements IObservedObject { - private subscribedWatches: SubscribedWatches = new SubscribedWatches(); +@Observed() class A implements IObservedObject, ISubscribedWatches { + private subscribedWatches: ISubscribedWatches = STATE_MGMT_FACTORY.makeSubscribedWatches(); public addWatchSubscriber(watchId: WatchIdType): void { this.subscribedWatches.addWatchSubscriber(watchId); @@ -73,51 +100,69 @@ function main() {} this.subscribedWatches.executeOnSubscribingWatches(propertyName); } - public _permissibleAddRefDepth: int32 = 0; + private ____V1RenderId: RenderIdType = 0; + + public setV1RenderId(renderId: RenderIdType): void { + this.____V1RenderId = renderId; + } + + protected conditionalAddRef(meta: IMutableStateMeta): void { + if (OBSERVE.shouldAddRef(this.____V1RenderId)) { + meta.addRef(); + } + } public propA: string = "hello"; private __backing_trackA: string = "world"; - private __meta_trackA: MutableStateMeta = new MutableStateMeta("@Track"); + private __meta_trackA: IMutableStateMeta = STATE_MGMT_FACTORY.makeMutableStateMeta(); public constructor() {} public get trackA(): string { - if (((this._permissibleAddRefDepth) > (0))) { - this.__meta_trackA.addRef(); - } + this.conditionalAddRef(this.__meta_trackA); return this.__backing_trackA; } public set trackA(newValue: string) { if (((this.__backing_trackA) !== (newValue))) { this.__backing_trackA = newValue; - this.__meta_trackA.fireChange(); - this.executeOnSubscribingWatches("trackA"); + this.__meta_trackA.fireChange(); + this.executeOnSubscribingWatches("trackA"); } } } -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class MyStateSample extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct MyStateSample extends CustomComponent { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_statevar = new StateDecoratedVariable("statevar", ((({let gensym___76198660 = initializers; + this.__backing_statevar = STATE_MGMT_FACTORY.makeState(this, "statevar", ((({let gensym___76198660 = initializers; (((gensym___76198660) == (null)) ? undefined : gensym___76198660.statevar)})) ?? ("Hello World")), ((_: string): void => { this.stateOnChange(_); })); - this.__backing_propvar = new PropDecoratedVariable("propvar", ((({let gensym___241486692 = initializers; + this.__backing_propvar = STATE_MGMT_FACTORY.makeProp(this, "propvar", ((({let gensym___241486692 = initializers; (((gensym___241486692) == (null)) ? undefined : gensym___241486692.propvar)})) ?? ("Hello World")), ((_: string): void => { this.propOnChange(_); })); - this.__backing_storagelinkvar = new StorageLinkDecoratedVariable("prop1", "storagelinkvar", "Hello World", ((_: string): void => { + if (({let gensym___165820150 = initializers; + (((gensym___165820150) == (null)) ? undefined : gensym___165820150.__backing_linkvar)})) { + this.__backing_linkvar = STATE_MGMT_FACTORY.makeLink(this, "linkvar", initializers!.__backing_linkvar!, ((_: string): void => { + this.linkOnChange(_); + })); + }; + this.__backing_storagelinkvar = STATE_MGMT_FACTORY.makeStorageLink(this, "prop1", "storagelinkvar", "Hello World", ((_: string): void => { this.storageLinkOnChange(_); })) - this.__backing_storagepropvar = new StoragePropDecoratedVariable("prop2", "storagepropvar", "Hello World", ((_: string): void => { + this.__backing_storagepropvar = STATE_MGMT_FACTORY.makeStorageProp(this, "prop2", "storagepropvar", "Hello World", ((_: string): void => { this.storagePropOnChange(_); })) - this.__backing_providevar = this.addProvidedVar("providevar", "providevar", ((({let gensym___194235814 = initializers; - (((gensym___194235814) == (null)) ? undefined : gensym___194235814.providevar)})) ?? ("Hello World")), false, ((_: string): void => { + this.__backing_objectlinkvar = STATE_MGMT_FACTORY.makeObjectLink(this, "objectlinkvar", ({let gensym___172556967 = initializers; + (((gensym___172556967) == (null)) ? undefined : gensym___172556967.objectlinkvar)})!, ((_: string): void => { + this.objectLinkOnChange(_); + })) + this.__backing_providevar = STATE_MGMT_FACTORY.makeProvide(this, "providevar", "providevar", ((({let gensym___244584558 = initializers; + (((gensym___244584558) == (null)) ? undefined : gensym___244584558.providevar)})) ?? ("Hello World")), false, ((_: string): void => { this.ProvideOnChange(_); })); } @@ -127,9 +172,13 @@ function main() {} (((gensym___220608839) == (null)) ? undefined : gensym___220608839.propvar)})) !== (undefined))) { this.__backing_propvar!.update((initializers!.propvar as string)); } + if (((({let gensym___164966179 = initializers; + (((gensym___164966179) == (null)) ? undefined : gensym___164966179.objectlinkvar)})) !== (undefined))) { + this.__backing_objectlinkvar!.update(initializers!.objectlinkvar!); + } } - private __backing_statevar?: StateDecoratedVariable; + private __backing_statevar?: IStateDecoratedVariable; public get statevar(): string { return this.__backing_statevar!.get(); @@ -139,7 +188,7 @@ function main() {} this.__backing_statevar!.set(value); } - private __backing_propvar?: PropDecoratedVariable; + private __backing_propvar?: IPropDecoratedVariable; public get propvar(): string { return this.__backing_propvar!.get(); @@ -149,7 +198,17 @@ function main() {} this.__backing_propvar!.set(value); } - private __backing_storagelinkvar?: StorageLinkDecoratedVariable; + private __backing_linkvar?: ILinkDecoratedVariable; + + public get linkvar(): string { + return this.__backing_linkvar!.get(); + } + + public set linkvar(value: string) { + this.__backing_linkvar!.set(value); + } + + private __backing_storagelinkvar?: IStorageLinkDecoratedVariable; public get storagelinkvar(): string { return this.__backing_storagelinkvar!.get(); @@ -159,7 +218,7 @@ function main() {} this.__backing_storagelinkvar!.set(value); } - private __backing_storagepropvar?: StoragePropDecoratedVariable; + private __backing_storagepropvar?: IStoragePropDecoratedVariable; public get storagepropvar(): string { return this.__backing_storagepropvar!.get(); @@ -169,7 +228,13 @@ function main() {} this.__backing_storagepropvar!.set(value); } - private __backing_providevar?: ProvideDecoratedVariable; + private __backing_objectlinkvar?: IObjectLinkDecoratedVariable; + + public get objectlinkvar(): A { + return this.__backing_objectlinkvar!.get(); + } + + private __backing_providevar?: IProvideDecoratedVariable; public get providevar(): string { return this.__backing_providevar!.get(); @@ -183,10 +248,14 @@ function main() {} public propOnChange(propName: string) {} + public linkOnChange(propName: string) {} + public storageLinkOnChange(propName: string) {} public storagePropOnChange(propName: string) {} + public objectLinkOnChange(propName: string) {} + public ProvideOnChange(propName: string) {} @memo() public _build(@memo() style: ((instance: MyStateSample)=> MyStateSample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_MyStateSample | undefined): void { @@ -199,52 +268,88 @@ function main() {} } -@Component({freezeWhenInactive:false}) final class Child extends CustomComponent { - public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void {} +@Component({freezeWhenInactive:false}) final struct Child extends CustomComponent { + public __initializeStruct(initializers: __Options_Child | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_providevar = STATE_MGMT_FACTORY.makeConsume(this, "providevar", "providevar", ((_: string): void => { + this.ConsumeOnChange(_); + })); + } public __updateStruct(initializers: __Options_Child | undefined): void {} + private __backing_providevar?: IConsumeDecoratedVariable; + + public get providevar(): string { + return this.__backing_providevar!.get(); + } + + public set providevar(value: string) { + this.__backing_providevar!.set(value); + } + + public ConsumeOnChange(propName: string) {} + @memo() public _build(@memo() style: ((instance: Child)=> Child) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Child | undefined): void {} private constructor() {} } +@Retention({policy:"SOURCE"}) @interface __Link_intrinsic {} + @Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_MyStateSample { set statevar(statevar: string | undefined) get statevar(): string | undefined - set __backing_statevar(__backing_statevar: StateDecoratedVariable | undefined) + set __backing_statevar(__backing_statevar: IStateDecoratedVariable | undefined) - get __backing_statevar(): StateDecoratedVariable | undefined + get __backing_statevar(): IStateDecoratedVariable | undefined set propvar(propvar: string | undefined) get propvar(): string | undefined - set __backing_propvar(__backing_propvar: PropDecoratedVariable | undefined) + set __backing_propvar(__backing_propvar: IPropDecoratedVariable | undefined) + + get __backing_propvar(): IPropDecoratedVariable | undefined + @__Link_intrinsic() set linkvar(linkvar: string | undefined) + + @__Link_intrinsic() get linkvar(): string | undefined + set __backing_linkvar(__backing_linkvar: LinkSourceType | undefined) - get __backing_propvar(): PropDecoratedVariable | undefined + get __backing_linkvar(): LinkSourceType | undefined set storagelinkvar(storagelinkvar: string | undefined) get storagelinkvar(): string | undefined - set __backing_storagelinkvar(__backing_storagelinkvar: StorageLinkDecoratedVariable | undefined) + set __backing_storagelinkvar(__backing_storagelinkvar: IStorageLinkDecoratedVariable | undefined) - get __backing_storagelinkvar(): StorageLinkDecoratedVariable | undefined + get __backing_storagelinkvar(): IStorageLinkDecoratedVariable | undefined set storagepropvar(storagepropvar: string | undefined) get storagepropvar(): string | undefined - set __backing_storagepropvar(__backing_storagepropvar: StoragePropDecoratedVariable | undefined) + set __backing_storagepropvar(__backing_storagepropvar: IStoragePropDecoratedVariable | undefined) - get __backing_storagepropvar(): StoragePropDecoratedVariable | undefined + get __backing_storagepropvar(): IStoragePropDecoratedVariable | undefined + set objectlinkvar(objectlinkvar: A | undefined) + + get objectlinkvar(): A | undefined + set __backing_objectlinkvar(__backing_objectlinkvar: IObjectLinkDecoratedVariable | undefined) + + get __backing_objectlinkvar(): IObjectLinkDecoratedVariable | undefined set providevar(providevar: string | undefined) get providevar(): string | undefined - set __backing_providevar(__backing_providevar: ProvideDecoratedVariable | undefined) + set __backing_providevar(__backing_providevar: IProvideDecoratedVariable | undefined) - get __backing_providevar(): ProvideDecoratedVariable | undefined + get __backing_providevar(): IProvideDecoratedVariable | undefined } @Component({freezeWhenInactive:false}) export interface __Options_Child { + set providevar(providevar: string | undefined) + + get providevar(): string | undefined + set __backing_providevar(__backing_providevar: IConsumeDecoratedVariable | undefined) + + get __backing_providevar(): IConsumeDecoratedVariable | undefined } @@ -258,7 +363,6 @@ class __EntryWrapper extends EntryPoint { public constructor() {} } - `; function testWatchTransformer(this: PluginTestContext): void { diff --git a/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts b/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts index 9a0601eeb61e4b1fa8c4532a57f24ad3f80eefb6..a1d525dd7c0d7066ecafa04ee423a8a34350eee3 100644 --- a/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/imports/import-struct.test.ts @@ -45,7 +45,7 @@ import { CustomComponent as CustomComponent } from \"arkui.component.customCompo import { Component as Component, Text as Text } from \"@ohos.arkui.component\"; import { SimpleStruct as SimpleStruct } from \"./utils/simple-struct\"; -@Component() final class ImportStruct extends CustomComponent { +@Component() final struct ImportStruct extends CustomComponent { public build() { SimpleStruct(); SimpleStruct(({ @@ -70,7 +70,7 @@ import { SimpleStruct as SimpleStruct } from \"./utils/simple-struct\"; function main() {} -@Component({freezeWhenInactive:false}) final class ImportStruct extends CustomComponent { +@Component({freezeWhenInactive:false}) final struct ImportStruct extends CustomComponent { public __initializeStruct(initializers: __Options_ImportStruct | undefined, @memo() content: (()=> void) | undefined): void {} public __updateStruct(initializers: __Options_ImportStruct | undefined): void {} @memo() public _build(@memo() style: ((instance: ImportStruct)=> ImportStruct) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_ImportStruct | undefined): void { diff --git a/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts b/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts index 0ea1ca2ad6082d77249cf6913271e597c41a7581..6b6b18ca0fa703f05ac2d26af3bf4c05b0ebf601 100644 --- a/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/imports/kit-import.test.ts @@ -38,117 +38,163 @@ const importParsed: Plugins = { const pluginTester = new PluginTester('test import transform', buildConfig); const expectedParsedScript: string = ` -import { EntryPoint as EntryPoint } from \"arkui.UserView\"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Prop as Prop, Column as Column, Entry as Entry } from \"@kit.ArkUI\"; -import { Text as Text, Component as Component, ClickEvent as ClickEvent } from \"@ohos.arkui.component\"; -import { State as State } from \"@ohos.arkui.stateManagement\"; -import { Button as Button } from \"arkui.component.button\"; -import hilog from \"@ohos.hilog\"; - -@Entry() @Component() final class A extends CustomComponent { - @State() public a: string = \"str\"; - @Prop() public b!: string; - - public build() { - Column(){ - Button(\"button\").onClick(((e: ClickEvent) => {})); - Text(\"text\").fontSize(20); - }; - } - public constructor() {} + +import { EntryPoint as EntryPoint } from "arkui.UserView"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Prop as Prop, Column as Column, Entry as Entry } from "@kit.ArkUI"; + +import { Text as Text, Component as Component, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + +import { State as State } from "@ohos.arkui.stateManagement"; + +import { Button as Button } from "arkui.component.button"; + +import hilog from "@ohos.hilog"; + +@Entry() @Component() final struct A extends CustomComponent { + @State() public a: string = "str"; + + @Prop() public b!: string; + + public build() { + Column(){ + Button("button").onClick(((e: ClickEvent) => {})); + Text("text").fontSize(20); + }; + } + + public constructor() {} + } @Entry() @Component() export interface __Options_A { - a?: string; - @State() __backing_a?: string; - b?: string; - @Prop() __backing_b?: string; + a?: string; + @State() __backing_a?: string; + b?: string; + @Prop() __backing_b?: string; + } class __EntryWrapper extends EntryPoint { - public entry(): void { - A(); - } - public constructor() {} + public entry(): void { + A(); + } + + public constructor() {} + } `; const expectedCheckedScript: string = ` -import { PropDecoratedVariable as PropDecoratedVariable } from \"arkui.stateManagement.decorators.decoratorProp\"; -import { StateDecoratedVariable as StateDecoratedVariable } from \"arkui.stateManagement.decorators.decoratorState\"; -import { memo as memo } from \"arkui.stateManagement.runtime\"; -import { UITextAttribute as UITextAttribute } from \"arkui.component.text\"; -import { UIButtonAttribute as UIButtonAttribute } from \"arkui.component.button\"; -import { EntryPoint as EntryPoint } from \"arkui.UserView\"; -import { CustomComponent as CustomComponent } from \"arkui.component.customComponent\"; -import { Prop as Prop, Column as Column, Entry as Entry } from \"@kit.ArkUI\"; -import { Text as Text, Component as Component, ClickEvent as ClickEvent } from \"@ohos.arkui.component\"; -import { State as State } from \"@ohos.arkui.stateManagement\"; -import { Button as Button } from \"arkui.component.button\"; -import hilog from \"@ohos.hilog\"; + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { IPropDecoratedVariable as IPropDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; + +import { IStateDecoratedVariable as IStateDecoratedVariable } from "arkui.stateManagement.decorator"; + +import { TextAttribute as TextAttribute } from "arkui.component.text"; + +import { ButtonAttribute as ButtonAttribute } from "arkui.component.button"; + +import { EntryPoint as EntryPoint } from "arkui.UserView"; + +import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + +import { Prop as Prop, Column as Column, Entry as Entry } from "@kit.ArkUI"; + +import { Text as Text, Component as Component, ClickEvent as ClickEvent } from "@ohos.arkui.component"; + +import { State as State } from "@ohos.arkui.stateManagement"; + +import { Button as Button } from "arkui.component.button"; + +import hilog from "@ohos.hilog"; function main() {} -@Entry({useSharedStorage:false,storage:\"\",routeName:\"\"}) @Component({freezeWhenInactive:false}) final class A extends CustomComponent { - public __initializeStruct(initializers: __Options_A | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_a = new StateDecoratedVariable(\"a\", ((({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.a)})) ?? (\"str\"))); - this.__backing_b = new PropDecoratedVariable(\"b\", (initializers!.b as string)); - } - public __updateStruct(initializers: __Options_A | undefined): void { - if (((({let gensym___ = initializers; - (((gensym___) == (null)) ? undefined : gensym___.b)})) !== (undefined))) { - this.__backing_b!.update((initializers!.b as string)); - } - } - private __backing_a?: StateDecoratedVariable; - public get a(): string { - return this.__backing_a!.get(); - } - public set a(value: string) { - this.__backing_a!.set(value); - } - private __backing_b?: PropDecoratedVariable; - public get b(): string { - return this.__backing_b!.get(); - } - public set b(value: string) { - this.__backing_b!.set(value); - } - @memo() public _build(@memo() style: ((instance: A)=> A) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_A | undefined): void { - Column(undefined, (() => { - Button(@memo() ((instance: UIButtonAttribute): void => { - instance.onClick(((e: ClickEvent) => {})); - return; - }), \"button\"); - Text(@memo() ((instance: UITextAttribute): void => { - instance.fontSize(20); - return; - }), \"text\"); - })); + + +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct A extends CustomComponent { + public __initializeStruct(initializers: __Options_A | undefined, @memo() content: (()=> void) | undefined): void { + this.__backing_a = STATE_MGMT_FACTORY.makeState(this, "a", ((({let gensym___94024326 = initializers; + (((gensym___94024326) == (null)) ? undefined : gensym___94024326.a)})) ?? ("str"))); + this.__backing_b = STATE_MGMT_FACTORY.makeProp(this, "b", (initializers!.b as string)); + } + + public __updateStruct(initializers: __Options_A | undefined): void { + if (((({let gensym___81454501 = initializers; + (((gensym___81454501) == (null)) ? undefined : gensym___81454501.b)})) !== (undefined))) { + this.__backing_b!.update((initializers!.b as string)); } - private constructor() {} + } + + private __backing_a?: IStateDecoratedVariable; + + public get a(): string { + return this.__backing_a!.get(); + } + + public set a(value: string) { + this.__backing_a!.set(value); + } + + private __backing_b?: IPropDecoratedVariable; + + public get b(): string { + return this.__backing_b!.get(); + } + + public set b(value: string) { + this.__backing_b!.set(value); + } + + @memo() public _build(@memo() style: ((instance: A)=> A) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_A | undefined): void { + Column(undefined, (() => { + Button(((instance: ButtonAttribute): void => { + instance.onClick(((e: ClickEvent) => {})); + return; + }), "button"); + Text(((instance: TextAttribute): void => { + instance.fontSize(20); + return; + }), "text"); + })); + } + + private constructor() {} + } -@Entry({useSharedStorage:false,storage:\"\",routeName:\"\"}) @Component({freezeWhenInactive:false}) export interface __Options_A { - set a(a: string | undefined) - get a(): string | undefined - set __backing_a(__backing_a: StateDecoratedVariable | undefined) - get __backing_a(): StateDecoratedVariable | undefined - set b(b: string | undefined) - get b(): string | undefined - set __backing_b(__backing_b: PropDecoratedVariable | undefined) - get __backing_b(): PropDecoratedVariable | undefined +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) export interface __Options_A { + set a(a: string | undefined) + + get a(): string | undefined + set __backing_a(__backing_a: IStateDecoratedVariable | undefined) + + get __backing_a(): IStateDecoratedVariable | undefined + set b(b: string | undefined) + + get b(): string | undefined + set __backing_b(__backing_b: IPropDecoratedVariable | undefined) + + get __backing_b(): IPropDecoratedVariable | undefined + } class __EntryWrapper extends EntryPoint { - @memo() public entry(): void { - A._instantiateImpl(undefined, (() => { - return new A(); - })); - } - public constructor() {} + @memo() public entry(): void { + A._instantiateImpl(undefined, (() => { + return new A(); + })); + } + + public constructor() {} + } `; diff --git a/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts b/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts index 7a38d75448d929665ff9522029e0384a98e18ecb..893cdfbc7dd73cf35be72b56b3887378f0fb1160 100644 --- a/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts +++ b/arkui-plugins/test/ut/ui-plugins/xcomponent/xcomponent-basic.test.ts @@ -38,17 +38,22 @@ const xcomponentTransform: Plugins = { const pluginTester = new PluginTester('test basic XComponent transform', buildConfig); const expectedScript: string = ` + import { memo as memo } from "arkui.stateManagement.runtime"; -import { UIFlexAttribute as UIFlexAttribute } from "arkui.component.flex"; + +import { FlexAttribute as FlexAttribute } from "arkui.component.flex"; + import { EntryPoint as EntryPoint } from "arkui.UserView"; + import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; + import { Component as Component, Flex as Flex, XComponent as XComponent, FlexDirection as FlexDirection, XComponentType as XComponentType, Entry as Entry, XComponentController as XComponentController, ItemAlign as ItemAlign, FlexAlign as FlexAlign, XComponentParameter as XComponentParameter } from "@ohos.arkui.component"; function main() {} -@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class Index extends CustomComponent { +@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final struct Index extends CustomComponent { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { this.__backing_myXComponentController = ((({let gensym___221905990 = initializers; (((gensym___221905990) == (null)) ? undefined : gensym___221905990.myXComponentController)})) ?? (new XComponentController())); @@ -67,7 +72,7 @@ function main() {} } @memo() public _build(@memo() style: ((instance: Index)=> Index) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_Index | undefined): void { - Flex(@memo() ((instance: UIFlexAttribute): void => { + Flex(((instance: FlexAttribute): void => { instance.width("100%").height("100%"); return; }), { @@ -107,8 +112,136 @@ class __EntryWrapper extends EntryPoint { } `; +const expectedHeader: string = ` + +import { memo as memo } from "arkui.stateManagement.runtime"; + +import { ImageAIOptions as ImageAIOptions, ImageAnalyzerConfig as ImageAnalyzerConfig } from "./imageCommon"; + +import { CommonMethod as CommonMethod, AttributeModifier as AttributeModifier } from "./common"; + +import { XComponentType as XComponentType } from "./enums"; + +import { VoidCallback as VoidCallback } from "./units"; + +import { memo as memo, ComponentBuilder as ComponentBuilder } from "./../stateManagement/runtime"; + +function main() {} + + +@memo() export function XComponent(@memo() style?: ((instance: XComponentAttribute)=> void), params: XComponentParameter | XComponentOptions | NativeXComponentParameters, packageInfo: string, @memo() content_?: (()=> void)): void + + +export declare interface SurfaceRect { + set offsetX(offsetX: number | undefined) + + get offsetX(): number | undefined + set offsetY(offsetY: number | undefined) + + get offsetY(): number | undefined + set surfaceWidth(surfaceWidth: number) + + get surfaceWidth(): number + set surfaceHeight(surfaceHeight: number) + + get surfaceHeight(): number + +} + +export declare interface SurfaceRotationOptions { + set lock(lock: boolean | undefined) + + get lock(): boolean | undefined + +} + +export declare class XComponentController { + public constructor() + + public getXComponentSurfaceId(): string + + public getXComponentContext(): Object + + public setXComponentSurfaceRect(rect: SurfaceRect): void + + public getXComponentSurfaceRect(): SurfaceRect + + public setXComponentSurfaceRotation(rotationOptions: SurfaceRotationOptions): void + + public getXComponentSurfaceRotation(): Required + + public onSurfaceCreated(surfaceId: string): void + + public onSurfaceChanged(surfaceId: string, rect: SurfaceRect): void + + public onSurfaceDestroyed(surfaceId: string): void + + public startImageAnalyzer(config: ImageAnalyzerConfig): Promise + + public stopImageAnalyzer(): void + +} + +export declare interface XComponentOptions { + set type(type: XComponentType) + + get type(): XComponentType + set controller(controller: XComponentController) + + get controller(): XComponentController + set imageAIOptions(imageAIOptions: ImageAIOptions | undefined) + + get imageAIOptions(): ImageAIOptions | undefined + set screenId(screenId: number | undefined) + + get screenId(): number | undefined + +} + +export declare interface NativeXComponentParameters { + set type(type: XComponentType) + + get type(): XComponentType + set imageAIOptions(imageAIOptions: ImageAIOptions | undefined) + + get imageAIOptions(): ImageAIOptions | undefined + +} + +export type OnNativeLoadCallback = ((event?: object)=> void); + +export declare interface XComponentAttribute extends CommonMethod { + onLoad(callback: OnNativeLoadCallback | undefined): this + onDestroy(event: VoidCallback | undefined): this + enableAnalyzer(enable: boolean | undefined): this + enableSecure(isSecure: boolean | undefined): this + hdrBrightness(brightness: number | undefined): this + enableTransparentLayer(enabled: boolean | undefined): this + attributeModifier(modifier: AttributeModifier | AttributeModifier | undefined): this + +} + +export declare interface XComponentParameter { + set id(id: string) + + get id(): string + set type(type: XComponentType) + + get type(): XComponentType + set libraryname(libraryname: string | undefined) + + get libraryname(): string | undefined + set controller(controller: XComponentController | undefined) + + get controller(): XComponentController | undefined + +} +` + function testXComponentTransformer(this: PluginTestContext): void { expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript)); + expect(parseDumpSrc(this.declContexts?.['arkui.component.xcomponent']?.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedHeader)); + } pluginTester.run( @@ -119,5 +252,6 @@ pluginTester.run( }, { stopAfter: 'checked', + tracing: {externalSourceNames:['arkui.component.xcomponent']} } ); diff --git a/arkui-plugins/test/utils/plugin-tester.ts b/arkui-plugins/test/utils/plugin-tester.ts index 8a64da3fc7a740eb3a4e60b12499083463bf8ba3..7b5a40dc9082236870be283785b09b4fe183ab1f 100644 --- a/arkui-plugins/test/utils/plugin-tester.ts +++ b/arkui-plugins/test/utils/plugin-tester.ts @@ -165,7 +165,7 @@ class PluginTester { } private async compile(plugins: Plugins[], stopAfter?: PluginState, tracing?: TraceOptions): Promise { - this.taskProcessor = new TaskProcessor(this.hashId, this.configBuilder.buildConfig); + this.taskProcessor = new TaskProcessor(this.hashId, this.configBuilder.buildConfig, tracing); return this.taskProcessor.invokeWorkers(plugins, stopAfter); } @@ -196,7 +196,7 @@ class PluginTester { that.clear(); }); - that.resolve = that.compile(plugins, options.stopAfter); + that.resolve = that.compile(plugins, options.stopAfter, options.tracing); that.compileTests(testName, pluginHooks); }); } diff --git a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts index 7171c74dde56200f6a946f4f45bb86907ca7857e..99b1a6cf82bc9b4901a9c85e76c99dacb1169b69 100644 --- a/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts +++ b/arkui-plugins/ui-plugins/builder-lambda-translators/factory.ts @@ -86,20 +86,22 @@ export class factory { */ static updateBuilderLambdaMethodDecl( node: arkts.MethodDefinition, - prefixArgs: arkts.ETSParameterExpression[], + styleArg: arkts.ETSParameterExpression, newAnno: arkts.AnnotationUsage[], - newName: string | undefined + newName: string | undefined, + externalSourceName?: string ): arkts.MethodDefinition { const func: arkts.ScriptFunction = node.scriptFunction; - let newParams: arkts.Expression[]; + let newParams: arkts.Expression[] = [styleArg]; if (func.params.length > 0) { - newParams = [...prefixArgs, ...func.params.slice(0, func.params.length - 1)]; + newParams.push(...func.params.slice(0, func.params.length - 1)); if (node.name.name === BuilderLambdaNames.ORIGIN_METHOD_NAME) { newParams.push(this.createReusableKeyArgForCustomComponent()); } + if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { + newParams.push(this.createPackageInfoArgForXComponent()); + } newParams.push(func.params.at(func.params.length - 1)!); - } else { - newParams = prefixArgs; } const updateFunc = arkts.factory .updateScriptFunction( @@ -420,7 +422,9 @@ export class factory { ); reuseId = isReusable ? arkts.factory.createStringLiteral(type.name) : undefined; } - const args: (arkts.AstNode | undefined)[] = [this.createStyleArgInBuilderLambda(lambdaBody, returnType, moduleName)]; + const args: (arkts.AstNode | undefined)[] = [ + this.createStyleArgInBuilderLambda(lambdaBody, returnType, moduleName), + ]; let index = 0; while (index < params.length) { if (isReusable && index === params.length - 1) { @@ -539,20 +543,16 @@ export class factory { const func: arkts.ScriptFunction = node.scriptFunction; const isFunctionCall: boolean = isBuilderLambdaFunctionCall(node); const typeNode: arkts.TypeNode | undefined = builderLambdaMethodDeclType(node); - const prefixArgs: arkts.ETSParameterExpression[] = []; - prefixArgs.push(this.createStyleArgInBuilderLambdaDecl(typeNode, isFunctionCall)); - if (externalSourceName === 'arkui.component.xcomponent' && node.name.name === 'XComponent') { - prefixArgs.push(this.createPackageInfoArgForXComponent()); - } const newOverloads: arkts.MethodDefinition[] = node.overloads.map((method) => factory.transformBuilderLambdaMethodDecl(method) ); return this.updateBuilderLambdaMethodDecl( node, - prefixArgs, + this.createStyleArgInBuilderLambdaDecl(typeNode, isFunctionCall), removeAnnotationByName(func.annotations, BuilderLambdaNames.ANNOTATION_NAME), - replaceBuilderLambdaDeclMethodName(node.name.name) + replaceBuilderLambdaDeclMethodName(node.name.name), + externalSourceName ).setOverloads(newOverloads); } diff --git a/arkui-plugins/ui-plugins/property-translators/factory.ts b/arkui-plugins/ui-plugins/property-translators/factory.ts index f7704736399995e23dbd5acf19d7247e5d2c753d..b28d6ea0e00a7a96315de9ac4edbf62962546d57 100644 --- a/arkui-plugins/ui-plugins/property-translators/factory.ts +++ b/arkui-plugins/ui-plugins/property-translators/factory.ts @@ -654,17 +654,15 @@ export class factory { */ static wrapInterfacePropertyType(type: arkts.TypeNode, wrapTypeName: StateManagementTypes): arkts.TypeNode { if (arkts.isETSUnionType(type)) { - return arkts.factory.updateUnionType( - type, - type.types.map((t) => factory.wrapInterfacePropertyType(t, wrapTypeName)) - ); - } else if (!arkts.isETSUndefinedType(type)) { - return arkts.factory.createTypeReference( - arkts.factory.createTypeReferencePart( - arkts.factory.createIdentifier(wrapTypeName), - arkts.factory.createTSTypeParameterInstantiation([(type as arkts.TypeNode).clone()]) - ) - ); + return arkts.factory.updateUnionType(type, [ + arkts.factory.createTypeReference( + arkts.factory.createTypeReferencePart( + arkts.factory.createIdentifier(wrapTypeName), + arkts.factory.createTSTypeParameterInstantiation([type.types[0]]) + ) + ), + type.types[1], + ]); } return type; } diff --git a/arkui-plugins/ui-plugins/struct-translators/factory.ts b/arkui-plugins/ui-plugins/struct-translators/factory.ts index fc0a1ca57d897a7427b9baad1b6e7c44f33db388..91223e88e65c91504c30909530c3db1f11f004b8 100644 --- a/arkui-plugins/ui-plugins/struct-translators/factory.ts +++ b/arkui-plugins/ui-plugins/struct-translators/factory.ts @@ -297,7 +297,7 @@ export class factory { } /* - * add headers for animation in UICommonMethod + * add headers for animation in CommonMethod */ static modifyExternalComponentCommon(node: arkts.TSInterfaceDeclaration): arkts.TSInterfaceDeclaration { const animationStart = factory.createAnimationMethod(BuilderLambdaNames.ANIMATION_START); @@ -475,7 +475,7 @@ export class factory { if (!node.id || !node.body) { return node; } - if (externalSourceName === ARKUI_COMPONENT_COMMON_SOURCE_NAME && node.id.name === 'UICommonMethod') { + if (externalSourceName === ARKUI_COMPONENT_COMMON_SOURCE_NAME && node.id.name === 'CommonMethod') { return factory.modifyExternalComponentCommon(node); } if (isCustomComponentInterface(node)) {