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 18b94e97c13d6191b5eb49de8254c9189ef3acbc..5985b348a595a9c73423c0d78a82376865effc91 100644
--- a/en/application-dev/reference/apis/js-apis-data-distributedobject.md
+++ b/en/application-dev/reference/apis/js-apis-data-distributedobject.md
@@ -2,7 +2,7 @@
The **distributedDataObject** module provides basic data object management, including creating, querying, deleting, modifying, and subscribing to data objects, and distributed data object collaboration for the same application among multiple devices.
-> **NOTE**
+> **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.
@@ -25,7 +25,7 @@ Creates a distributed data object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| context | Context | Yes| Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md).|
+| context | Context | Yes| Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md).|
| source | object | Yes| Attributes of the distributed data object.|
**Return value**
@@ -54,15 +54,15 @@ Stage model:
// Import the module.
import distributedObject from '@ohos.data.distributedDataObject';
import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
+
+let g_object = null;
+
class EntryAbility extends UIAbility {
onWindowStageCreate(windowStage){
- context = this.context
+ // Create a distributed data object, which has attributes of the string, number, boolean, and object types.
+ g_object = distributedObject.create(this.context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
}
}
-// Create a distributed data object, which contains attributes of the string, number, boolean, and object types.
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
```
## distributedObject.genSessionId
@@ -110,7 +110,7 @@ Called when the **revokeSave()** API is successfully called.
## DistributedObjectV9
-Represents a distributed data object.
+Provides APIs for managing a distributed data object. Before using any API of this class, use [create()](#distributedobjectcreate9) to create a distributed data object.
### setSessionId9+
@@ -131,7 +131,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Error codes**
- For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md).
+For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
@@ -139,35 +139,10 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{
- console.log("join session");
-});
-```
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-// Add g_object to the distributed network.
-g_object.setSessionId(distributedObject.genSessionId(), ()=>{
- console.log("join session");
+ console.info("join session");
});
```
@@ -189,7 +164,7 @@ Exits all joined sessions.
**Error codes**
- For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md).
+ For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
@@ -197,43 +172,14 @@ Exits all joined sessions.
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId(), ()=>{
- console.log("join session");
+ console.info("join session");
});
// Exit the distributed network.
g_object.setSessionId(() => {
- console.log("leave all lession.");
-});
-```
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-// Add g_object to the distributed network.
-g_object.setSessionId(distributedObject.genSessionId(), ()=>{
- console.log("join session");
-});
-// Exit the distributed network.
-g_object.setSessionId(() => {
- console.log("leave all lession.");
+ console.info("leave all lession.");
});
```
@@ -261,7 +207,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Error codes**
- For details about the error codes, see [Distributed Data Object Error Codes] (../errorcodes/errorcode-distributed-dataObject.md).
+ For details about the error codes, see [Distributed Data Object Error Codes](../errorcodes/errorcode-distributed-dataObject.md).
| ID| Error Message|
| -------- | -------- |
@@ -269,40 +215,7 @@ Sets a session ID for synchronization. Automatic synchronization is performed fo
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-// Add g_object to the distributed network.
-g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
- console.log("join session.");
- }).catch((error)=>{
- console.info("error:" + error.code + error.message);
-});
-// Exit the distributed network.
-g_object.setSessionId().then (()=>{
- console.log("leave all lession.");
- }).catch((error)=>{
- console.info("error:" + error.code + error.message);
-});
-```
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Add g_object to the distributed network.
g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
console.info("join session.");
@@ -311,7 +224,7 @@ g_object.setSessionId(distributedObject.genSessionId()).then (()=>{
});
// Exit the distributed network.
g_object.setSessionId().then (()=>{
- console.log("leave all lession.");
+ console.info("leave all lession.");
}).catch((error)=>{
console.info("error:" + error.code + error.message);
});
@@ -321,7 +234,7 @@ g_object.setSessionId().then (()=>{
on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<string> }>): void
-Subscribes to the data change of this distributed data object.
+Subscribes to data changes of this distributed data object.
**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject
@@ -334,38 +247,7 @@ Subscribes to the data change of this distributed data object.
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-globalThis.changeCallback = (sessionId, changeData) => {
- console.info("change" + sessionId);
- if (changeData != null && changeData != undefined) {
- changeData.forEach(element => {
- console.info("changed !" + element + " " + g_object[element]);
- });
- }
-}
-g_object.on("change", globalThis.changeCallback);
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.changeCallback = (sessionId, changeData) => {
console.info("change" + sessionId);
if (changeData != null && changeData != undefined) {
@@ -381,7 +263,7 @@ g_object.on("change", globalThis.changeCallback);
off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<string> }>): void
-Unsubscribes from the data change of this distributed data object.
+Unsubscribes from the data changes of this distributed data object.
**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject
@@ -395,33 +277,7 @@ Unsubscribes from the data change of this distributed data object.
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-// Unregister the specified data change callback.
-g_object.off("change", globalThis.changeCallback);
-// Unregister all data change callbacks.
-g_object.off("change");
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
// Unregister the specified data change callback.
g_object.off("change", globalThis.changeCallback);
// Unregister all data change callbacks.
@@ -432,7 +288,7 @@ g_object.off("change");
on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, status: 'online' | 'offline' }>): void
-Subscribes to the status change of this distributed data object.
+Subscribes to statue changes of this distributed data object.
**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject
@@ -445,36 +301,10 @@ Subscribes to the status change of this distributed data object.
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-g_object.on("status", globalThis.statusCallback);
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-globalThis.statusCallback = (sessionId, networkId, status) => {
- globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
g_object.on("status", globalThis.statusCallback);
```
@@ -496,40 +326,11 @@ Unsubscribes from the status change of this distributed data object.
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
globalThis.statusCallback = (sessionId, networkId, status) => {
globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
}
-// Unsubscribe from the specified status change callback for the distributed data object.
-g_object.off("status",globalThis.statusCallback);
-// Unregister all status change callbacks.
-g_object.off("status");
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false, parent:{mother:"jack mom",father:"jack Dad"}});
-globalThis.statusCallback = (sessionId, networkId, status) => {
- globalThis.response += "status changed " + sessionId + " " + status + " " + networkId;
-}
-// Unsubscribe from all status change callbacks for the distributed data object.
+// Unregister the specified status change callback.
g_object.off("status",globalThis.statusCallback);
// Unregister all status change callbacks.
g_object.off("status");
@@ -560,37 +361,10 @@ The saved data will be released in the following cases:
**Example**
-FA model:
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
-g_object.setSessionId("123456");
-g_object.save("local", (result) => {
- console.log("save callback");
- console.info("save sessionId: " + result.sessionId);
- console.info("save version: " + result.version);
- console.info("save deviceId: " + result.deviceId);
-});
-```
-
-Stage model:
```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local", (result) => {
- console.log("save callback");
+ console.info("save callback");
console.info("save sessionId: " + result.sessionId);
console.info("save version: " + result.version);
console.info("save deviceId: " + result.deviceId);
@@ -627,40 +401,10 @@ The saved data will be released in the following cases:
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context,{name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
g_object.save("local").then((result) => {
- console.log("save callback");
- console.info("save sessionId " + result.sessionId);
- console.info("save version " + result.version);
- console.info("save deviceId " + result.deviceId);
-}, () => {
- console.error("save failed");
-});
-```
-Stage model:
-
-```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context
- }
-}
-let g_object = distributedObject.create(context,{name:"Amy", age:18, isVis:false});
-g_object.setSessionId("123456");
-g_object.save("local").then((result) => {
- console.log("save callback");
+ console.info("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
@@ -673,7 +417,7 @@ g_object.save("local").then((result) => {
revokeSave(callback: AsyncCallback<RevokeSaveSuccessResponse>): void
-Revokes the saving operation of a distributed data object. This API uses an asynchronous callback to return the result.
+Revokes the saving operation of this distributed data object. This API uses an asynchronous callback to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted.
@@ -688,54 +432,19 @@ If the object is stored on another device, the data on the local device will be
**Example**
-FA model:
-
```js
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
-g_object.setSessionId("123456");
-// Save data for persistence.
-g_object.save("local", (result) => {
- console.log("save callback");
- console.info("save sessionId " + result.sessionId);
- console.info("save version " + result.version);
- console.info("save deviceId " + result.deviceId);
-});
-// Delete the persistence data.
-g_object.revokeSave((result) => {
- console.log("revokeSave callback");
- console.log("revokeSave sessionId " + result.sessionId);
-});
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
// Save data for persistence.
g_object.save("local", (result) => {
- console.log("save callback");
+ console.info("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
});
// Delete the persistence data.
g_object.revokeSave((result) => {
- console.log("revokeSave callback");
- console.log("revokeSave sessionId " + result.sessionId);
+ console.info("revokeSave callback");
+ console.info("revokeSave sessionId " + result.sessionId);
});
```
@@ -743,7 +452,7 @@ g_object.revokeSave((result) => {
revokeSave(): Promise<RevokeSaveSuccessResponse>
-Revokes the saving operation of a distributed data object. This API uses a promise to return the result.
+Revokes the saving operation of this distributed data object. This API uses a promise to return the result.
If the object is saved on the local device, the data saved on all trusted devices will be deleted.
If the object is stored on another device, the data on the local device will be deleted.
@@ -761,57 +470,20 @@ If the object is stored on another device, the data on the local device will be
FA model:
```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import featureAbility from '@ohos.ability.featureAbility';
-// Obtain the context.
-let context = featureAbility.getContext();
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
g_object.setSessionId("123456");
// Save data for persistence.
g_object.save("local").then((result) => {
- console.log("save callback");
- console.info("save sessionId " + result.sessionId);
- console.info("save version " + result.version);
- console.info("save deviceId " + result.deviceId);
-}, () => {
- console.error("save failed");
-});
-// Delete the persistence data.
-g_object.revokeSave().then((result) => {
- console.log("revokeSave callback");
- console.log("sessionId" + result.sessionId);
-}, () => {
- console.error("revokeSave failed");
-});
-```
-
-Stage model:
-
-```ts
-import distributedObject from '@ohos.data.distributedDataObject';
-import UIAbility from '@ohos.app.ability.UIAbility';
-// Obtain the context.
-let context;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage) {
- context = this.context
- }
-}
-let g_object = distributedObject.create(context, {name:"Amy", age:18, isVis:false});
-g_object.setSessionId("123456");
-g_object.save("local").then((result) => {
- console.log("save callback");
+ console.info("save callback");
console.info("save sessionId " + result.sessionId);
console.info("save version " + result.version);
console.info("save deviceId " + result.deviceId);
}, () => {
console.error("save failed");
});
-
// Delete the persistence data.
g_object.revokeSave().then((result) => {
- console.log("revokeSave callback");
- console.log("sessionId" + result.sessionId);
+ console.info("revokeSave callback");
+ console.info("sessionId" + result.sessionId);
}, () => {
console.error("revokeSave failed");
});
@@ -824,7 +496,7 @@ createDistributedObject(source: object): DistributedObject
Creates a distributed data object.
-> **NOTE**
+> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use **distributedObject.create**.
@@ -852,7 +524,7 @@ let g_object = distributedObject.createDistributedObject({name:"Amy", age:18, is
## DistributedObject(deprecated)
-Provides APIs for managing a distributed data object.
+Provides APIs for managing a distributed data object. Before using any API of this class, use [createDistributedObject()](#distributedobjectcreatedistributedobjectdeprecated) to create a **DistributedObject** object.
### setSessionId(deprecated)
@@ -860,7 +532,7 @@ setSessionId(sessionId?: string): boolean
Sets a session ID for synchronization. Automatic synchronization is performed for multiple devices with the same session ID on a trusted network.
-> **NOTE**
+> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [setSessionId](#setsessionid9).
@@ -897,7 +569,7 @@ on(type: 'change', callback: Callback<{ sessionId: string, fields: Array<stri
Subscribes to data changes of this distributed data object.
-> **NOTE**
+> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('change')](#onchange9).
@@ -932,7 +604,7 @@ off(type: 'change', callback?: Callback<{ sessionId: string, fields: Array<st
Unsubscribes from the data changes of this distributed data object.
-> **NOTE**
+> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('change')](#offchange9).
@@ -963,7 +635,7 @@ on(type: 'status', callback: Callback<{ sessionId: string, networkId: string, st
Subscribes to status changes of this distributed data object.
-> **NOTE**
+> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [on('status')](#onstatus9).
@@ -993,9 +665,9 @@ off(type: 'status', callback?: Callback<{ sessionId: string, deviceId: string, s
Unsubscribes from the status change of this distributed data object.
-> **NOTE**
+> **NOTE**
>
-> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('status')](#offstatus9) instead.
+> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [off('status')](#offstatus9).
**System capability**: SystemCapability.DistributedDataManager.DataObject.DistributedObject
@@ -1004,7 +676,7 @@ Unsubscribes from the status change of this distributed data object.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type to unsubscribe from. The value is **status**, which indicates the status change (online or offline) of the distributed data object. |
-| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object will be unsubscribed from.
**sessionId** indicates the session ID of the distributed data object.
**deviceId** indicates the device ID of the distributed data object.
**status** indicates the object status, which can be online or offline.|
+| callback | Callback<{ sessionId: string, deviceId: string, status: 'online' \| 'offline' }> | No| Callback for status changes. If this parameter is not specified, all status change callbacks of this distributed data object 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 object status, which can be online or offline.|
**Example**
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 b51525e00e7711641c1cc048bdce31565a5b81c4..de22c34d2a99d3e7391061cc9233089409944599 100644
--- a/en/application-dev/reference/apis/js-apis-data-preferences.md
+++ b/en/application-dev/reference/apis/js-apis-data-preferences.md
@@ -38,7 +38,7 @@ Obtains a **Preferences** instance. This API uses an asynchronous callback to re
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------------------ | ---- | ------------------------------------------------------------ |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance.|
| callback | AsyncCallback<[Preferences](#preferences)> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined** and **object** is the **Preferences** instance obtained. Otherwise, **err** is an error code.|
@@ -55,39 +55,39 @@ let preferences = null;
try {
data_preferences.getPreferences(context, 'mystore', function (err, val) {
if (err) {
- console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
return;
}
- console.info("Got the preferences successfully.");
+ preferences = val;
+ console.info("Obtained the preferences successfully.");
})
} catch (err) {
- console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
- }
-}
let preferences = null;
-try {
- data_preferences.getPreferences(context, 'mystore', function (err, val) {
- if (err) {
- console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
- return;
- }
- console.info("Got the preferences successfully.");
- })
-} catch (err) {
- console.info("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ try {
+ data_preferences.getPreferences(this.context, 'mystore', function (err, val) {
+ if (err) {
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
+ return;
+ }
+ preferences = val;
+ console.info("Obtained the preferences successfully.");
+ })
+ } catch (err) {
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
+ }
+ }
}
```
@@ -103,7 +103,7 @@ Obtains a **Preferences** instance. This API uses a promise to return the result
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance.|
**Return value**
@@ -126,38 +126,36 @@ try {
let promise = data_preferences.getPreferences(context, 'mystore');
promise.then((object) => {
preferences = object;
- console.info("Got the preferences successfully.");
+ console.info("Obtained the preferences successfully.");
}).catch((err) => {
- console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
- console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
}
```
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
- }
-}
let preferences = null;
-try {
- let promise = data_preferences.getPreferences(context, 'mystore');
- promise.then((object) => {
- preferences = object;
- console.info("Got the preferences successfully.");
- }).catch((err) => {
- console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
- })
-} catch(err) {
- console.log("Failed to get the preferences. code =" + err.code + ", message =" + err.message);
+
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ try {
+ let promise = data_preferences.getPreferences(this.context, 'mystore');
+ promise.then((object) => {
+ preferences = object;
+ console.info("Obtained the preferences successfully.");
+ }).catch((err) => {
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
+ })
+ } catch(err) {
+ console.info("Failed to obtain the preferences. code =" + err.code + ", message =" + err.message);
+ }
+ }
}
```
@@ -177,7 +175,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to delete. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
@@ -214,25 +212,22 @@ try {
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
- }
-}
-try {
- data_preferences.deletePreferences(context, 'mystore', function (err, val) {
- if (err) {
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ try {
+ data_preferences.deletePreferences(this.context, 'mystore', function (err, val) {
+ if (err) {
+ console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
+ return;
+ }
+ console.info("Deleted the preferences successfully." );
+ })
+ } catch (err) {
console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
- return;
}
- console.info("Deleted the preferences successfully." );
- })
-} catch (err) {
- console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
+ }
}
```
@@ -252,7 +247,7 @@ The deleted **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to delete.|
**Return value**
@@ -293,25 +288,22 @@ try {
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
+
class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
+ onWindowStageCreate(windowStage) {
+ try{
+ let promise = data_preferences.deletePreferences(this.context, 'mystore');
+ promise.then(() => {
+ console.info("Deleted the preferences successfully.");
+ }).catch((err) => {
+ console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
+ })
+ } catch(err) {
+ console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
+ }
}
}
-
-try{
- let promise = data_preferences.deletePreferences(context, 'mystore');
- promise.then(() => {
- console.info("Deleted the preferences successfully.");
- }).catch((err) => {
- console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
- })
-} catch(err) {
- console.info("Failed to delete the preferences. code =" + err.code + ", message =" + err.message);
-}
```
## data_preferences.removePreferencesFromCache
@@ -328,7 +320,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description |
| -------- | ------------------------------------- | ---- | ---------------------------------------------------- |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to remove. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the operation is successful, **err** is **undefined**. Otherwise, **err** is an error code.|
@@ -357,25 +349,22 @@ try {
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
-class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
- }
-}
-try {
- data_preferences.removePreferencesFromCache(context, 'mystore', function (err, val) {
- if (err) {
+class EntryAbility extends UIAbility {
+ onWindowStageCreate(windowStage) {
+ try {
+ data_preferences.removePreferencesFromCache(this.context, 'mystore', function (err, val) {
+ if (err) {
+ console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
+ return;
+ }
+ console.info("Removed the preferences successfully.");
+ })
+ } catch (err) {
console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
- return;
}
- console.info("Removed the preferences successfully.");
- })
-} catch (err) {
- console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
+ }
}
```
@@ -394,7 +383,7 @@ The removed **Preferences** instance cannot be used for data operations. Otherwi
| Name | Type | Mandatory| Description |
| ------- | ------------------------------------- | ---- | ----------------------- |
-| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-ability-context.md). |
+| context | Context | Yes | Application context.
For details about the application context of the FA model, see [Context](js-apis-inner-app-context.md).
For details about the application context of the stage model, see [Context](js-apis-inner-application-uiAbilityContext.md). |
| name | string | Yes | Name of the **Preferences** instance to remove.|
**Return value**
@@ -427,25 +416,22 @@ try {
Stage model:
```ts
-// Obtain the context.
import UIAbility from '@ohos.app.ability.UIAbility';
-let context = null;
+
class EntryAbility extends UIAbility {
- onWindowStageCreate(windowStage){
- context = this.context;
+ onWindowStageCreate(windowStage) {
+ try {
+ let promise = data_preferences.removePreferencesFromCache(this.context, 'mystore');
+ promise.then(() => {
+ console.info("Removed the preferences successfully.");
+ }).catch((err) => {
+ console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
+ })
+ } catch(err) {
+ console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
+ }
}
}
-
-try {
- let promise = data_preferences.removePreferencesFromCache(context, 'mystore');
- promise.then(() => {
- console.info("Removed the preferences successfully.");
- }).catch((err) => {
- console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
- })
-} catch(err) {
- console.info("Failed to remove the preferences. code =" + err.code + ", message =" + err.message);
-}
```
## Preferences
@@ -459,7 +445,7 @@ Before calling any method of **Preferences**, you must obtain a **Preferences**
get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void
-Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not the type of the default value, the default value is returned.
+Obtains the value of a key. This API uses an asynchronous callback to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
@@ -477,13 +463,13 @@ Obtains the value of a key. This API uses an asynchronous callback to return the
try {
preferences.get('startup', 'default', function (err, val) {
if (err) {
- console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
return;
}
console.info("Obtained the value of 'startup' successfully. val: " + val);
})
} catch (err) {
- console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
@@ -492,7 +478,7 @@ try {
get(key: string, defValue: ValueType): Promise<ValueType>
-Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not the type of the default value, the default value is returned.
+Obtains the value of a key. This API uses a promise to return the result. If the value is **null** or is not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
@@ -520,7 +506,7 @@ try {
console.info("Failed to get value of 'startup'. code =" + err.code + ", message =" + err.message);
})
} catch(err) {
- console.info("Failed to get the value of 'startup'. code =" + err.code + ", message =" + err.message);
+ console.info("Failed to obtain the value of 'startup'. code =" + err.code + ", message =" + err.message);
}
```
@@ -794,10 +780,10 @@ try {
promise.then(() => {
console.info("Deleted the key 'startup'.");
}).catch((err) => {
- console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
+ console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
})
} catch(err) {
- console.log("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
+ console.info("Failed to delete the key 'startup'. code =" + err.code +", message =" + err.message);
}
```
@@ -945,7 +931,7 @@ Subscribes to data changes. A callback will be triggered to return the new value
try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) {
- console.info("Failed to get the preferences.");
+ console.info("Failed to obtain the preferences.");
return;
}
let observer = function (key) {
@@ -987,7 +973,7 @@ Unsubscribes from data changes.
| Name | Type | Mandatory| Description |
| -------- | -------------------------------- | ---- | ------------------------------------------ |
| type | string | Yes | Event type to unsubscribe from. The value **change** indicates data change events. |
-| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, all callbacks for data changes will be unregistered. |
+| callback | Callback<{ key : string }> | No | Callback to unregister. If this parameter is left blank, the callbacks used to subscribing to all data changes will be unregistered.|
**Example**
@@ -995,7 +981,7 @@ Unsubscribes from data changes.
try {
data_preferences.getPreferences(this.context, 'mystore', function (err, preferences) {
if (err) {
- console.info("Failed to get the preferences.");
+ console.info("Failed to obtain the preferences.");
return;
}
let observer = function (key) {
diff --git a/en/application-dev/reference/apis/js-apis-data-storage.md b/en/application-dev/reference/apis/js-apis-data-storage.md
index 8df3ab1e84ff92e39f31566416a34c4ffb3afa9b..75e9293eadcd0a25fc923146b92246a885829df6 100644
--- a/en/application-dev/reference/apis/js-apis-data-storage.md
+++ b/en/application-dev/reference/apis/js-apis-data-storage.md
@@ -1,4 +1,4 @@
-# @ohos.data.storage
+# @ohos.data.storage (Lightweight Data Storage)
The **DataStorage** module provides applications with data processing capability and allows applications to perform lightweight data storage and query. Data is stored in key-value (KV) pairs. Keys are of the string type, and values can be of the number, string, or Boolean type.
@@ -367,7 +367,7 @@ Provides APIs for obtaining and modifying storage data.
getSync(key: string, defValue: ValueType): ValueType
-Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned.
+Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
@@ -396,7 +396,7 @@ console.info("The value of startup is " + value);
get(key: string, defValue: ValueType, callback: AsyncCallback<ValueType>): void
-Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses an asynchronous callback to return the result.
+Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
@@ -425,7 +425,7 @@ storage.get('startup', 'default', function(err, value) {
get(key: string, defValue: ValueType): Promise<ValueType>
-Obtains the value corresponding to a key. If the value is null or not in the default value format, the default value is returned. This API uses a promise to return the result.
+Obtains the value corresponding to a key. If the value is null or not of the default value type, **defValue** is returned. This API uses a promise to return the result.
**System capability**: SystemCapability.DistributedDataManager.Preferences.Core
diff --git a/en/application-dev/reference/apis/js-apis-permissionrequestresult.md b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md
index ba926d9a609f934611ef42eab0bfa4f26420b2fe..a26078b7435fadd2599f531612025511b6e63b60 100644
--- a/en/application-dev/reference/apis/js-apis-permissionrequestresult.md
+++ b/en/application-dev/reference/apis/js-apis-permissionrequestresult.md
@@ -14,7 +14,7 @@ The **PermissionRequestResult** module defines the result of a permission reques
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| permissions | Array<string> | Yes| No| Permissions requested.|
-| authResults | Array<number> | Yes| No|Resule of the permission Request.
**-1**: The permission has been set and no dialog box will be displayed. Users can modify the permission in **Settings**.
**0**: No operation is required.
**1**: Dynamic user authorization is required via a dialog window .
**2**: The request is invalid. Possible causes are as follows:
- The permission is not declared in the configuration file.
- The permission name is invalid.
- Special conditions for applying for the permission do not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).|
+| authResults | Array<number> | Yes| No|Result of the permission Request.
**-1**: The permission has been set and no dialog box will be displayed. Users can modify the permission in **Settings**.
**0**: No operation is required.
**1**: Dynamic user authorization is required via a dialog window .
**2**: The request is invalid. Possible causes are as follows:
- The permission is not declared in the configuration file.
- The permission name is invalid.
- Special conditions for applying for the permission do not satisfied. See [ohos.permission.LOCATION](../../security/permission-list.md#ohospermissionlocation) and [ohos.permission.APPROXIMATELY_LOCATION](../../security/permission-list.md#ohospermissionapproximately_location).|
## Usage