diff --git a/api/arkui/stateManagement/decorator.d.ets b/api/arkui/stateManagement/decorator.d.ets index 3c3659fd93a08ca3d2ab31336a0e0fe894711ea5..4acc119c9a09ba8b0a045c1cc0efc4428e01a184 100644 --- a/api/arkui/stateManagement/decorator.d.ets +++ b/api/arkui/stateManagement/decorator.d.ets @@ -19,64 +19,444 @@ */ import { ExtendableComponent } from '../component/extendableComponent'; - + +/** + * Defining State annotation + * State variable that holds the state property and is used to render the owning custom component. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface State {}; +/** + * Defining Prop annotation + * Prop is an annotation which is mutable, and its changes will not be synchronized to the parent component. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Prop {}; +/** + * Defining PropRef annotation + * PropRef is an annotation which is mutable. + * Any object property modifications made through PropRef are visible in the + * parent component, which is different from Prop. + * In order to prevent this, need to take a deep copy of the parent data. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface PropRef {}; + +/** + * Defining Link annotation + * Link decorated variable creates two-way synchronization with a variable of its parent component. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Link {}; +/** + * Defining Observed annotation + * Observed is used to decorate a class. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Observed {}; +/** + * Defining Track annotation + * Track is a decorator used to decorate properties of class objects. + * Any changes to the properties decorated by Track will trigger only updates to the UI associated with those properties. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Track {}; +/** + * Defining ObjectLink annotation + * ObjectLink is used to observe property changes in nested class objects. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface ObjectLink {}; +/** + * Defining StorageProp annotation + * StorageProp a one-way data synchronization is established from the attribute with the given key in AppStorage to the variable. + * A local change can be made, but it will not be synchronized to AppStorage. + * An update to the attribute with the given key in AppStorage will overwrite local changes. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface StorageProp { property: string; }; +/** + * Defining StoragePropRef annotation + * StoragePropRef is an annotation which is mutable. + * Any object property modifications made through StoragePropRef are visible in the + * AppStorage, which is different from StorageProp. + * In order to prevent this, need to take a deep copy of AppStorage instance data. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface StoragePropRef { + /** + * The give property in AppStorage. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + property: string; +}; + +/** + * Defining StorageLink annotation + * StorageLink is used to create a two-way data synchronization between the variable + * it decorates and the attribute with the given key in AppStorage. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface StorageLink { + /** + * The give property in AppStorage. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ property: string; }; +/** + * Defining LocalStorageProp annotation + * LocalStorageProp is a one-way data synchronization is established from the attribute with the given key in + * LocalStorage to the variable. This means that, local changes + * (if any) will not be synchronized to LocalStorage, and an update to the attribute with the given key in LocalStorage. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface LocalStorageProp { + /** + * The give property in LocalStorage. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ property: string; }; +/** + * Defining LocalStoragePropRef annotation + * LocalStoragePropRef is an annotation which is mutable. + * Any object property modifications made through LocalStoragePropRef are visible in the + * LocalStorage, which is different from LocalStorageProp. + * In order to prevent this, need to take a deep copy of LocalStorage data. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface LocalStoragePropRef { + /** + * The give property in AppStorage. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + property: string; +}; + +/** + * Defining LocalStorageLink annotation + * LocalStorageLink is used to create a two-way data synchronization with the attribute + * in LocalStorage. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface LocalStorageLink { + /** + * The give property in LocalStorage. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ property: string; }; +/** + * Defining Provide annotation + * Provide is used for two-way data synchronization with descendant components when + * state data needs to be transferred between multiple levels. An @Provide decorated state + * variable exists in the ancestor component and is said to be "provided" to descendent components. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Provide { + /** + * The alias name. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ alias: string = ""; + /** + * allowOverride is used to override an existing @Provide decorated variable. + * + * @type { boolean } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ allowOverride: boolean = false; }; +/** + * Defining Consume annotation + * Consume is used to access the provided state variable for a descendent component + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Consume { + /** + * The alias name. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ alias: string = ""; }; +/** + * Defining Watch annotation + * Watch is used to listen for state variables. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Watch { + /** + * The callback function name. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ callback: string; }; +/** + * Defining Require annotation + * Require is a decorator for declaring that parameters – regular variables. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ @Retention({policy: "SOURCE"}) export declare @interface Require {}; +/** + * Defining Local annotation + * Local is the internal state of a component, which enables the variables in the + * custom component to observe changes. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Local {}; + +/** + * Defining Param annotation + * Param indicates the state passed in from the external, ensuring that + * data can be synchronized between the parent and child components. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Param {}; + +/** + * Defining Once annotation + * Once annotation accepts values passed in only during variable initialization + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Once {}; + +/** + * Defining Event annotation + * Event is used to decorate the callback method is a standard, indicating that the + * child component needs to pass in the callback for updating the data source. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Event {}; + +/** + * Defining Provider annotation + * Provider is used for two-way data synchronization with descendant components when + * state data needs to be transferred between multiple levels. An @Provider decorated state + * variable exists in the ancestor component and is said to be "provider" to descendent components. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Provider { + /** + * The alias name. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + alias: string = ""; +}; + +/** + * Defining Consumer annotation + * Consumer is used to access the provided state variable for a descendent component + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Consumer { + /** + * The alias name. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + alias: string = ""; +}; + +/** + * Defining ObservedV2 annotation + * ObservedV2 is used to decorate with class. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface ObservedV2 {}; + +/** + * Defining Trace annotation + * Trace is used to directly observe the property changes of nested objects + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Trace {}; + +/** + * Defining Computed annotation + * Computed is a method decorator that decorates the getter method. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Computed {}; + +/** + * Defining Monitor annotation + * Monitor provides the capability of listening for state variables of V2. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +@Retention({policy: "SOURCE"}) +export declare @interface Monitor { + /** + * Listened property name. + * + * @type { string[] } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + path: string[]; +}; + +/** + * Define IMonitor interface + * + * @interface IMonitor + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +declare interface IMonitor { + /** + * Array of changed paths(keys) + * + * @type { Array } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + dirty: Array; + /** + * Return the pair of the value before the most recent change and current value for given path. + * If path does not exist, return undefined; If path is not specified, return the value pair corresponding to the first path in dirty. + * + * @param { string } [path] Listened property name + * @returns { IMonitorValue | undefined } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + value(path?: string): IMonitorValue | undefined; +} + +/** + * Define IMonitorValue interface + * + * @interface IMonitorValue + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +declare interface IMonitorValue { + /** + * Get the previous value. + * + * @type { T } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + before: T; + /** + * Get current value. + * + * @type { T } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + now: T; + /** + * Monitored path input by the user. + * + * @type { string } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + path: string; +} + /** * Define decorated variable interface. * @@ -191,6 +571,27 @@ export declare interface IPropDecoratedVariable extends IDecoratedMutableVari IDecoratedUpdatableVariable, IDecoratedV1Variable { } +/** + * Define PropRef decoration variable interface. + * + * @extends IDecoratedMutableVariable, IDecoratedUpdatableVariable, IDecoratedV1Variable + * @interface IPropRefDecoratedVariable + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare interface IPropRefDecoratedVariable extends IDecoratedMutableVariable, + IDecoratedUpdatableVariable, IDecoratedV1Variable {} + +/** + * Define LocalStoragePropRef decoration variable interface. + * + * @extends IDecoratedMutableVariable, IDecoratedV1Variable + * @interface ILocalStoragePropRefDecoratedVariable + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare interface ILocalStoragePropRefDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} + /** * Define Link decoration variable interface. * @@ -350,6 +751,20 @@ export declare interface IStateMgmtFactory { makeObjectLink(owningView: ExtendableComponent, varName: string, initValue: T, wathcFunc?: WatchFuncType): IObjectLinkDecoratedVariable; + /** + * Create a PropRef variable instance. + * + * @param { ExtendableComponent } owningView - custom component. + * @param { string } varName - state variable name. + * @param { T } initValue - state variable initValue. + * @param { WatchFuncType } [watchFunc] - watch type + * @returns { IPropRefDecoratedVariable } PropRef instance + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + makePropRef(owningView: ExtendableComponent, varName: string, initValue: T, + watchFunc?: WatchFuncType): IPropRefDecoratedVariable; + /** * Create a StorageLink variable instance. * @@ -380,6 +795,21 @@ export declare interface IStateMgmtFactory { */ makeStoragePropRef(owningView: ExtendableComponent, propName: string, varName: string, initValue: T, ttype: Type, watchFunc?: WatchFuncType): IStoragePropRefDecoratedVariable; + /** + * Create a LocalStoragePropRef variable instance. + * + * @param { ExtendableComponent } owningView - custom component. + * @param { string } propName - property name. + * @param { string } varName - state variable name. + * @param { T } initValue - init value. + * @param { Type } ttype - value type. + * @param { WatchFuncType } [watchFunc] - watch type + * @returns { ILocalStoragePropRefDecoratedVariable } LocalStoragePropRef instance + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + makeLocalStoragePropRef(owningView: ExtendableComponent, propName: string, + varName: string, initValue: T, ttype: Type, watchFunc?: WatchFuncType): ILocalStoragePropRefDecoratedVariable; /** * Create a LocalStorageLink variable instance.