diff --git a/api/@internal/component/ets/common.d.ts b/api/@internal/component/ets/common.d.ts index 76a9d6bf424b425f04aa9d7db754ecc3c25db98e..1ee4bb31504a7c2e6cd60f6fd6d4e24f4072c29e 100644 --- a/api/@internal/component/ets/common.d.ts +++ b/api/@internal/component/ets/common.d.ts @@ -66,7 +66,7 @@ import { CircleAttribute } from './circle'; import { RectAttribute } from './rect'; import { PathAttribute } from './path'; import { EllipseAttribute } from './ellipse'; -import { LocalStorage } from '../stateManagement/storage/localStorage'; +import { LocalStorage } from '../stateManagement/storages/localStorage'; import { CustomBuilder, WrappedBuilder } from './builder'; import curves from '../../@ohos.curves'; /*** endif */ diff --git a/api/@ohos.arkui.UIContext.d.ts b/api/@ohos.arkui.UIContext.d.ts index 004dd91301e99788a30e936268725d451efc83e0..bda9777e8cacf7a6dfe2d4c02a26ea3e88efee65 100644 --- a/api/@ohos.arkui.UIContext.d.ts +++ b/api/@ohos.arkui.UIContext.d.ts @@ -55,7 +55,7 @@ import { TimePickerDialogOptions } from './arkui/component/timePicker'; import { AlertDialogParamWithConfirm, AlertDialogParamWithButtons, AlertDialogParamWithOptions } from './arkui/component/alertDialog'; import { ActionSheetOptions } from './arkui/component/actionSheet'; import { TextPickerDialogOptions } from './arkui/component/textPicker'; -import { LocalStorage } from './arkui/stateManagement/storage/localStorage'; +import { LocalStorage } from './arkui/stateManagement/storages/localStorage'; import { DatePickerDialogOptions } from './arkui/component/datePicker'; import { TabsController } from './arkui/component/tabs'; import { Scroller } from './arkui/component/scroll'; diff --git a/api/@ohos.arkui.stateManagement.d.ets b/api/@ohos.arkui.stateManagement.d.ets index 89a2bed08d5f0616202169df936f880b550d3938..47ca8f8b66b82df7c93b073e8a15272354e2a81c 100644 --- a/api/@ohos.arkui.stateManagement.d.ets +++ b/api/@ohos.arkui.stateManagement.d.ets @@ -19,9 +19,21 @@ * @arkts 1.2 */ -export * from './arkui/stateManagement/decorator'; +export * from './arkui/stateManagement/common'; export * from './arkui/stateManagement/runtime'; -export * from './arkui/stateManagement/storage/appStorage'; -export * from './arkui/stateManagement/storage/localStorage'; -export * from './arkui/stateManagement/utils'; -export * from './arkui/stateManagement/storage/storageProperty'; +export * from './arkui/stateManagement/storages'; +export * from './arkui/stateManagement/base/backingValue'; +export * from './arkui/stateManagement/base/decoratorBase'; +export * from './arkui/stateManagement/base/iObservedObject'; +export * from './arkui/stateManagement/base/mutableStateMeta'; +export * from './arkui/stateManagement/decorators/decoratorState'; +export * from './arkui/stateManagement/decorators/decoratorLink'; +export * from './arkui/stateManagement/decorators/decoratorObjectLink'; +export * from './arkui/stateManagement/decorators/decoratorProp'; +export * from './arkui/stateManagement/decorators/decoratorProvide'; +export * from './arkui/stateManagement/decorators/decoratorConsume'; +export * from './arkui/stateManagement/decorators/decoratorStorageLink'; +export * from './arkui/stateManagement/decorators/decoratorStorageProp'; +export * from './arkui/stateManagement/decorators/decoratorWatch'; +export * from './arkui/stateManagement/storagess/appStorage'; +export * from './arkui/stateManagement/storagess/localStorage'; \ No newline at end of file diff --git a/api/arkui/component/customComponent.d.ets b/api/arkui/component/customComponent.d.ets index cfd065cf4b339c5d99df98e0aabb203a7e613be6..888294c2512b5a200eb5b7b6c89f4fe443cd90a5 100644 --- a/api/arkui/component/customComponent.d.ets +++ b/api/arkui/component/customComponent.d.ets @@ -23,7 +23,11 @@ import { ExtendableComponent } from './extendableComponent'; import { GeometryInfo, Layoutable, Measurable, SizeResult } from './common' import { ConstraintSizeOptions } from './units' import { Builder } from './builder' -import { LocalStorage } from './../stateManagement/storage/localStorage'; +import { LocalStorage } from './../stateManagement/storages/localStorage'; +import { UIContext } from './../../../api/@ohos.arkui.UIContext' +import { WatchFuncType } from '../stateManagement/decorators/decoratorWatch' +import { ProvideDecoratedVariable } from '../stateManagement/decorators/decoratorProvide' +import { ConsumeDecoratedVariable } from '../stateManagement/decorators/decoratorConsume' /** * Defines Entry Annotation. @@ -197,55 +201,34 @@ export declare abstract class BaseCustomComponent extends ExtendableComponent { aboutToRecycle(): void; } -/** - * Definition of custom component class. - * - * @extends BaseCustomComponent - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @crossplatform - * @atomicservice - * @since 20 - */ -export declare abstract class CustomComponent, T_Options> extends BaseCustomComponent { - /** - * Constructor to use to create a customComponent instance. - * @param {boolean} [useSharedStorage] - determine whether to use the LocalStorage instance object returned by UIContext.getSharedLocalStorage() interface. - * @param {LocalStorage} [storage] - localStorage instance. - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - constructor(useSharedStorage?: boolean, storage?: LocalStorage); - - /** - * Define the constructor of custom component - * - * @param { () => T } factory - factory to create instance of custom component - * @param { T_Options } initializers - initial data for all the fields in custom component - * @param { string } reuseId - reuse id for reusable. Only valid if custom component decorated with @Reusable - * @param { @Builder () => void } content - tail closure for custom component - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @crossplatform - * @atomicservice - * @since 20 - */ +export declare abstract class CustomComponent, T_Options> { + public addProvidedVar(varName: string, providedPropName: string, initValue: T, allowOverride: boolean = false, watchFunc?: WatchFuncType): ProvideDecoratedVariable; + public initConsume(varName: string, providedPropName: string, watchFunc?: WatchFuncType): ConsumeDecoratedVariable; + @memo @ComponentBuilder - static $_instantiate( - factory: () => T, - initializers?: T_Options, - reuseId?: string, - @Builder content?: () => void - ): T + static $_instantiate, S_Options>( + factory: () => S, + initializers?: S_Options, + @memo + content?: () => void, + reuseKey?: string + ): S; - /** - * aboutToReuse Method - * - * @param { Record } params - Custom component init params. - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @crossplatform - * @atomicservice - * @since 20 - */ - aboutToReuse(params: Record): void; + // Life cycle for custom component + aboutToAppear(): void + aboutToDisappear(): void + onDidBuild(): void + + onPageShow(): void + onPageHide(): void + onBackPress(): boolean + getUIContext(): UIContext + + @memo + build(): void; + + aboutToReuse(): void + aboutToRecycle(): void } /** diff --git a/api/arkui/stateManagement/storage/appStorage.d.ets b/api/arkui/stateManagement/base/backingValue.d.ets similarity index 76% rename from api/arkui/stateManagement/storage/appStorage.d.ets rename to api/arkui/stateManagement/base/backingValue.d.ets index 4a3bf1b8ff53ca02c74ed1d69168e00fa44b1923..0a915e71f305d0fe0eccb15cfc33abd97c3fa1c8 100644 --- a/api/arkui/stateManagement/storage/appStorage.d.ets +++ b/api/arkui/stateManagement/base/backingValue.d.ets @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 Huawei Device Co., Ltd. + * 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 @@ -18,6 +18,8 @@ * @arkts 1.2 */ -import { LocalStorage } from './localStorage'; - -export const AppStorage: LocalStorage = new LocalStorage(); + export declare class BackingValue { + public constructor(initValue: T) + public get value(): T + public set value(newVale: T) + } \ No newline at end of file diff --git a/api/arkui/stateManagement/utils.d.ets b/api/arkui/stateManagement/base/decoratorBase.d.ets similarity index 40% rename from api/arkui/stateManagement/utils.d.ets rename to api/arkui/stateManagement/base/decoratorBase.d.ets index a764b6d316b92950f8612f463e077abf8841ef0c..47f8b147ff5838c4614cc493dde7dfe22fc73ab3 100644 --- a/api/arkui/stateManagement/utils.d.ets +++ b/api/arkui/stateManagement/base/decoratorBase.d.ets @@ -1,51 +1,50 @@ -/* - * 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. - */ -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -/** - * UIUtils is a state management tool class for operating the observed data. - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare class UIUtils { - /** - * Get raw object from the Object, like builtin type, objectLiteral. - * If input parameter is a regular Object without proxy, return Object itself. - * - * @param { T } source input source Object data. - * @returns { T } raw object. - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static getTarget(source: T): T; - - /** - * Make non-observed data into observed data. - * Support builtin type and objectLiteral. - * - * @param { T } source input source object data. - * @returns { T } proxy object from the source object data. - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static makeObserved(source: T): T; +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { WatchFuncType } from '../decorators/decoratorWatch'; + +export declare interface IDecoratedImmutableVariable { + get(): T +} + +export declare interface IDecoratedMutableVariable { + get(): T + set(newValue: T): void +} + +export declare interface IDecoratedUpdatableVariable { + update(newValue: T): void +} + +export declare interface AbstractProperty extends IDecoratedMutableVariable { + info(): string; +} + +export declare interface SubscribedAbstractProperty extends AbstractProperty { + aboutToBeDeleted(): void; +} + +export declare class DecoratedVariableBase { + public constructor(decorator: string, varName: string) +} + +export declare class DecoratedV1VariableBase extends DecoratedVariableBase { + public constructor(decorator: string, varName: string, initValue:T, watchFunc?: WatchFuncType) } \ No newline at end of file diff --git a/api/arkui/stateManagement/base/iObservedObject.d.ets b/api/arkui/stateManagement/base/iObservedObject.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..0ea4c2fe574826811469141659383f8ff17d379e --- /dev/null +++ b/api/arkui/stateManagement/base/iObservedObject.d.ets @@ -0,0 +1,28 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ +import { int32 } from '@koalaui.runtime.common'; + +export declare interface IObservedObject { + _permissibleAddRefDepth: int32; +} + +export declare function castToIObservedObject(obj: T): T | undefined; + +export declare function setObservationDepth(obj: T, depth: int32): void; \ No newline at end of file diff --git a/api/arkui/stateManagement/base/mutableStateMeta.d.ets b/api/arkui/stateManagement/base/mutableStateMeta.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..6aee33a1b11392258743c814c66f84d19401844a --- /dev/null +++ b/api/arkui/stateManagement/base/mutableStateMeta.d.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +export declare class MutableStateMetaBase { + public constructor(decorator: string) +} + +export declare class MutableStateMeta extends MutableStateMetaBase { + public addRef(): void + public fireChange(): void + public constructor(decorator: string) +} + +export declare class MutableKeyedStateMeta extends MutableStateMetaBase { + public addRef(key: string): void + public fireChange(key: string): void + public constructor(decorator: string) +} \ No newline at end of file diff --git a/api/arkui/stateManagement/common.d.ets b/api/arkui/stateManagement/common.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..2f479853668e98cb341c18043bafed1f22b08871 --- /dev/null +++ b/api/arkui/stateManagement/common.d.ets @@ -0,0 +1,81 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +@Retention({policy: "SOURCE"}) +export declare @interface State {}; + +@Retention({policy: "SOURCE"}) +export declare @interface Prop {}; + +@Retention({policy: "SOURCE"}) +export declare @interface Link {}; + +@Retention({policy: "SOURCE"}) +export declare @interface Observed {}; + +@Retention({policy: "SOURCE"}) +export declare @interface Track {}; + +@Retention({policy: "SOURCE"}) +export declare @interface ObjectLink {}; + +@Retention({policy: "SOURCE"}) +export declare @interface StorageProp { + property: string; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface StorageLink { + property: string; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface LocalStorageProp { + property: string; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface LocalStorageLink { + property: string; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface Provide { + alias: string = ""; + allowOverride: boolean = false; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface Consume { + alias: string = ""; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface Watch { + callback: string; +}; + +@Retention({policy: "SOURCE"}) +export declare @interface Require {}; + +export declare class UIUtils { + static getTarget(source: T): T; + static makeObserved(source: T): T; +} diff --git a/api/arkui/stateManagement/decorator.d.ets b/api/arkui/stateManagement/decorator.d.ets deleted file mode 100644 index 4acc119c9a09ba8b0a045c1cc0efc4428e01a184..0000000000000000000000000000000000000000 --- a/api/arkui/stateManagement/decorator.d.ets +++ /dev/null @@ -1,850 +0,0 @@ -/* - * 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. - */ -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -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. - * - * @interface IDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IDecoratedVariable { - /** - * Decorated variable name. - * - * @type { string } - * @readonly - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - readonly varName: string; -} - -/** - * Define V1 decorated variable interface. - * - * @extends IDecoratedVariable - * @interface IDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IDecoratedV1Variable extends IDecoratedVariable { - /** - * Registers the watch callback function with the data source. - * - * @param { IDecoratedV1Variable } decoratedVar - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - registerWatchToSource(decoratedVar: IDecoratedV1Variable): void; -} - -/** - * Define decorated immutable variable interface. - * - * @interface IDecoratedImmutableVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IDecoratedImmutableVariable { - /** - * Get the state variable. - * - * @returns { T } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - get(): T; -} - -/** - * Define decorated mutable variable interface. - * - * @interface IDecoratedMutableVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IDecoratedMutableVariable { - /** - * Get the state variable. - * - * @returns { T } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - get(): T; - /** - * Set the state variable with a new Value. - * - * @param { T } newValue - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - set(newValue: T): void; -} - -/** - * Define decorated updatable variable interface. - * - * @interface IDecoratedUpdatableVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IDecoratedUpdatableVariable { - /** - * Update the state variable with a new Value. - * - * @param { T } newValue - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - update(newValue: T): void; -} - -/** - * Define state decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IStateDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IStateDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -export declare interface IPropDecoratedVariable extends IDecoratedMutableVariable, - 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. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface ILinkDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface ILinkDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define Provide decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IProvideDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IProvideDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define Consume decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IConsumeDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IConsumeDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define ObjectLink decoration variable interface. - * - * @extends IDecoratedImmutableVariable, IDecoratedUpdatableVariable, IDecoratedV1Variable - * @interface IObjectLinkDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IObjectLinkDecoratedVariable extends IDecoratedImmutableVariable, - IDecoratedUpdatableVariable, IDecoratedV1Variable {} - -/** - * Define StorageLink decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IStorageLinkDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IStorageLinkDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define StorageProp decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IStoragePropDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IStoragePropDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable { -} - -/** - * Define StoragePropRef decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface IStoragePropRefDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IStoragePropRefDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define LocalStorageLink decoration variable interface. - * - * @extends IDecoratedMutableVariable, IDecoratedV1Variable - * @interface ILocalStorageLinkDecoratedVariable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface ILocalStorageLinkDecoratedVariable extends IDecoratedMutableVariable, IDecoratedV1Variable {} - -/** - * Define Link source type. - * - * @typedef { IStateDecoratedVariable | ILinkDecoratedVariable | IObjectLinkDecoratedVariable | - IPropDecoratedVariable | IStorageLinkDecoratedVariable | ILocalStorageLinkDecoratedVariable | IStoragePropRefDecoratedVariable | - IProvideDecoratedVariable | IConsumeDecoratedVariable } LinkSourceType - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export type LinkSourceType = IStateDecoratedVariable | ILinkDecoratedVariable | IObjectLinkDecoratedVariable | - IPropDecoratedVariable | IStorageLinkDecoratedVariable | ILocalStorageLinkDecoratedVariable | IStoragePropRefDecoratedVariable | - IProvideDecoratedVariable | IConsumeDecoratedVariable; - - -/** - * Define mutable state meta interface. - * - * @interface IMutableStateMeta - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface IMutableStateMeta { - /** - * Collect the dependancy for UI component with state variable - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - addRef(): void; - /** - * Notify UI component to update when state variable is changed - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - fireChange(): void; -} - -export declare interface IMutableKeyedStateMeta { - addRef(key: string): void; - addRef(index: int): void; - fireChange(key: string): void; - fireChange(index: int): void; -} - -export declare interface IObserve { - readonly renderingComponent: number; - readonly renderingId: RenderIdType; - shouldAddRef(iObjectsRenderId: RenderIdType): boolean; -} - -export declare const OBSERVE: IObserve; - -export type RenderIdType = int; - -export declare interface IObservedObject extends IWatchSubscriberRegister { - setV1RenderId(renderId: RenderIdType): void; -} - -export declare const STATE_MGMT_FACTORY: IStateMgmtFactory; - -export declare interface IStateMgmtFactory { - makeMutableStateMeta(): IMutableStateMeta; - makeSubscribedWatches(): ISubscribedWatches; - makeState(owningView: ExtendableComponent, varName: string, initValue: T, - watchFunc?: WatchFuncType): IStateDecoratedVariable; - makeProp(owningView: ExtendableComponent, varName: string, initValue: T, - watchFunc?: WatchFuncType): IPropDecoratedVariable; - makeLink(owningView: ExtendableComponent, varName: string, source: LinkSourceType, - watchFunc?: WatchFuncType): ILinkDecoratedVariable; - makeProvide(owningView: ExtendableComponent, varName: string, provideAlias: string, - initValue: T, allowOverride: boolean, wathcFunc?: WatchFuncType): IProvideDecoratedVariable; - makeConsume(owningView: ExtendableComponent, varName: string, - provideAlias: string, watchFunc?: WatchFuncType): IConsumeDecoratedVariable; - 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. - * - * @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 { IStorageLinkDecoratedVariable } StorageLink instance - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - makeStorageLink(owningView: ExtendableComponent, propName: string, - varName: string, initValue: T, ttype: Type, watchFunc?: WatchFuncType): IStorageLinkDecoratedVariable; - /** - * Create a StoragePropRef 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 { IStoragePropRefDecoratedVariable } StoragePropRef instance - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - 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. - * - * @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 { ILocalStorageLinkDecoratedVariable } LocalStorageLink instance - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - makeLocalStorageLink(owningView: ExtendableComponent, propName: string, - varName: string, initValue: T, ttype: Type, watchFunc?: WatchFuncType): ILocalStorageLinkDecoratedVariable; -} - -export type WatchFuncType = ((propertyName: string) => void); - -export type WatchIdType = int; - -export declare interface IWatchSubscriberRegister { - addWatchSubscriber(watchId: WatchIdType): void; - removeWatchSubscriber(watchId: WatchIdType): boolean; -} - -export declare interface ISubscribedWatches extends IWatchSubscriberRegister { - executeOnSubscribingWatches(propertyName: string): void; -} - -export declare interface AbstractProperty extends IDecoratedMutableVariable { - info(): string; -} - -export declare interface SubscribedAbstractProperty extends AbstractProperty { - aboutToBeDeleted(): void; -} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorConsume.d.ets b/api/arkui/stateManagement/decorators/decoratorConsume.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..bedeb8b5decf039688cd5ade1aeee0582ee0bc8e --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorConsume.d.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { ProvideDecoratedVariable } from './decoratorProvide' +import { WatchIdType, WatchFuncType } from './decoratorWatch'; + +export declare class ConsumeDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor( + varName: string, + provideAlias: string, + source: ProvideDecoratedVariable, + watchFunc?: WatchFuncType + ) + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorLink.d.ets b/api/arkui/stateManagement/decorators/decoratorLink.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..5d65d77dacbcccb242336a9b7972676ea0aa59ec --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorLink.d.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { WatchFuncType } from './decoratorWatch'; + +export declare class LinkDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor(varName: string, source: DecoratedV1VariableBase, watchFunc?: WatchFuncType) + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorObjectLink.d.ets b/api/arkui/stateManagement/decorators/decoratorObjectLink.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..c943219773e1e504d79c8f8a142bd5f1a88b4992 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorObjectLink.d.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedImmutableVariable, IDecoratedUpdatableVariable } from '../base/decoratorBase'; +import { WatchFuncType } from './decoratorWatch'; + +export declare class ObjectLinkDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedImmutableVariable, IDecoratedUpdatableVariable { + public constructor(varName: string, parentInitValue: T, watchFunc?: WatchFuncType) + public get(): T + public update(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorProp.d.ets b/api/arkui/stateManagement/decorators/decoratorProp.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..89eb7968be4b03ce3a1f19b69cc58b5d17623973 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorProp.d.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable, IDecoratedUpdatableVariable } from '../base/decoratorBase'; +import { WatchFuncType } from './decoratorWatch'; + +export declare class PropDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable, IDecoratedUpdatableVariable { + public constructor(varName: string, sourceValue: T, watchFunc?: WatchFuncType) + public get(): T + public set(newValue: T): void + public update(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorProvide.d.ets b/api/arkui/stateManagement/decorators/decoratorProvide.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..eea12b02491de14e7753f0ebb3ddc86361fa84d9 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorProvide.d.ets @@ -0,0 +1,29 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { WatchIdType, WatchFuncType } from './decoratorWatch'; + +export declare class ProvideDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor(varName: string, provideAlias: string, initValue: T, watchFunc?: WatchFuncType) + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorState.d.ets b/api/arkui/stateManagement/decorators/decoratorState.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..5992f62fc190765f6d6452621ede8e88f398c081 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorState.d.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { PropDecoratedVariable } from './decoratorProp'; +import { WatchIdType, WatchFuncType } from './decoratorWatch'; + +export declare interface __MkPropReturnType { + prop: PropDecoratedVariable; + watchId: WatchIdType; +} + +export declare class StateDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor(varName: string, initValue: T, watchFunc?: WatchFuncType) + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorStorageLink.d.ets b/api/arkui/stateManagement/decorators/decoratorStorageLink.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..45821e860b64524e8f38d44d67c74c1bdae91053 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorStorageLink.d.ets @@ -0,0 +1,31 @@ +/* + * 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. + */ + +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { WatchFuncType } from './decoratorWatch'; + +export declare class StorageLinkDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor(propName: string, varName: string, localValue: T, watchFunc?: WatchFuncType) + public getInfo(): string + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorStorageProp.d.ets b/api/arkui/stateManagement/decorators/decoratorStorageProp.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..574844395183b7fbc8e561fbae51a0f3647f82b2 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorStorageProp.d.ets @@ -0,0 +1,30 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { DecoratedV1VariableBase, IDecoratedMutableVariable } from '../base/decoratorBase'; +import { WatchFuncType } from './decoratorWatch'; + +export declare class StoragePropDecoratedVariable extends DecoratedV1VariableBase + implements IDecoratedMutableVariable { + public constructor(propName: string, varName:string, localVal: T, watchFunc?: WatchFuncType) + public getInfo(): string + public get(): T + public set(newValue: T): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/decorators/decoratorWatch.d.ets b/api/arkui/stateManagement/decorators/decoratorWatch.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..9607eb38cc6c45836f96297241e78a52c4df6bf9 --- /dev/null +++ b/api/arkui/stateManagement/decorators/decoratorWatch.d.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ +import { int32 } from '@koalaui.runtime.common'; + +export type WatchFuncType = ((propertyName: string) => void); + +export type WatchIdType = int32; + +export declare class WatchFunc { + public constructor(func: WatchFuncType) +} + +export declare interface IWatchTrigger { + addWatchSubscriber(watchId: WatchIdType): void + removeWatchSubscriber(watchId: WatchIdType): boolean + executeOnSubscribingWatches(propertyName: string): void +} + +export declare class SubscribedWatches implements IWatchTrigger { + public addWatchSubscriber(id: WatchIdType): void + public removeWatchSubscriber(id: WatchIdType): boolean + public executeOnSubscribingWatches(propertyName: string): void +} \ No newline at end of file diff --git a/api/arkui/stateManagement/storage.d.ets b/api/arkui/stateManagement/storage.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..d9db07a64504aaf2a2e84fb6678d6a5ecae1cfff --- /dev/null +++ b/api/arkui/stateManagement/storage.d.ets @@ -0,0 +1,339 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +export interface StorageProperty { + key: string; + defaultValue: number | string | boolean | Object; +} + +export type PersistPropsOptions = StorageProperty; + +interface AbstractProperty { + info(): string; + get(): T; + set(newValue: T): void; +} + +interface SubscribedAbstractProperty extends AbstractProperty { + aboutToBeDeleted(): void; +} + +declare class LocalStorage { + static getShared(): LocalStorage | undefined; + + constructor(initializingProperties?: StorageProperty[]); + + has(propName: string): boolean; + + keys(): IterableIterator; + + size(): int; + + get(propName: string): T | undefined; + + set(propName: string, newValue: T): boolean; + + setOrCreate(propName: string, newValue?: T): boolean; + + ref(propName: string): AbstractProperty | undefined; + + setAndRef(propName: string, defaultValue: T): AbstractProperty; + + link(propName: string): SubscribedAbstractProperty | undefined; + + setAndLink(propName: string, defaultValue: T): SubscribedAbstractProperty; + + prop(propName: string): SubscribedAbstractProperty | undefined; + + setAndProp(propName: string, defaultValue: T): SubscribedAbstractProperty; + + delete(propName: string): boolean; + + clear(): boolean; +} + +declare class AppStorage { + static has(propName: string): boolean; + + static keys(): IterableIterator; + + static size(): int; + + static get(propName: string): T | undefined; + + static set(propName: string, newValue: T): boolean; + + static setOrCreate(propName: string, newValue?: T): boolean; + + static ref(propName: string): AbstractProperty | undefined; + + static setAndRef(propName: string, defaultValue: T): AbstractProperty; + + static link(propName: string): SubscribedAbstractProperty | undefined; + + static setAndLink(propName: string, defaultValue: T): SubscribedAbstractProperty; + + static prop(propName: string): SubscribedAbstractProperty | undefined; + + static setAndProp(propName: string, defaultValue: T): SubscribedAbstractProperty; + + static delete(propName: string): boolean; + + static clear(): boolean; +} + +export declare class PersistentStorage { + + static persistProp(key: string, defaultValue: T): void; + + static deleteProp(key: string): void; + + static persistProps(props: PersistPropsOptions[]): void; + + static keys(): Array; +} + +export interface EnvPropsOptions { + key: string; + defaultValue: number | string | boolean; +} + +export declare class Environment { + static envProp(key: string, value: S): boolean; + + static envProps(props: EnvPropsOptions[]): void; + + static keys(): Array; +} + + +/** + * Function that returns default creator. + * + * @typedef { function } StorageDefaultCreator + * @returns { T } default creator + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export type StorageDefaultCreator = () => T; + +/** + * Define class constructor with arbitrary parameters. + * @interface TypeConstructorWithArgs + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +// #ToDO: fix +export interface TypeConstructorWithArgs { + /** + * @param { any } args the arguments of the constructor. + * @returns { T } return class instance. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + // new(...args: Array): T; +} + +/** + * AppStorageV2 is for UI state of app-wide access, has same life cycle as the app, + * and saves database content only in memory. + * + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export declare class AppStorageV2 { + /** + * If the value for the given key is already available, return the value. + * If not, add the key with value generated by calling defaultFunc and return it to caller. + * + * @param { TypeConstructorWithArgs } type class type of the stored value. + * @param { string | StorageDefaultCreator } [keyOrDefaultCreator] alias name of the key, + * or the function generating the default value. + * @param { StorageDefaultCreator } [defaultCreator] the function generating the default value + * @returns { T | undefined } the value of the existed key or the default value + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static connect( + type: TypeConstructorWithArgs, + keyOrDefaultCreator?: string | StorageDefaultCreator, + defaultCreator?: StorageDefaultCreator + ): T | undefined; + + /** + * Removes data with the given key or given class type. + * + * @param { string | TypeConstructorWithArgs } keyOrType key or class type removing + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static remove(keyOrType: string | TypeConstructorWithArgs): void; + /** + * Return the array of all keys. + * + * @returns { Array } the array of all keys + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static keys(): Array; +} + +/** + * Function that returns reason type when error. + * + * @typedef { function } PersistenceErrorCallback + * @param { string } key persisted key when error + * @param { 'quota' | 'serialization' | 'unknown' } reason reason type when error + * @param { string } message more message when error + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export type PersistenceErrorCallback = (key: string, reason: 'quota' | 'serialization' | 'unknown', message: string) => void; + +/** + * PersistenceV2 is for UI state of app-wide access, available on app re-start, + * and saves database content in disk. + * + * @extends AppStorageV2 + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export declare class PersistenceV2 extends AppStorageV2 { + /** + * Used to manually persist data changes to disks. + * + * @param { string | TypeConstructorWithArgs } keyOrType key or class type need to persist. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static save(keyOrType: string | TypeConstructorWithArgs): void; + + /** + * Be called when persisting has encountered an error. + * + * @param { PersistenceErrorCallback | undefined } callback called when error + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static notifyOnError(callback: PersistenceErrorCallback | undefined): void; +} + +/** + * Define TypeConstructor type. + * + * @interface TypeConstructor + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export interface TypeConstructor { + /** + * @returns { T } + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + // new(): T; +} + +/** + * Function that returns PropertyDecorator. + * + * @typedef { function } TypeDecorator + * @param { TypeConstructor } type type info + * @returns { PropertyDecorator } Type decorator + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +// export type TypeDecorator = (type: TypeConstructor) => PropertyDecorator; + + +/** + * Define Type PropertyDecorator, adds type information to an object. + * + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +// export declare const Type: TypeDecorator; + +/** + * UIUtils is a state management tool class for operating the observed data. + * + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export declare class UIUtils { + /** + * Get raw object from the Object wrapped with an ObservedObject. + * If input parameter is a regular Object without ObservedObject, return Object itself. + * + * @param { T } source input source Object data. + * @returns { T } raw object from the Object wrapped with an ObservedObject. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static getTarget(source: T): T; + + /** + * Make non-observed data into observed data. + * Support non-observed class, JSON.parse Object and Sendable class. + * + * @param { T } source input source object data. + * @returns { T } proxy object from the source object data. + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static makeObserved(source: T): T; + +} \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/environment.d.ets b/api/arkui/stateManagement/storage/environment.d.ets deleted file mode 100644 index 0a5fef29db487987febeda98bcdcffeb6f685127..0000000000000000000000000000000000000000 --- a/api/arkui/stateManagement/storage/environment.d.ets +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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. - */ - -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -/** - * EnvProps object - * - * @interface EnvPropsOptions - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare interface EnvPropsOptions { - - /** - * Property name of Environment variable - * - * @type { string } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - key: string; - - /** - * DefaultValue is the default value if cannot get the environment property value - * - * @type { number | string | boolean } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - defaultValue: number | string | boolean; -} - -/** - * Defines the Environment interface. - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare class Environment { - /** - * Creates a new property in AppStorage. The UI framework implementation takes care of updating - * its value whenever the named device environment property changes. Recommended use is at app startup. - * The function call fails and returns false if a property with given name exists in AppStorage already. - * It is wrong API use to access a property with given name in AppStorage before calling Environment.envProp. - * - * @param { string } key - environment property - * @param { T } value - is the default value if cannot get the environment property value - * @returns { boolean } false if method failed - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static envProp(key: string, value: T): boolean; - - /** - * Called when multiple property values are added to Environment. - * - * @param { EnvPropsOptions[] } props environment parameter - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static envProps(props: EnvPropsOptions[]): void; - - /** - * returns an Array of all environment property keys - * - * @returns { Array } all environment property keys - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static keys(): Array; -} \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/localStorage.d.ets b/api/arkui/stateManagement/storage/localStorage.d.ets deleted file mode 100644 index 4ddea45ee6a853c58ea43f43a4e65b7a441c6be1..0000000000000000000000000000000000000000 --- a/api/arkui/stateManagement/storage/localStorage.d.ets +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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. - */ -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -import { IStorageProperties, AbstractProperty, SubscribedAbstractProperty } from './storageProperty'; - -/** - * LocalStorage - * Class implements a Map of ObservableObjectBase UI state variables. - * Instances can be created to manage UI state within a limited "local" - * access, and life cycle as defined by the app. - * AppStorage singleton is sub-class of LocalStorage for - * UI state of app-wide access and same life cycle as the app. - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare class LocalStorage { - /** - * Construct new instance of LocalStorage - * initialize with all properties and their values that Object.keys(params) returns - * Property values must not be undefined. - * - * @param { Record } [initializingProperties] - Record - * containing keys and values. - * see set() for valid values - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public constructor(initializingProperties?: Record); - /** - * Obtain a handler or an alias to LocalStorage property with given name. - * - * @param { string } propName LocalStorage property name - * @param {Type} ttype - data type - * @returns { AbstractProperty | undefined } AbstractProperty object if property with given name exists - * return undefined otherwise. - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public ref(propName: string, ttype: Type): AbstractProperty | undefined; - /** - * Obtain a handler or an alias to LocalStorage property with given name. - * - * If property does not exist in LocalStorage, create it with given default value. - * - * @param { string } propName LocalStorage property name - * @param { T } defaultValue If property does not exist in LocalStorage, - * create it with given default value. - * @param {Type} ttype - data type - * @returns { AbstractProperty } AbstractProperty object - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public setAndRef(propName: string, defaultValue: T, ttype: Type): AbstractProperty; - /** - * Create and return a two-way sync "(link") to named property - * - * @param { string } propName - name of source property in LocalStorage - * @param { Type } ttype - data type - * @returns { SubscribedAbstractProperty | undefined } instance of SubscribedAbstractProperty - * return undefined if named property does not already exist in LocalStorage - * Apps can use SDK functions of base class SubscribedPropertyAbstract - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @crossplatform - * @since 20 - */ - public link(propName: string, ttype: Type): SubscribedAbstractProperty | undefined; - - /** - * Like see link(), but will create and initialize a new source property in LocalStorage if missing - * - * @param { string } propName - name of source property in LocalStorage - * @param { T } defaultValue - value to be used for initializing new property in LocalStorage - * default value must be of type T, can be undefined or null. - * @param { Type } ttype - data type - * @returns { SubscribedAbstractProperty } instance of SubscribedAbstractProperty - * Apps can use SDK functions of base class SubscribedAbstractProperty - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public setAndLink(propName: string, defaultValue: T, ttype: Type): SubscribedAbstractProperty; - - /** - * Check if LocalStorage has a property with given name - * return true if property with given name exists - * same as ES6 Map.prototype.has() - * - * @param { string } propName - searched property - * @param { Type } [ttype] - data type - * @returns { boolean } true if property with such name exists in LocalStorage - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public has(propName: string, ttype?: Type): boolean; - /** - * Returns value of given property - * return undefined if no property with this name - * - * @param { string } propName - property name - * @param {Type} ttype - data type - * @returns { T | undefined } property value if found or undefined - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public get(propName: string, ttype: Type): T | undefined; - /** - * Set value of given property in LocalStorage - * Method sets nothing and returns false if property with this name does not exist in LocalStorage - * newValue can be undefined or null from API 20. - * - * @param { string } propName - * @param { T } newValue - must be of type T, can be undefined or null - * @returns { boolean } true on success, i.e. when above conditions are satisfied, otherwise false - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public set(propName: string, newValue: T): boolean; - /** - * Set value of given property, if it exists, see set() . - * Add property if no property with given name and initialize with given value. - * newValue can be undefined or null from API 12 - * - * @param { string } propName - * @param { T } newValue - must be of type T, can be undefined or null - * @param { Type } ttype - data type - * @returns { boolean } true on success, i.e. when above conditions are satisfied, otherwise false - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public setOrCreate(propName: string, newValue: T, ttype: Type): boolean; - /** - * Provide names of all properties in LocalStorage - * same as ES6 Map.prototype.keys() - * - * @returns { IterableIterator } return a Map Iterator - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public keys(): IterableIterator; - /** - * Returns number of properties in LocalStorage - * same as Map.prototype.size() - * - * @returns { number } return number of properties - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public size(): number; - /** - * Delete property from StorageBase - * Use with caution: - * Before deleting a prop from LocalStorage all its subscribers need to - * unsubscribe from the property. - * This method fails and returns false if given property still has subscribers - * Another reason for failing is unknown property. - * Developer advise: - * Subscribers are created with see link(), see prop() - * and also via @LocalStorageLink and @LocalStorageProp state variable decorators. - * That means as long as their is a @Component instance that uses such decorated variable - * or a sync relationship with a SubscribedAbstractProperty variable the property can nit - * (and also should not!) be deleted from LocalStorage. - * - * @param { string } propName - * @returns { boolean } false if method failed - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public delete(propName: string): boolean; - /** - * Delete all properties from the LocalStorage instance - * Precondition is that there are no subscribers. - * method returns false and deletes no properties if there is any property - * that still has subscribers - * - * @returns { boolean } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - public clear(): boolean; -} \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/persistentStorage.d.ets b/api/arkui/stateManagement/storage/persistentStorage.d.ets deleted file mode 100644 index fcb91d1ec523ca4c97f9436b0cde85ca23dc8999..0000000000000000000000000000000000000000 --- a/api/arkui/stateManagement/storage/persistentStorage.d.ets +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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. - */ - -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -/** - * Defines the PersistentStorage interface. - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare class PersistentStorage { - /** - * Add property 'key' to AppStorage properties whose current value will be - * persistent. - * If AppStorage does not include this property it will be added and initializes - * with given value - * - * @param { string } key - property name - * @param { Type } ttype - persist value type - * @param { T } defaultValue - If AppStorage does not include this property it will be initialized with this value - * @param { ToJSONType } [toJson] - serialization function - * @param { FromJSONType } [fromJson] - deserialization function - * @returns { boolean } - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static persistProp(key: string, ttype: Type, defaultValue: T, - toJson?: ToJSONType, fromJson?: FromJSONType): boolean; - - /** - * Reverse of @see persistProp - * - * @param { string } key - no longer persist the property named key - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static deleteProp(key: string): void; - - /** - * Inform persisted AppStorage property names - * - * @returns { Array } array of AppStorage keys - * @static - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - static keys(): Array; -} - -/** - * Define toJson type function. - * - * @typedef { function } ToJSONType - * @param { T } value toJson value - * @returns { jsonx.JsonElement } Json stringify element object - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare type ToJSONType = (value: T) => jsonx.JsonElement; - -/** - * Define fromJson type function. - * - * @typedef { function } FromJSONType - * @param { jsonx.JsonElement } element json element - * @returns { T } deserialization result - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export declare type FromJSONType = (element: jsonx.JsonElement) => T; \ No newline at end of file diff --git a/api/arkui/stateManagement/storage/storageProperty.d.ets b/api/arkui/stateManagement/storage/storageProperty.d.ets deleted file mode 100644 index 191374a7e22d6df9a5e8b2507bed8f5d68382f05..0000000000000000000000000000000000000000 --- a/api/arkui/stateManagement/storage/storageProperty.d.ets +++ /dev/null @@ -1,144 +0,0 @@ -/* - * 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. - */ -/** - * @file - * @kit ArkUI - * @arkts 1.2 - */ - -/** - * Defines the callback that is called when state variable with value is change - * @typedef { function } OnChangeType - * @param {string} propertyName - property name - * @param {T} newValue - the new value of state variable - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export type OnChangeType = (propertyName: string, newValue: T) => void; - -/** - * Define AbstractProperty interface. - * - * AbstractProperty can be understood as a handler or an alias - * to a property inside LocalStorage / AppStorage singleton - * allows to read the value with @see get and to change the - * value with @see set. - * - * @interface AbstractProperty - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export interface AbstractProperty { - /** - * Returns the name of the referenced property - * - * @returns { string } name of the referenced property - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - info(): string { return ""; }; - - /** - * Returns the type of the referenced property - * - * @returns { Type } type of the referenced property - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - ttype(): Type { return Type.of(undefined); }; - - /** - * Reads value of the referenced AppStorage/LocalStorage property. - * - * @returns { T } value of the referenced AppStorage/LocalStorage property. - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - get(): T { return undefined; }; - - /** - * Assign a new value to the referenced property - * - * @param {T} newValue - a new value of the referenced property - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - set(newValue: T): void {}; - /** - * Register callback function to be called on value change of the referenced property - * calling with value undefined clear the callback. - * - * @param {OnChangeType | undefined} onChangeFunc - register callback function - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - onChange(onChangeFunc: OnChangeType | undefined): void {}; -} - -/** - * SubscribedAbstractProperty is the return value of - * - AppStorage static functions Link(), Prop(), SetAndLink(), and SetAndProp() - * - LocalStorage member methods link(), prop(), setAndLink(), and setAndProp() - * 'T' can be boolean, string, number or custom class. - * Main functions - * see get() reads the linked AppStorage/LocalStorage property value, - * see set(newValue) write a new value to the synched AppStorage/LocalStorage property - * see aboutToBeDeleted() ends the sync relationship with the AppStorage/LocalStorage property - * The app must call this function before the SubscribedAbstractProperty object - * goes out of scope. - * - * @extends AbstractProperty - * @interface SubscribedAbstractProperty - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export interface SubscribedAbstractProperty extends AbstractProperty { - /** - * An app needs to call this function before the instance of SubscribedAbstractProperty - * goes out of scope / is subject to garbage collection. Its purpose is to unregister the - * variable from the two-way/one-way sync relationship that AppStorage/LocalStorage.link()/prop() - * and related functions create. - * - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - aboutToBeDeleted(): void {}; -} - -/** - * Define IStorageProperties interface - * - * @interface IStorageProperties - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ -export interface IStorageProperties { - /** - * Storage value. - * - * @type { NullishType } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - value: NullishType; - /** - * Storage variable ttype. - * - * @type { Type } - * @syscap SystemCapability.ArkUI.ArkUI.Full - * @since 20 - */ - ttype: Type; -} \ No newline at end of file diff --git a/api/arkui/stateManagement/storages/appStorage.d.ets b/api/arkui/stateManagement/storages/appStorage.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..b5d4066fe5a0935bc725e7be4fd09b64ee370f87 --- /dev/null +++ b/api/arkui/stateManagement/storages/appStorage.d.ets @@ -0,0 +1,39 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { LocalStorage } from './localStorage'; +import { AbstractProperty, SubscribedAbstractProperty } from '../base/decoratorBase'; + +export declare class AppStorage extends LocalStorage { + public static ref(propName: string): AbstractProperty | undefined; + public static setAndRef(propName: string, defaultValue: T): AbstractProperty; + public static link(propName: string): SubscribedAbstractProperty | undefined; + public static setAndLink(propName: string, defaultValue: T): SubscribedAbstractProperty; + public static prop(propName: string): SubscribedAbstractProperty | undefined; + public static setAndProp(propName: string, defaultValue: T): SubscribedAbstractProperty; + public static has(propName: string): boolean; + public static get(propName: string): T | undefined; + public static set(propName: string, newValue: T): boolean; + public static setOrCreate(propName: string, newValue: T): void; + public static keys(): IterableIterator; + public static size(): number; + public static delete(propName: string): boolean; + public static clear(): boolean; +} \ No newline at end of file diff --git a/api/arkui/stateManagement/storages/localStorage.d.ets b/api/arkui/stateManagement/storages/localStorage.d.ets new file mode 100644 index 0000000000000000000000000000000000000000..96f27906180faa0f6ce5f37463775bc1a73c769f --- /dev/null +++ b/api/arkui/stateManagement/storages/localStorage.d.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ +/** + * @file + * @kit ArkUI + * @arkts 1.2 + */ + +import { AbstractProperty, SubscribedAbstractProperty } from '../base/decoratorBase'; + +export declare class LocalStorage { + public constructor(initializingProperties?: Object); + public static getShared(): LocalStorage | undefined; + public ref(propName: string): AbstractProperty | undefined; + public setAndRef(propName: string, defaultValue: T): AbstractProperty; + public link(propName: string): SubscribedAbstractProperty | undefined; + public setAndLink(propName: string, defaultValue: T): SubscribedAbstractProperty; + public prop(propName: string): SubscribedAbstractProperty | undefined; + public setAndProp(propName: string, defaultValue: T): SubscribedAbstractProperty; + public has(propName: string): boolean; + public get(propName: string): T | undefined; + public set(propName: string, newValue: T): boolean; + public setOrCreate(propName: string, newValue: T): boolean; + public keys(): IterableIterator; + public size(): number; + public delete(propName: string): boolean; + public clear(): boolean; +} \ No newline at end of file