From 78c56283bf3802cdc5ccd1987a53ff2f9388f6c7 Mon Sep 17 00:00:00 2001 From: Annie_wang Date: Tue, 21 Feb 2023 17:18:52 +0800 Subject: [PATCH] update docs Signed-off-by: Annie_wang --- .../apis/js-apis-distributedKVStore.md | 18 +-- .../reference/apis/js-apis-system-storage.md | 108 ++++++++++++------ 2 files changed, 79 insertions(+), 47 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-distributedKVStore.md b/en/application-dev/reference/apis/js-apis-distributedKVStore.md index 7dbc21ff6d..11b7053bbd 100644 --- a/en/application-dev/reference/apis/js-apis-distributedKVStore.md +++ b/en/application-dev/reference/apis/js-apis-distributedKVStore.md @@ -271,10 +271,10 @@ Creates a **KVManager** instance to manage KV stores. Stage model: ```js -import AbilityStage from '@ohos.application.Ability' +import UIAbility from '@ohos.app.ability.UIAbility' let kvManager; -export default class MyAbilityStage extends AbilityStage { +export default class EntryAbility extends UIAbility { onCreate() { console.log("MyAbilityStage onCreate") let context = this.context @@ -722,7 +722,7 @@ Subscribes to service status changes. | Name | Type | Mandatory| Description | | ------------- | -------------------- | ---- | ------------------------------------------------------------ | | event | string | Yes | Event to subscribe to. The value is **distributedDataServiceDie**, which indicates a service status change event.| -| deathCallback | Callback<void> | Yes | Callback invoked to return service status changes. | +| deathCallback | Callback<void> | Yes | Callback invoked to return service status changes. | **Example** @@ -2847,7 +2847,7 @@ try { ### get -get(key: string, callback: AsyncCallback): void +get(key: string, callback: AsyncCallback<boolean | string | number | Uint8Array>): void Obtains the value of the specified key. This API uses an asynchronous callback to return the result. @@ -2898,7 +2898,7 @@ try { ### get -get(key: string): Promise<boolean | string| number | Uint8Array> +get(key: string): Promise<boolean | string | number | Uint8Array> Obtains the value of the specified key. This API uses a promise to return the result. @@ -4849,7 +4849,7 @@ Before calling any method in **DeviceKVStore**, you must use [getKVStore](#getkv ### get -get(key: string, callback: AsyncCallback): void +get(key: string, callback: AsyncCallback<boolean | string | number | Uint8Array>): void Obtains the value of the specified key for this device. This API uses an asynchronous callback to return the result. @@ -4900,7 +4900,7 @@ try { ### get -get(key: string): Promise<boolean | string| number | Uint8Array> +get(key: string): Promise<boolean | string | number | Uint8Array> Obtains the value of the specified key for this device. This API uses a promise to return the result. @@ -4952,7 +4952,7 @@ try { ### get -get(deviceId: string, key: string, callback: AsyncCallback<boolean|string|number|Uint8Array>): void +get(deviceId: string, key: string, callback: AsyncCallback<boolean | string | number | Uint8Array>): void Obtains a string value that matches the specified device ID and key. This API uses an asynchronous callback to return the result. @@ -5004,7 +5004,7 @@ try { ### get -get(deviceId: string, key: string): Promise<boolean|string|number|Uint8Array> +get(deviceId: string, key: string): Promise<boolean | string | number | Uint8Array> Obtains a string value that matches the specified device ID and key. This API uses a promise to return the result. diff --git a/en/application-dev/reference/apis/js-apis-system-storage.md b/en/application-dev/reference/apis/js-apis-system-storage.md index 57891f91e4..a4a3bb6b5d 100644 --- a/en/application-dev/reference/apis/js-apis-system-storage.md +++ b/en/application-dev/reference/apis/js-apis-system-storage.md @@ -1,23 +1,22 @@ # @system.storage (Data Storage) -> **NOTE**
+> **NOTE** > -> - The APIs of this module are no longer maintained since API Version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API Version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). +> - The APIs of this module are no longer maintained since API version 6, and you are advised to use [`@ohos.data.storage`](js-apis-data-storage.md). From API version 9, you are advised to use [`@ohos.data.preferences`](js-apis-data-preferences.md). > -> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> - The APIs of this module can be used only in the FA model. +> - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> - The APIs of this module can be used only in the FA model. ## Modules to Import - ```js import storage from '@system.storage'; ``` - ## storage.get -get(Object): void +get(options: GetStorageOptions): void Reads the value stored in the cache based on the specified key. @@ -25,13 +24,9 @@ Reads the value stored in the cache based on the specified key. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| key | string | Yes| Key of the data to read.| -| default | string | No| Default value returned when the **key** does not exist.| -| success | Function | No| Called to return the value obtained when **storage.get()** is successful.| -| fail | Function | No| Called when **storage.get()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| -| complete | Function | No| Called when **storage.get()** is complete.| +| Name | Type | Mandatory| Description | +| ------- | -------------------- | ---- | ---------- | +| options | [GetStorageOptions](#getstorageoptions) | Yes | API configuration.| **Example** @@ -54,10 +49,9 @@ export default { } ``` - ## storage.set -set(Object): void +set(options: SetStorageOptions): void Sets the value in the cache based on the specified key. @@ -65,13 +59,9 @@ Sets the value in the cache based on the specified key. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| key | string | Yes| Key of the data to set.| -| value | string | Yes| New value to set. The length must be less than 128 bytes.| -| success | Function | No| Called when **storage.set()** is successful.| -| fail | Function | No| Called when **storage.set()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| -| complete | Function | No| Called when **storage.set()** is complete.| +| Name | Type | Mandatory| Description | +| ------- | ------------------- | ---- | ---------- | +| options | [SetStorageOptions](#setstorageoptions) | Yes | API configuration.| **Example** @@ -92,10 +82,9 @@ export default { } ``` - ## storage.clear -clear(Object): void +clear(options?: ClearStorageOptions): void Clears the key-value pairs from the cache. @@ -103,11 +92,9 @@ Clears the key-value pairs from the cache. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| success | Function | No| Called when **storage.clear()** is successful.| -| fail | Function | No| Called when **storage.clear()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| -| complete | Function | No| Called when **storage.clear()** is complete.| +| Name | Type | Mandatory| Description | +| ------- | ------------------------------------------- | ---- | -------------- | +| options | [ClearStorageOptions](#clearstorageoptions) | No | API configuration.| **Example** @@ -126,10 +113,9 @@ export default { } ``` - ## storage.delete -delete(Object): void +delete(options: DeleteStorageOptions): void Deletes the key-value pair based on the specified key. @@ -137,12 +123,9 @@ Deletes the key-value pair based on the specified key. **Parameters** -| Name| Type| Mandatory| Description| -| -------- | -------- | -------- | -------- | -| key | string | Yes| Key of the data to delete.| -| success | Function | No| Called when **storage.delete()** is successful.| -| fail | Function | No| Called when **storage.delete()** fails. In the callback, **data** indicates the error information, and **code** indicates the error code.| -| complete | Function | No| Called when **storage.delete()** is complete.| +| Name | Type | Mandatory| Description | +| ------- | --------------------------------------------- | ---- | -------------- | +| options | [DeleteStorageOptions](#deletestorageoptions) | Yes | API configuration.| **Example** @@ -161,3 +144,52 @@ export default { } } ``` + +## GetStorageOptions + +**System capability**: SystemCapability.DistributedDataManager.Preferences.Core + +| Name | Type | Mandatory| Description | +| -------- | ---------------- | ---- | ------------------- | +| key | string | Yes | Key of the target data. | +| default | string | No | Default value returned when the specified key does not exist. | +| success | (data: any) => void | No | Called to return the result when **storage.get()** is called successfully. **data** is the value indexed by the specified key. | +| fail | (data: string, code: number) => void | No | Called to return the result when **storage.get()** fails to be called. **data** is the error information, and **code** indicates the error code. | +| complete | () => void | No | Called when **storage.get()** is complete. | + + +## SetStorageOptions + +**System capability**: SystemCapability.DistributedDataManager.Preferences.Core + +| Name | Type | Mandatory| Description | +| -------- | ------------------- | ---- | -------------------- | +| key | string | Yes | Key of the data to set. | +| value | string | Yes | New value to set. The length must be less than 128 bytes. | +| success | () => void | No | Called when **storage.set()** is called successfully. | +| fail | (data: string, code: number) => void | No | Called to return the result when **storage.set()** fails to be called. **data** is the error information, and **code** indicates the error code. | +| complete | () => void | No | Called when **storage.set()** is complete. | + + +## ClearStorageOptions + +**System capability**: SystemCapability.DistributedDataManager.Preferences.Core + +| Name | Type | Mandatory| Description | +| -------- | --------------------- | ---- | -------------------- | +| success | () => void | No | Called when **storage.clear()** is called successfully. | +| fail | (data: string, code: number) => void | No | Called to return the result when **storage.clear()** fails to be called. **data** is the error information, and **code** indicates the error code. | +| complete | () => void | No | Called when **storage.clear()** is complete. | + + +## DeleteStorageOptions + +**System capability**: SystemCapability.DistributedDataManager.Preferences.Core + +| Name | Type | Mandatory| Description | +| -------- | -------------------- | ---- | ------------------ | +| key | string | Yes | Key of the data to delete. | +| success | () => void | No | Called when **storage.delete()** is called successfully. | +| fail | (data: string, code: number) => void | No | Called to return the result when **storage.delete()** fails to be called. **data** is the error information, and **code** indicates the error code. | +| complete | () => void | No | Called when **storage.delete()** is complete. | + -- GitLab