From ab0573b96f415b29efc4c4572cb02eabdd875fa2 Mon Sep 17 00:00:00 2001 From: Cuecuexiaoyu Date: Mon, 23 Jun 2025 22:04:29 +0800 Subject: [PATCH] storagelink and storageProp add ttype Signed-off-by: Cuecuexiaoyu Change-Id: I50748622b7f5dc22a7ca2fe4e9219886267dfd3a --- arkui-plugins/common/predefines.ts | 8 +- .../storagelink/storagelink-complex-type.ets | 1 - .../storageprop/storageprop-complex-type.ets | 1 - .../storagelink-appstorage.test.ts | 22 +---- .../storagelink-complex-type.test.ts | 43 ++------- .../storagelink-primitive-type.test.ts | 18 +--- .../storageprop-appstorage.test.ts | 19 ++-- .../storageprop-complex-type.test.ts | 87 +++++++------------ .../storageprop-primitive-type.test.ts | 27 +++--- .../property-translators/factory.ts | 14 +++ .../property-translators/storageProp.ts | 7 +- .../property-translators/storagelink.ts | 1 + 12 files changed, 86 insertions(+), 162 deletions(-) diff --git a/arkui-plugins/common/predefines.ts b/arkui-plugins/common/predefines.ts index 6e51e18f7..1d255239a 100644 --- a/arkui-plugins/common/predefines.ts +++ b/arkui-plugins/common/predefines.ts @@ -109,7 +109,7 @@ export enum StateManagementTypes { LINK_DECORATED = 'ILinkDecoratedVariable', LINK_SOURCE_TYPE = 'LinkSourceType', STORAGE_LINK_DECORATED = 'IStorageLinkDecoratedVariable', - STORAGE_PROP_DECORATED = 'IStoragePropDecoratedVariable', + STORAGE_PROP_REF_DECORATED = 'IStoragePropRefDecoratedVariable', PROP_DECORATED = 'IPropDecoratedVariable', MUTABLE_STATE = 'MutableState', SYNCED_PROPERTY = 'SyncedProperty', @@ -130,7 +130,7 @@ export enum StateManagementTypes { MAKE_STATE = 'makeState', MAKE_LINK = 'makeLink', MAKE_PROP = 'makeProp', - MAKE_STORAGE_PROP = 'makeStorageProp', + MAKE_STORAGE_PROP_REF = 'makeStoragePropRef', MAKE_STORAGE_LINK = 'makeStorageLink', MAKE_PROVIDE = 'makeProvide', MAKE_CONSUME = 'makeConsume', @@ -167,7 +167,7 @@ export const DECORATOR_TYPE_MAP = new Map( [DecoratorNames.LINK, StateManagementTypes.LINK_SOURCE_TYPE], [DecoratorNames.PROP, StateManagementTypes.PROP_DECORATED], [DecoratorNames.STORAGE_LINK, StateManagementTypes.STORAGE_LINK_DECORATED], - [DecoratorNames.STORAGE_PROP, StateManagementTypes.STORAGE_PROP_DECORATED], + [DecoratorNames.STORAGE_PROP, StateManagementTypes.STORAGE_PROP_REF_DECORATED], [DecoratorNames.LOCAL_STORAGE_PROP, StateManagementTypes.SYNCED_PROPERTY], [DecoratorNames.LOCAL_STORAGE_LINK, StateManagementTypes.MUTABLE_STATE], [DecoratorNames.OBJECT_LINK, StateManagementTypes.OBJECT_LINK_DECORATED], @@ -184,7 +184,7 @@ export const INTERMEDIATE_IMPORT_SOURCE: Map = new Map = new Set(); @StorageLink('Prop5') mapA: Map = new Map(); - @StorageLink('Prop6') unionA: string | undefined = ""; @StorageLink('Prop7') classA: Person = new Person("John"); @StorageLink('Prop8') enumA: Status = Status.NotFound; 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 6136d1bd3..50c2ea128 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 @@ -35,7 +35,6 @@ struct MyStateSample { @StorageProp('Prop3') dateB: Date = new Date('2021-09-09'); @StorageProp('Prop4') setB: Set = new Set(); @StorageProp('Prop5') mapB: Map = new Map(); - @StorageProp('Prop6') unionB: string | undefined = ""; @StorageProp('Prop7') classB: Person = new Person("Kevin"); @StorageProp('Prop8') enumB: Status = Status.NotFound; 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 1e87fdf90..b191ae481 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,27 +38,16 @@ const storageLinkTransform: Plugins = { const pluginTester = new PluginTester('test storagelink with appstorage', buildConfig); const expectedScript: string = ` - import { memo as memo } from "arkui.stateManagement.runtime"; - 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 { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; - import { EntryPoint as EntryPoint } from "arkui.UserView"; - import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - 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() {} @@ -68,17 +57,15 @@ AppStorage.setOrCreate("PropB", new Data(50)); class Data { public code: number; - public constructor(code: number) { this.code = code; } - } @Entry({shared:false,storage:"",routeName:""}) @Component() final struct Index extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_storageLink = STATE_MGMT_FACTORY.makeStorageLink(this, "PropA", "storageLink", 1) - this.__backing_storageLinkObject = STATE_MGMT_FACTORY.makeStorageLink(this, "PropB", "storageLinkObject", new Data(1)) + this.__backing_storageLink = STATE_MGMT_FACTORY.makeStorageLink(this, "PropA", "storageLink", 1, Type.from()) + this.__backing_storageLinkObject = STATE_MGMT_FACTORY.makeStorageLink(this, "PropB", "storageLinkObject", new Data(1), Type.from()) } public __updateStruct(initializers: __Options_Index | undefined): void {} @@ -126,18 +113,13 @@ class Data { @Entry({shared:false,storage:"",routeName:""}) @Component() export interface __Options_Index { set storageLink(storageLink: number | undefined) - get storageLink(): number | undefined set __backing_storageLink(__backing_storageLink: IStorageLinkDecoratedVariable | undefined) - get __backing_storageLink(): IStorageLinkDecoratedVariable | undefined set storageLinkObject(storageLinkObject: Data | undefined) - get storageLinkObject(): Data | undefined set __backing_storageLinkObject(__backing_storageLinkObject: IStorageLinkDecoratedVariable | undefined) - get __backing_storageLinkObject(): IStorageLinkDecoratedVariable | undefined - } class __EntryWrapper extends EntryPoint { 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 a7c21fac8..040e58d9d 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,31 +38,19 @@ 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 { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; - import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; - import { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; - import { EntryPoint as EntryPoint } from "arkui.UserView"; - import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - import { Component as Component, Entry as Entry } from "@ohos.arkui.component"; - import { StorageLink as StorageLink } from "@ohos.arkui.stateManagement"; function main() {} - - class Person { public name: string = ""; @@ -140,14 +128,13 @@ final class Status extends BaseEnum { @Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - 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) + this.__backing_arrayA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop1", "arrayA", [1, 2, 3], Type.from>()) + this.__backing_objectA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "objectA", {}, Type.from()) + this.__backing_dateA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop3", "dateA", new Date("2021-08-08"), Type.from()) + this.__backing_setA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop4", "setA", new Set(), Type.from>()) + this.__backing_mapA = STATE_MGMT_FACTORY.makeStorageLink>(this, "Prop5", "mapA", new Map(), Type.from>()) + this.__backing_classA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop7", "classA", new Person("John"), Type.from()) + this.__backing_enumA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop8", "enumA", Status.NotFound, Type.from()) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} @@ -202,16 +189,6 @@ final class Status extends BaseEnum { this.__backing_mapA!.set(value); } - private __backing_unionA?: IStorageLinkDecoratedVariable; - - public get unionA(): string | undefined { - return this.__backing_unionA!.get(); - } - - public set unionA(value: string | undefined) { - this.__backing_unionA!.set(value); - } - private __backing_classA?: IStorageLinkDecoratedVariable; public get classA(): Person { @@ -269,12 +246,6 @@ final class Status extends BaseEnum { set __backing_mapA(__backing_mapA: IStorageLinkDecoratedVariable> | undefined) get __backing_mapA(): IStorageLinkDecoratedVariable> | undefined - set unionA(unionA: string | undefined | undefined) - - get unionA(): string | undefined | undefined - set __backing_unionA(__backing_unionA: IStorageLinkDecoratedVariable | undefined) - - get __backing_unionA(): IStorageLinkDecoratedVariable | undefined set classA(classA: Person | undefined) get classA(): Person | undefined 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 01d3053de..48a000477 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,36 +38,24 @@ 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 { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; - import { IStorageLinkDecoratedVariable as IStorageLinkDecoratedVariable } from "arkui.stateManagement.decorator"; - import { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; - import { EntryPoint as EntryPoint } from "arkui.UserView"; - import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - import { Component as Component, Entry as Entry } from "@ohos.arkui.component"; - import { StorageLink as StorageLink } from "@ohos.arkui.stateManagement"; function main() {} - - @Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - 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) + this.__backing_numA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop1", "numA", 33, Type.from()) + this.__backing_stringA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop2", "stringA", "AA", Type.from()) + this.__backing_booleanA = STATE_MGMT_FACTORY.makeStorageLink(this, "Prop3", "booleanA", true, Type.from()) } public __updateStruct(initializers: __Options_MyStateSample | undefined): 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 03c12c361..aee6f382a 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,11 @@ const storagePropTransform: Plugins = { const pluginTester = new PluginTester('test storageprop with appstorage', buildConfig); const expectedScript: string = ` - import { memo as memo } from "arkui.stateManagement.runtime"; import { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; -import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; +import { IStoragePropRefDecoratedVariable as IStoragePropRefDecoratedVariable } from "arkui.stateManagement.decorator"; import { TextAttribute as TextAttribute } from "arkui.component.text"; @@ -77,13 +76,13 @@ class Data { @Entry({shared:false,storage:"",routeName:""}) @Component() final struct Index extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_Index | undefined, @memo() content: (()=> void) | undefined): void { - this.__backing_storageProp = STATE_MGMT_FACTORY.makeStorageProp(this, "PropA", "storageProp", 1) - this.__backing_storagePropObject = STATE_MGMT_FACTORY.makeStorageProp(this, "PropB", "storagePropObject", new Data(1)) + this.__backing_storageProp = STATE_MGMT_FACTORY.makeStoragePropRef(this, "PropA", "storageProp", 1, Type.from()) + this.__backing_storagePropObject = STATE_MGMT_FACTORY.makeStoragePropRef(this, "PropB", "storagePropObject", new Data(1), Type.from()) } public __updateStruct(initializers: __Options_Index | undefined): void {} - private __backing_storageProp?: IStoragePropDecoratedVariable; + private __backing_storageProp?: IStoragePropRefDecoratedVariable; public get storageProp(): number { return this.__backing_storageProp!.get(); @@ -93,7 +92,7 @@ class Data { this.__backing_storageProp!.set(value); } - private __backing_storagePropObject?: IStoragePropDecoratedVariable; + private __backing_storagePropObject?: IStoragePropRefDecoratedVariable; public get storagePropObject(): Data { return this.__backing_storagePropObject!.get(); @@ -128,15 +127,15 @@ class Data { set storageProp(storageProp: number | undefined) get storageProp(): number | undefined - set __backing_storageProp(__backing_storageProp: IStoragePropDecoratedVariable | undefined) + set __backing_storageProp(__backing_storageProp: IStoragePropRefDecoratedVariable | undefined) - get __backing_storageProp(): IStoragePropDecoratedVariable | undefined + get __backing_storageProp(): IStoragePropRefDecoratedVariable | undefined set storagePropObject(storagePropObject: Data | undefined) get storagePropObject(): Data | undefined - set __backing_storagePropObject(__backing_storagePropObject: IStoragePropDecoratedVariable | undefined) + set __backing_storagePropObject(__backing_storagePropObject: IStoragePropRefDecoratedVariable | undefined) - get __backing_storagePropObject(): IStoragePropDecoratedVariable | undefined + get __backing_storagePropObject(): IStoragePropRefDecoratedVariable | undefined } 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 520f03561..d3a0e5135 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,31 +38,19 @@ 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 { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; - -import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; - +import { IStoragePropRefDecoratedVariable as IStoragePropRefDecoratedVariable } from "arkui.stateManagement.decorator"; import { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; - import { EntryPoint as EntryPoint } from "arkui.UserView"; - import { LayoutCallback as LayoutCallback } from "arkui.component.customComponent"; - import { CustomComponentV2 as CustomComponentV2 } from "arkui.component.customComponent"; - import { CustomComponent as CustomComponent } from "arkui.component.customComponent"; - import { Component as Component, Entry as Entry } from "@ohos.arkui.component"; - import { StorageProp as StorageProp } from "@ohos.arkui.stateManagement"; function main() {} - - class Person { public name: string = ""; @@ -140,19 +128,18 @@ final class Status extends BaseEnum { @Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - 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) + this.__backing_arrayB = STATE_MGMT_FACTORY.makeStoragePropRef>(this, "Prop1", "arrayB", [1, 2, 3], Type.from>()) + this.__backing_objectB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop2", "objectB", {}, Type.from()) + this.__backing_dateB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop3", "dateB", new Date("2021-09-09"), Type.from()) + this.__backing_setB = STATE_MGMT_FACTORY.makeStoragePropRef>(this, "Prop4", "setB", new Set(), Type.from>()) + this.__backing_mapB = STATE_MGMT_FACTORY.makeStoragePropRef>(this, "Prop5", "mapB", new Map(), Type.from>()) + this.__backing_classB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop7", "classB", new Person("Kevin"), Type.from()) + this.__backing_enumB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop8", "enumB", Status.NotFound, Type.from()) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_arrayB?: IStoragePropDecoratedVariable>; + private __backing_arrayB?: IStoragePropRefDecoratedVariable>; public get arrayB(): Array { return this.__backing_arrayB!.get(); @@ -162,7 +149,7 @@ final class Status extends BaseEnum { this.__backing_arrayB!.set(value); } - private __backing_objectB?: IStoragePropDecoratedVariable; + private __backing_objectB?: IStoragePropRefDecoratedVariable; public get objectB(): Object { return this.__backing_objectB!.get(); @@ -172,7 +159,7 @@ final class Status extends BaseEnum { this.__backing_objectB!.set(value); } - private __backing_dateB?: IStoragePropDecoratedVariable; + private __backing_dateB?: IStoragePropRefDecoratedVariable; public get dateB(): Date { return this.__backing_dateB!.get(); @@ -182,7 +169,7 @@ final class Status extends BaseEnum { this.__backing_dateB!.set(value); } - private __backing_setB?: IStoragePropDecoratedVariable>; + private __backing_setB?: IStoragePropRefDecoratedVariable>; public get setB(): Set { return this.__backing_setB!.get(); @@ -192,7 +179,7 @@ final class Status extends BaseEnum { this.__backing_setB!.set(value); } - private __backing_mapB?: IStoragePropDecoratedVariable>; + private __backing_mapB?: IStoragePropRefDecoratedVariable>; public get mapB(): Map { return this.__backing_mapB!.get(); @@ -202,17 +189,7 @@ final class Status extends BaseEnum { this.__backing_mapB!.set(value); } - private __backing_unionB?: IStoragePropDecoratedVariable; - - public get unionB(): string | undefined { - return this.__backing_unionB!.get(); - } - - public set unionB(value: string | undefined) { - this.__backing_unionB!.set(value); - } - - private __backing_classB?: IStoragePropDecoratedVariable; + private __backing_classB?: IStoragePropRefDecoratedVariable; public get classB(): Person { return this.__backing_classB!.get(); @@ -222,7 +199,7 @@ final class Status extends BaseEnum { this.__backing_classB!.set(value); } - private __backing_enumB?: IStoragePropDecoratedVariable; + private __backing_enumB?: IStoragePropRefDecoratedVariable; public get enumB(): Status { return this.__backing_enumB!.get(); @@ -242,51 +219,45 @@ final class Status extends BaseEnum { set arrayB(arrayB: Array | undefined) get arrayB(): Array | undefined - set __backing_arrayB(__backing_arrayB: IStoragePropDecoratedVariable> | undefined) + set __backing_arrayB(__backing_arrayB: IStoragePropRefDecoratedVariable> | undefined) - get __backing_arrayB(): IStoragePropDecoratedVariable> | undefined + get __backing_arrayB(): IStoragePropRefDecoratedVariable> | undefined set objectB(objectB: Object | undefined) get objectB(): Object | undefined - set __backing_objectB(__backing_objectB: IStoragePropDecoratedVariable | undefined) + set __backing_objectB(__backing_objectB: IStoragePropRefDecoratedVariable | undefined) - get __backing_objectB(): IStoragePropDecoratedVariable | undefined + get __backing_objectB(): IStoragePropRefDecoratedVariable | undefined set dateB(dateB: Date | undefined) get dateB(): Date | undefined - set __backing_dateB(__backing_dateB: IStoragePropDecoratedVariable | undefined) + set __backing_dateB(__backing_dateB: IStoragePropRefDecoratedVariable | undefined) - get __backing_dateB(): IStoragePropDecoratedVariable | undefined + get __backing_dateB(): IStoragePropRefDecoratedVariable | undefined set setB(setB: Set | undefined) get setB(): Set | undefined - set __backing_setB(__backing_setB: IStoragePropDecoratedVariable> | undefined) + set __backing_setB(__backing_setB: IStoragePropRefDecoratedVariable> | undefined) - get __backing_setB(): IStoragePropDecoratedVariable> | undefined + get __backing_setB(): IStoragePropRefDecoratedVariable> | undefined set mapB(mapB: Map | undefined) get mapB(): Map | undefined - set __backing_mapB(__backing_mapB: IStoragePropDecoratedVariable> | undefined) - - get __backing_mapB(): IStoragePropDecoratedVariable> | undefined - set unionB(unionB: string | undefined | undefined) - - get unionB(): string | undefined | undefined - set __backing_unionB(__backing_unionB: IStoragePropDecoratedVariable | undefined) + set __backing_mapB(__backing_mapB: IStoragePropRefDecoratedVariable> | undefined) - get __backing_unionB(): IStoragePropDecoratedVariable | undefined + get __backing_mapB(): IStoragePropRefDecoratedVariable> | undefined set classB(classB: Person | undefined) get classB(): Person | undefined - set __backing_classB(__backing_classB: IStoragePropDecoratedVariable | undefined) + set __backing_classB(__backing_classB: IStoragePropRefDecoratedVariable | undefined) - get __backing_classB(): IStoragePropDecoratedVariable | undefined + get __backing_classB(): IStoragePropRefDecoratedVariable | undefined set enumB(enumB: Status | undefined) get enumB(): Status | undefined - set __backing_enumB(__backing_enumB: IStoragePropDecoratedVariable | undefined) + set __backing_enumB(__backing_enumB: IStoragePropRefDecoratedVariable | undefined) - get __backing_enumB(): IStoragePropDecoratedVariable | undefined + get __backing_enumB(): IStoragePropRefDecoratedVariable | 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 62fc938a5..5b65941b4 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,12 +38,11 @@ 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 { STATE_MGMT_FACTORY as STATE_MGMT_FACTORY } from "arkui.stateManagement.decorator"; -import { IStoragePropDecoratedVariable as IStoragePropDecoratedVariable } from "arkui.stateManagement.decorator"; +import { IStoragePropRefDecoratedVariable as IStoragePropRefDecoratedVariable } from "arkui.stateManagement.decorator"; import { PageLifeCycle as PageLifeCycle } from "arkui.component.customComponent"; @@ -65,14 +64,14 @@ function main() {} @Entry({shared:false,storage:"",routeName:""}) @Component() final struct MyStateSample extends CustomComponent implements PageLifeCycle { public __initializeStruct(initializers: __Options_MyStateSample | undefined, @memo() content: (()=> void) | undefined): void { - 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) + this.__backing_numB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop1", "numB", 43, Type.from()) + this.__backing_stringB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop2", "stringB", "BB", Type.from()) + this.__backing_booleanB = STATE_MGMT_FACTORY.makeStoragePropRef(this, "Prop3", "booleanB", false, Type.from()) } public __updateStruct(initializers: __Options_MyStateSample | undefined): void {} - private __backing_numB?: IStoragePropDecoratedVariable; + private __backing_numB?: IStoragePropRefDecoratedVariable; public get numB(): number { return this.__backing_numB!.get(); @@ -82,7 +81,7 @@ function main() {} this.__backing_numB!.set(value); } - private __backing_stringB?: IStoragePropDecoratedVariable; + private __backing_stringB?: IStoragePropRefDecoratedVariable; public get stringB(): string { return this.__backing_stringB!.get(); @@ -92,7 +91,7 @@ function main() {} this.__backing_stringB!.set(value); } - private __backing_booleanB?: IStoragePropDecoratedVariable; + private __backing_booleanB?: IStoragePropRefDecoratedVariable; public get booleanB(): boolean { return this.__backing_booleanB!.get(); @@ -112,21 +111,21 @@ function main() {} set numB(numB: number | undefined) get numB(): number | undefined - set __backing_numB(__backing_numB: IStoragePropDecoratedVariable | undefined) + set __backing_numB(__backing_numB: IStoragePropRefDecoratedVariable | undefined) - get __backing_numB(): IStoragePropDecoratedVariable | undefined + get __backing_numB(): IStoragePropRefDecoratedVariable | undefined set stringB(stringB: string | undefined) get stringB(): string | undefined - set __backing_stringB(__backing_stringB: IStoragePropDecoratedVariable | undefined) + set __backing_stringB(__backing_stringB: IStoragePropRefDecoratedVariable | undefined) - get __backing_stringB(): IStoragePropDecoratedVariable | undefined + get __backing_stringB(): IStoragePropRefDecoratedVariable | undefined set booleanB(booleanB: boolean | undefined) get booleanB(): boolean | undefined - set __backing_booleanB(__backing_booleanB: IStoragePropDecoratedVariable | undefined) + set __backing_booleanB(__backing_booleanB: IStoragePropRefDecoratedVariable | undefined) - get __backing_booleanB(): IStoragePropDecoratedVariable | undefined + get __backing_booleanB(): IStoragePropRefDecoratedVariable | undefined } diff --git a/arkui-plugins/ui-plugins/property-translators/factory.ts b/arkui-plugins/ui-plugins/property-translators/factory.ts index 882a7b4ba..2b1948985 100644 --- a/arkui-plugins/ui-plugins/property-translators/factory.ts +++ b/arkui-plugins/ui-plugins/property-translators/factory.ts @@ -780,4 +780,18 @@ export class factory { } return property; } + + static createTypeFrom(typeAnnotation: arkts.TypeNode | undefined) { + return arkts.factory.createCallExpression( + arkts.factory.createMemberExpression( + arkts.factory.createIdentifier('Type'), + arkts.factory.createIdentifier('from'), + arkts.Es2pandaMemberExpressionKind.MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS, + false, + false + ), + typeAnnotation ? [typeAnnotation] : undefined, + undefined + ); + } } diff --git a/arkui-plugins/ui-plugins/property-translators/storageProp.ts b/arkui-plugins/ui-plugins/property-translators/storageProp.ts index ecec9362b..8d3cf948a 100644 --- a/arkui-plugins/ui-plugins/property-translators/storageProp.ts +++ b/arkui-plugins/ui-plugins/property-translators/storageProp.ts @@ -88,15 +88,16 @@ export class StoragePropTranslator extends PropertyTranslator implements Initial arkts.factory.createStringLiteral(storagePropValueStr), arkts.factory.create1StringLiteral(originalName), this.property.value ?? arkts.factory.createUndefinedLiteral(), + factory.createTypeFrom(this.property.typeAnnotation) ]; factory.judgeIfAddWatchFunc(args, this.property); - collectStateManagementTypeImport(StateManagementTypes.STORAGE_PROP_DECORATED); + collectStateManagementTypeImport(StateManagementTypes.STORAGE_PROP_REF_DECORATED); return arkts.factory.createAssignmentExpression( generateThisBacking(newName), arkts.Es2pandaTokenType.TOKEN_TYPE_PUNCTUATOR_SUBSTITUTION, factory.generateStateMgmtFactoryCall( - StateManagementTypes.MAKE_STORAGE_PROP, + StateManagementTypes.MAKE_STORAGE_PROP_REF, this.property.typeAnnotation, args, true @@ -108,7 +109,7 @@ export class StoragePropTranslator extends PropertyTranslator implements Initial const field = factory.createOptionalClassProperty( newName, this.property, - StateManagementTypes.STORAGE_PROP_DECORATED, + StateManagementTypes.STORAGE_PROP_REF_DECORATED, arkts.Es2pandaModifierFlags.MODIFIER_FLAGS_PRIVATE ); const thisValue: arkts.Expression = generateThisBacking(newName, false, true); diff --git a/arkui-plugins/ui-plugins/property-translators/storagelink.ts b/arkui-plugins/ui-plugins/property-translators/storagelink.ts index 8e3256a90..8c43bd631 100644 --- a/arkui-plugins/ui-plugins/property-translators/storagelink.ts +++ b/arkui-plugins/ui-plugins/property-translators/storagelink.ts @@ -88,6 +88,7 @@ export class StorageLinkTranslator extends PropertyTranslator implements Initial arkts.factory.createStringLiteral(storageLinkValueStr), arkts.factory.create1StringLiteral(originalName), this.property.value ?? arkts.factory.createUndefinedLiteral(), + factory.createTypeFrom(this.property.typeAnnotation) ]; factory.judgeIfAddWatchFunc(args, this.property); collectStateManagementTypeImport(StateManagementTypes.STORAGE_LINK_DECORATED); -- Gitee