diff --git a/api/arkui/stateManagement/utils.d.ets b/api/arkui/stateManagement/utils.static.d.ets similarity index 31% rename from api/arkui/stateManagement/utils.d.ets rename to api/arkui/stateManagement/utils.static.d.ets index a764b6d316b92950f8612f463e077abf8841ef0c..e73f7630b6bb57177920ee3ce2d5137cb4bdd786 100644 --- a/api/arkui/stateManagement/utils.d.ets +++ b/api/arkui/stateManagement/utils.static.d.ets @@ -48,4 +48,107 @@ export declare class UIUtils { * @since 20 */ static makeObserved(source: T): T; + + /** + * Creates read-only data binding. + * + * + * Example. UIUtils.makeBinding(()=>this.num); + * + * Supports simple getters for read-only data. + * Intended for primitive value parameters when calling a @Builder function where arguments are of type Binding. + * + * @param { GetterCallback } getter - A value or a function that returns the current value of type T. + * @returns { Binding } read-only data binding value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static makeBindingReadonly(getter: GetterCallback): Binding; + + /** + * Creates a mutable data binding. + * + * Two functions to implement function overloading. + * + * Example. UIUtils.makeBinding(()=>this.num, val => this.num = val); + * + * Supports getter-setter pairs for mutable data. + * Intended for primitive value parameters when calling a @Builder + * function where arguments are of type MutableBinding. + * + * @param { GetterCallback } getter - A value or a function that returns the current value of type T. + * @param { SetterCallback } setter - A function to set a new value of type T. + * If provided, a MutableBinding is created. + * @returns { MutableBinding } mutable data binding value + * @static + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static makeBindingMutable(getter: GetterCallback, setter: SetterCallback): MutableBinding; + + /** + * Creates data binding. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + static overload makeBinding { makeBindingReadonly, makeBindingMutable } +} + +/** + * Getter callback type. It is used to get value. + * + * @typedef { function } GetterCallback + * @returns { T } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare type GetterCallback = () => T; + +/** + * Setter callback type. It is used to assign a new value. + * + * @typedef { function } SetterCallback + * @param { T } newValue - update the value with newValue. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare type SetterCallback = (newValue: T) => void; + +/** + * Represents a read-only data binding. + * Use with @Builder argument list for primitive types. Use makeBinding to pass values when calling the function. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare class Binding { + /** + * Get function that can acquire the value. + * @returns T + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + get value(): T; +} + +/** + * Represents a mutable data binding allowing both read and write operations. + * Use with @Builder argument list for primitive types. Use makeBinding to pass values when calling the function. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ +export declare class MutableBinding { + /** + * Get function that can acquire the value. + * @returns T + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + get value(): T; + /** + * Set function that can set the new value. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @since 20 + */ + set value(newValue: T); } \ No newline at end of file