diff --git a/en/application-dev/database/database-distributedobject-guidelines.md b/en/application-dev/database/database-distributedobject-guidelines.md index 08b72e45cbd9c1f505f99be567e45296fbce8c52..440ed7160c1736522027f42050d0affd1c98ad71 100644 --- a/en/application-dev/database/database-distributedobject-guidelines.md +++ b/en/application-dev/database/database-distributedobject-guidelines.md @@ -2,7 +2,7 @@ ## When to Use -The distributed data objects allow data across devices to be processed like local variables by shielding complex data interaction between devices. For the devices that form a Super Device, when data in the distributed data object of an application is added, deleted, or modified on a device, the data for the same application is also updated on the other devices. The devices can listen for the data changes and online and offline states of other devices. The distributed data objects support basic data types, such as number, string, and Boolean, as well as complex data types, such as array and nested basic types. +The distributed data objects allow data across devices to be processed like local variables by shielding complex data interaction between devices. For the devices that form a Super Device, when data in the distributed data object of an application is added, deleted, or modified on a device, the data for the same application is also updated on the other devices. The devices can listen for the data changes and online and offline status of other devices. The distributed data objects support basic data types, such as number, string, and Boolean, as well as complex data types, such as array and nested basic types. ## Available APIs @@ -15,7 +15,7 @@ Call **createDistributedObject()** to create a distributed data object instance. **Table 1** API for creating a distributed data object instance | Package| API| Description| | -------- | -------- | -------- | -| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.
-  **source**: attributes of the **distributedObject** set.
-  **DistributedObject**: returns the distributed object created.| +| ohos.data.distributedDataObject| createDistributedObject(source: object): DistributedObject | Creates a distributed data object instance for data operations.
- **source**: attributes of the **distributedObject** set.
- **DistributedObject**: returns the distributed object created.| ### Generating a Session ID @@ -28,12 +28,12 @@ Call **genSessionId()** to generate a session ID randomly. The generated session ### Setting a SessionID for Distributed Data Objects -Call setSessionId() to set the session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID. +Call **setSessionId()** to set a session ID for a distributed data object. The session ID is a unique identifier for one collaboration across devices. The distributed data objects to be synchronized must be associated with the same session ID. **Table 3** API for setting a session ID | Class| API| Description| | -------- | -------- | -------- | -| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.
 **sessionId**: ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| +| DistributedDataObject | setSessionId(sessionId?: string): boolean | Sets a session ID for distributed data objects.
 **sessionId**: session ID of a distributed object in a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| ### Observing Data Changes @@ -43,7 +43,7 @@ Call **on()** to subscribe to data changes of a distributed data object. When th | Class| API| Description| | -------- | -------- | -------- | | DistributedDataObject| on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void | Subscribes to data changes.| -| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void | Unsubscribes from data changes. Callback used to return changes of the distributed object. If this parameter is not specified, all callbacks related to data changes will be unregistered.| +| DistributedDataObject| off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void | Unsubscribes from data changes. **Callback**: specifies callback used to return changes of the distributed data object. If this parameter is not specified, all callbacks related to data changes will be unregistered.| ### Observing Online or Offline Status @@ -90,10 +90,10 @@ The following example shows how to implement a distributed data object synchroni var remote_object = distributedObject.createDistributedObject({name:undefined, age:undefined, isVis:true, parent:undefined, list:undefined}); remote_object.setSessionId(sessionId); - // After obtaining that the device status goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. + // After learning that the device goes online, the remote object synchronizes data. That is, name changes to jack and age to 18. ``` -4. Observe the data changes of the distributed data object. Subscribe to data changes of the remote end. When the data is the peer end changes, a callback will be called to return the data changes. +4. Observe the data changes of the distributed data object. You can subscribe to data changes of the peer object. When the data in the peer object changes, a callback will be called to return the data changes. The sample code is as follows: @@ -108,8 +108,8 @@ The following example shows how to implement a distributed data object synchroni } } - // To refresh the page in changeCallback, correctly set this.changeCallback.bind(this) in - changeCallback. + // To refresh the page in changeCallback, correctly bind (this) to the changeCallback. + local_object.on("change", this.changeCallback.bind(this)); ``` 5. Modify object attributes. The object attributes support basic data types (such as number, Boolean, and string) and complex data types (array and nested basic types). @@ -123,7 +123,7 @@ The following example shows how to implement a distributed data object synchroni local_object.list = [{mother:"jack mom"}, {father:"jack Dad"}]; ``` - > ![icon-note.gif](../public_sys-resources/icon-note.gif) **NOTE**
+ > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> For the distributed data object of the complex type, only the root attribute can be modified. The subordinate attributes cannot be modified. Example: ```js // Supported modification. @@ -142,7 +142,7 @@ The following example shows how to implement a distributed data object synchroni The sample code is as follows: ```js - // Unsubscribe from changeCallback. + // Unsubscribe from the specified data change callback. local_object.off("change", changeCallback); // Unsubscribe from all data change callbacks. local_object.off("change"); @@ -156,16 +156,16 @@ The following example shows how to implement a distributed data object synchroni local_object.on("status", this.statusCallback); ``` -9. Unsubscribe from the status changes of the distributed data object. You can specify the callback to unsubscribe from. If you do not specify the callback, all status change callbacks will be unsubscribe from. +9. Unsubscribe from the status changes of the distributed data object. You can specify the callback to unsubscribe from. If you do not specify the callback, this API unsubscribes from all callbacks of this distributed data object. The sample code is as follows: ```js - // Unsubscribe from the online status change callback. + // Unsubscribe from the specified status change callback. local_object.off("status", statusCallback); - // Unsubscribe from all online status change callbacks. + // Unsubscribe from all status change callbacks. local_object.off("status"); ``` -10. Remove a distributed data object from the synchronization network. After the distributed data object is removed from the network, the data changes on the local end will not be synchronized to the remote end. +10. Remove a distributed data object from the synchronization network. Data changes on the local object will not be synchronized to the removed distributed data object. The sample code is as follows: ```js @@ -173,10 +173,10 @@ The following example shows how to implement a distributed data object synchroni ``` ## Development Example -The following example is provided for you to better understand the development of distributed data object: +The following example is provided for you to better understand the development of distributed data objects: - [Distributed Notepad](https://gitee.com/openharmony/distributeddatamgr_objectstore/tree/master/samples/distributedNotepad) -When an event occurs on a device, such as a note is added, the tile or content of a note is changed, and the event list is cleared, the change will be synchronized to other devices in the trusted network by the Notepad app. +When an event of the Notepad app occurs on a device, such as a note is added, the tile or content of a note is changed, or the event list is cleared, the change will be synchronized to other devices in the trusted network. diff --git a/en/application-dev/reference/apis/js-apis-data-distributedobject.md b/en/application-dev/reference/apis/js-apis-data-distributedobject.md index 6670e2eefaea1bd07d85083bf5436833613f998e..5ac7b6707c3afd30d7ccc6ae966fdf99439bd697 100644 --- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md +++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md @@ -1,6 +1,6 @@ # Distributed Data Object -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -26,7 +26,7 @@ Creates a distributed data object. | -------- | -------- | -------- | -------- | | source | object | Yes| Attribute of the distributed data object to create.| -**Return Value** +**Return value** | Type| Description| | -------- | -------- | | [DistributedObject](#distributedobject) | Distributed data object created.| @@ -34,7 +34,7 @@ Creates a distributed data object. **Example** ```js import distributedObject from '@ohos.data.distributedDataObject' - // Create a distributedObject instance. The attribute type of the object can be string, number, boolean, or Object. + // Create a distributed data object, which contains attributes of four types, namely, string, number, boolean, and object. var g_object = distributedObject.createDistributedObject({name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}}); ``` @@ -48,7 +48,7 @@ Creates a random session ID. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject -**Return Value** +**Return value** | Type| Description| | -------- | -------- | | string | Session ID created.| @@ -62,7 +62,7 @@ Creates a random session ID. ## DistributedObject -Represents a **distributedObject** instance. +Represents a distributed data object. ### setSessionId @@ -78,7 +78,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo | -------- | -------- | -------- | -------- | | sessionId | string | No| ID of a distributed data object on a trusted network. To remove a distributed data object from the network, set this parameter to "" or leave it empty.| -**Return Value** +**Return value** | Type| Description| | -------- | -------- | @@ -101,15 +101,15 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void -Subscribes to the data changes of this distributed data object. +Subscribes to the changes of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data change events.| - | callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback used to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the attributes of the distributed data object changed.| + | type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data changes.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | Yes| Callback used to return the changes of the distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** ```js @@ -130,15 +130,15 @@ Subscribes to the data changes of this distributed data object. off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void -Unsubscribes from the data changes of this distributed data object. +Unsubscribes from the changes of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to subscribe to. The value is **change**, which indicates data change events.| - | callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback used to return changes of the distributed data object. If this parameter is not specified, all callbacks related to data changes will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the attributes of the distributed data object changed.| + | type | string | Yes| Event type to unsubscribe from. The value is **change**, which indicates data changes.| + | callback | Callback<{ sessionId: string, fields: Array<string> }> | No| Callback used to return the changes of the distributed data object. If this parameter is not specified, this API unsubscribes from all callbacks for data changes of this distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**fields** indicates the changed attributes of the distributed data object.| **Example** @@ -149,11 +149,11 @@ Unsubscribes from the data changes of this distributed data object. g_object.on("change", function (sessionId, changeData) { console.info("change" + sessionId); }); - // Unsubscribe from the data change callback for the specified distributed data object. + // Unsubscribe from the specified data change callback for the distributed data object. g_object.off("change", function (sessionId, changeData) { console.info("change" + sessionId); }); - // Unsubscribe from all data change callbacks. + // Unsubscribe from all data change callbacks for the distributed data object. g_object.off("change"); ``` @@ -161,15 +161,15 @@ Unsubscribes from the data changes of this distributed data object. on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void -Subscribes to the status changes (online or offline) of this distributed data object. +Subscribes to the status change (online or offline) of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to subscribe to. The value is "status", which indicates the status (online or offline) change events.| - | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the online or offline status.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the network ID of the device.
**status** indicates the status, which can be online or offline.| + | type | string | Yes| Event type to subscribe to. The value is **status**, which indicates the change in the status (online or offline) of the distributed data object.| + | callback | Callback<{ sessionId: string, networkId: string, status: 'online' \| 'offline' }> | Yes| Callback used to return the status change.
**sessionId** indicates the session ID of the distributed data object.
**networkId** indicates the network ID of the device.
**status** indicates the status, which can be online or offline.| **Example** ```js @@ -186,15 +186,15 @@ Subscribes to the status changes (online or offline) of this distributed data ob off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, status: 'online' | 'offline' }>): void -Unsubscribes from the status (online or offline) changes of the distributed data object. +Unsubscribes from the status change (online or offline) of this distributed data object. **System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject **Parameters** | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | type | string | Yes| Event type to subscribe to. The value is "status", which indicates the status (online or offline) change events.| - | callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback used to return the status changes. If this parameter is not specified, all the status change callbacks will be unregistered.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the status, which can be online or offline.| + | type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the change in the status (online or offline) of the distributed data object.| + | callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback used to return the status change. If this parameter is not specified, this API unsubscribes from all callbacks of this distributed data object.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the status, which can be online or offline.| **Example** @@ -203,10 +203,10 @@ Unsubscribes from the status (online or offline) changes of the distributed data g_object.on("status", function (sessionId, networkId, status) { this.response += "status changed " + sessionId + " " + status + " " + networkId; }); - // Unsubscribe from the status change callback for the specified distributed data object. + // Unsubscribe from the specified status change callback for the distributed data object. g_object.off("status", function (sessionId, networkId, status) { this.response += "status changed " + sessionId + " " + status + " " + networkId; }); - // Unsubscribe from all status change callbacks. + // Unsubscribe from all status change callbacks for the distributed data object. g_object.off("status"); ``` diff --git a/en/application-dev/reference/apis/js-apis-data-preferences.md b/en/application-dev/reference/apis/js-apis-data-preferences.md index 791908e6c9a8e8509f364c587fa132958e475c31..9224a7ba33dfc51ca978a04b65e66e750d2110a1 100644 --- a/en/application-dev/reference/apis/js-apis-data-preferences.md +++ b/en/application-dev/reference/apis/js-apis-data-preferences.md @@ -1,6 +1,6 @@ # Preferences -Preferences provide capabilities for processing key-value (KV) data for applications and supports lightweight data persistence, modification, and query. Data is stored in KV pairs. Keys are of the string type, and values can be of the number, string, or Boolean type. +Preferences provide capabilities for processing data in the form of key-value (KV) pairs and supports lightweight data persistence, modification, and query. In KV pairs, keys are of the string type, and values can be of the number, string, or Boolean type. > ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
@@ -27,19 +27,19 @@ import data_preferences from '@ohos.data.preferences'; getPreferences(context: Context, name: string, callback: AsyncCallback<Preferences>): void -Reads a preference persistence file and loads data to the **Preferences** instance for data operations. This API uses an asynchronous callback to return the result. +Reads a **Preferences** persistence file and loads data to the **Preferences** instance for data operations. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| | name | string | Yes| Name of the **Preferences** instance persistence file.| - | callback | AsyncCallback<[Preferences](#preferences)> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<[Preferences](#preferences)> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -73,22 +73,22 @@ Reads a preference persistence file and loads data to the **Preferences** instan getPreferences(context: Context, name: string): Promise<Preferences> -Reads a preference persistence file and loads data to the **Preferences** instance for data operations. This API uses a promise to return the result. +Reads a **Preferences** persistence file and loads data to the **Preferences** instance for data operations. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| - | name | string | Yes| Name of the **Preferences** instance persistence file.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| + | name | string | Yes| Name of the** Preferences** instance persistence file.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<[Preferences](#preferences)> | Promise used to return the execution result.| + | Promise<[Preferences](#preferences)> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -122,18 +122,18 @@ Reads a preference persistence file and loads data to the **Preferences** instan deletePreferences(context: Context, name: string, callback: AsyncCallback<void>): void Deletes a **Preferences** singleton instance, the persistence file and backup file, and corrupted files from the memory. -Once a preference persistence file is deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the execution result. +Once a **Preferences** persistence file is deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| | name | string | Yes| Name of the **Preferences** instance persistence file.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -144,7 +144,7 @@ Once a preference persistence file is deleted, the **Preferences** instance cann console.info("Failed to delete data, err: " + err) return } - console.info("Deleted data successfully.") + console.info("Data deleted successfully.") }) } ``` @@ -155,22 +155,22 @@ Once a preference persistence file is deleted, the **Preferences** instance cann deletePreferences(context: Context, name: string): Promise<void> Deletes a **Preferences** singleton instance, the persistence file and backup file, and corrupted files from the memory. -Once a preference persistence file is deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the execution result. +Once a **Preferences** persistence file is deleted, the **Preferences** instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| - | name | string | Yes| Name of the **Preferences** instance persistence file.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| + | name | string | Yes| Name of the** Preferences** instance persistence file.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -178,7 +178,7 @@ Once a preference persistence file is deleted, the **Preferences** instance cann let promise = data_preferences.deletePreferences(this.context, 'mystore') promise.then(() => { - console.info("Deleted data successfully.") + console.info("Data deleted successfully.") }).catch((err) => { console.info("Failed to delete data, err: " + err) }) @@ -192,18 +192,18 @@ removePreferencesFromCache(context: Context, name: string, callback: AsyncCallba Removes a **Preferences** singleton instance from the memory. -When a **Preferences** singleton instance is removed, this instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the execution result. +When a **Preferences** singleton instance is removed, this instance cannot be used for data operations. Otherwise, data inconsistency will occur. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| - | name | string | Yes| Name of the **Preferences** instance persistence file.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| + | name | string | Yes| Name of the** Preferences** instance persistence file.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -230,18 +230,18 @@ When a **Preferences** singleton instance is removed, this instance cannot be us **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | context | [Context](js-apis-Context.md) | Yes| Context of the app or functionality.| - | name | string | Yes| Name of the **Preferences** instance persistence file.| + | context | [Context](js-apis-Context.md) | Yes| Context of the application or functionality.| + | name | string | Yes| Name of the** Preferences** instance persistence file.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -270,14 +270,14 @@ Obtains the value of a key. If the value is null or a non-default value, the def **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data to obtain. It cannot be empty.| | defValue | [ValueType](#valuetype) | Yes| Default value to be returned. It can be a number, string, or Boolean value.| - | callback | AsyncCallback<ValueType> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<ValueType> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -285,12 +285,12 @@ Obtains the value of a key. If the value is null or a non-default value, the def data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) { if (err) { - console.info("Get the preferences failed, err: " + err) + console.info("Failed to get the preferences, err: " + err) return } preferences.get('startup', 'default', function(err, value) { if (err) { - console.info("Get the value of startup failed, err: " + err) + console.info("Failed to get the value of startup, err: " + err) return } console.info("The value of startup is " + value) @@ -308,18 +308,18 @@ Obtains the value of a key. If the value is null or a non-default value, the def **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -- **Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data to obtain. It cannot be empty.| | defValue | [ValueType](#valuetype) | Yes| Default value to be returned. It can be a number, string, or Boolean value.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<ValueType> | Promise used to return the execution result.| + | Promise<ValueType> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -334,7 +334,7 @@ Obtains the value of a key. If the value is null or a non-default value, the def console.info("Failed to get the value of startup, err: " + err) }) }).catch((err) => { - console.info("Get the preferences failed, err: " + err) + console.info("Failed to get the preferences, err: " + err) }) } ``` @@ -344,18 +344,18 @@ Obtains the value of a key. If the value is null or a non-default value, the def put(key: string, value: ValueType, callback: AsyncCallback<void>): void -Obtains a **Preferences** instance, writes data to the **Preferences** instance, and saves the data to the file using **flush()** or **flushSync()**. This API uses an asynchronous callback to return the execution result. +Puts a new value to this **Preferences** instance and its persistence file. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| | value | [ValueType](#valuetype) | Yes| New value to store. It can be a number, string, or Boolean value.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -382,22 +382,22 @@ Obtains a **Preferences** instance, writes data to the **Preferences** instance, put(key: string, value: ValueType): Promise<void> -Obtains a **Preferences** instance, writes data to the **Preferences** instance, and saves the data to the file using **flush()** or **flushSync()**. This API uses a promise to return the execution result. +Puts a new value to this **Preferences** instance and its persistence file. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data. It cannot be empty.| | value | [ValueType](#valuetype) | Yes| New value to store. It can be a number, string, or Boolean value.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -412,7 +412,7 @@ Obtains a **Preferences** instance, writes data to the **Preferences** instance, console.info("Failed to put the value of startup, err: " + err) }) }).catch((err) => { - console.info("Get the preferences failed, err: " + err) + console.info("Failed to get the preferences, err: " + err) }) } ``` @@ -422,22 +422,22 @@ Obtains a **Preferences** instance, writes data to the **Preferences** instance, has(key: string, callback: AsyncCallback<boolean>): boolean -Checks whether the **Preferences** instance contains data with a given key. This API uses an asynchronous callback to return the result. +Checks whether this **Preferences** instance contains data with a given key. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data to check. It cannot be empty.| - | callback | AsyncCallback<boolean> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<boolean> | Yes| Callback used to return the result.| -**Return value** +- Return value | Type| Description| | -------- | -------- | | boolean | Returns **true** if the **Preferences** instance contains data with the specified key; returns **false** otherwise.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -468,21 +468,21 @@ Checks whether the **Preferences** instance contains data with a given key. This has(key: string): Promise<boolean> -Checks whether the **Preferences** instance contains data with a given key. This API uses a promise to return the result. +Checks whether this **Preferences** instance contains data with a given key. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the data to check. It cannot be empty.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<boolean> | Promise used to return the execution result.| + | Promise<boolean> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -501,7 +501,7 @@ Checks whether the **Preferences** instance contains data with a given key. This console.info("Check the key of startup failed, err: " + err) }) }).catch((err) => { - console.info("Get the preferences failed, err: " + err) + console.info("Failed to get the preferences, err: " + err) }) } ``` @@ -511,17 +511,17 @@ Checks whether the **Preferences** instance contains data with a given key. This delete(key: string, callback: AsyncCallback<void>): void -Deletes the KV pair of the specified key from this **Preferences** instance. This API uses an asynchronous callback to return the result. +Deletes a KV pair of the specified key from this **Preferences** instance. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the KV pair to delete. It cannot be empty.| - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -548,21 +548,21 @@ Deletes the KV pair of the specified key from this **Preferences** instance. Thi delete(key: string): Promise<void> -Deletes the KV pair of the specified key from this **Preferences** instance. This API uses a promise to return the result. +Deletes a KV pair of the specified key from this **Preferences** instance. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | | key | string | Yes| Key of the KV pair to delete. It cannot be empty.| -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -587,16 +587,16 @@ Deletes the KV pair of the specified key from this **Preferences** instance. Thi flush(callback: AsyncCallback<void>): void -Saves the modification to this **Preferences** instance and synchronizes the modification to the preference persistence file. This API uses an asynchronous callback to return the result. +Saves the modification to this **Preferences** instance and synchronizes the modification to the **Preferences** persistence file. This API uses an asynchronous callback to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -623,16 +623,16 @@ Saves the modification to this **Preferences** instance and synchronizes the mod flush(): Promise<void> -Saves the modification to this **Preferences** instance and synchronizes the modification to the preference persistence file. This API uses a promise to return the result. +Saves the modification to this **Preferences** instance and synchronizes the modification to the **Preferences** persistence file. This API uses a promise to return the result. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -661,12 +661,12 @@ Clears data of this **Preferences** instance. This API uses an asynchronous call **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Mandatory| Description| | -------- | -------- | -------- | -------- | - | callback | AsyncCallback<void> | Yes| Callback used to return the execution result.| + | callback | AsyncCallback<void> | Yes| Callback used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -697,12 +697,12 @@ Clears data of this **Preferences** instance. This API uses a promise to return **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Return value** +- Return value | Type| Description| | -------- | -------- | - | Promise<void> | Promise used to return the execution result.| + | Promise<void> | Promise used to return the result.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -731,13 +731,13 @@ Subscribes to data changes. When the value of the subscribed key changes, a call **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Description| | -------- | -------- | -------- | | type | string | Event type. The value **change** indicates data change events.| | callback | Callback<{ key : string }> | Callback used to return data changes.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences' @@ -779,13 +779,13 @@ Unsubscribes from data changes. **System capability**: SystemCapability.DistributedDataManager.Preferences.Core -**Parameters** +- Parameters | Name| Type| Description| | -------- | -------- | -------- | | type | string | Event type. The value **change** indicates data change events.| | callback | Callback<{ key : string }> | Callback used to return data changes.| -**Example** +- Example ```ts import Ability from '@ohos.application.Ability' import data_preferences from '@ohos.data.preferences'