diff --git a/api/@ohos.arkui.StateManagement.d.ts b/api/@ohos.arkui.StateManagement.d.ts new file mode 100644 index 000000000..008b9cb75 --- /dev/null +++ b/api/@ohos.arkui.StateManagement.d.ts @@ -0,0 +1,170 @@ +/* + * Copyright (C) 2024 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 + */ + +/** + * Function that returns default creator. + * + * @typedef { function } StorageDefaultCreator + * @returns { T } default creator + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ +export declare type StorageDefaultCreator = () => 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 { string } key key adding + * @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(key: string, defaultCreator?: StorageDefaultCreator): T | undefined; + + /** + * Removes the given key. Return false if the given key does not exist. + * + * @param { string } key key removing + * @returns { boolean } exist or not + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static remove(key: string): boolean; + + /** + * 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 declare 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 { + /** + * The purpose of the save function is request to persist non-observed object changes. + * + * @param { string } key key need to save, that persist non-observed object changes + * @syscap SystemCapability.ArkUI.ArkUI.Full + * @crossplatform + * @atomicservice + * @since 12 + */ + static save(key: string): 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 declare 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; diff --git a/kits/@kit.ArkUI.d.ts b/kits/@kit.ArkUI.d.ts index b9c7bbcd5..90d3e6cec 100644 --- a/kits/@kit.ArkUI.d.ts +++ b/kits/@kit.ArkUI.d.ts @@ -114,6 +114,7 @@ import { PresetSplitRatio, FoldSplitContainer, } from '@ohos.arkui.advanced.FoldSplitContainer'; +import { AppStorageV2, PersistenceV2, Type } from '@ohos.arkui.StateManagement'; export { AddFormMenuItem, AddFormOptions, AlertDialog, Animator, AnimatorOptions, AnimatorResult, App, AppResponse, AtomicServiceBar, @@ -142,5 +143,6 @@ export { screen, screenshot, uiAppearance, uiExtensionHost, uiObserver, window, windowAnimationManager, CustomContentDialog, IconOptions, ChipItemLabelOptions, ChipGroupItemOptions, ChipItemStyle, ChipGroupSpaceOptions, IconItemOptions, IconGroupSuffix, ChipGroup, SymbolGlyphModifier, Colors, CustomColors, Theme, ThemeControl, CustomTheme, ChipSymbolGlyphOptions, - ExtraRegionPosition, ExpandedRegionLayoutOptions, SemiFoldedRegionLayoutOptions, FoldedRegionLayoutOptions, PresetSplitRatio, FoldSplitContainer + ExtraRegionPosition, ExpandedRegionLayoutOptions, SemiFoldedRegionLayoutOptions, FoldedRegionLayoutOptions, PresetSplitRatio, FoldSplitContainer, + AppStorageV2, PersistenceV2, Type };