提交 edafd617 编写于 作者: Z zuojiangjiang

fix example code

Signed-off-by: Nzuojiangjiang <zuojiangjiang@huawei.com>
上级 30b36374
...@@ -2448,12 +2448,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void ...@@ -2448,12 +2448,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
### off('syncComplete')<sup>9+</sup> ### off('syncComplete')<sup>9+</sup>
...@@ -2475,14 +2484,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]& ...@@ -2475,14 +2484,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
...@@ -4098,14 +4113,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]& ...@@ -4098,14 +4113,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
...@@ -4154,12 +4175,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void ...@@ -4154,12 +4175,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
### sync<sup>7+</sup> ### sync<sup>7+</sup>
...@@ -5593,14 +5623,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]& ...@@ -5593,14 +5623,20 @@ off(event: 'syncComplete', syncCallback?: Callback&lt;Array&lt;[string, number]&
```js ```js
let kvStore; let kvStore;
try { class KvstoreModel {
const func = function (data) { call(data) {
console.log('syncComplete ' + data) console.log("syncComplete: " + data);
}; }
kvStore.on('syncComplete', func); subscribeSyncComplete() {
kvStore.off('syncComplete', func); if (kvStore != null) {
}catch(e) { kvStore.on('syncComplete', this.call);
console.log('syncComplete e ' + e); }
}
unsubscribeSyncComplete() {
if (kvStore != null) {
kvStore.off('syncComplete', this.call);
}
}
} }
``` ```
...@@ -5649,12 +5685,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void ...@@ -5649,12 +5685,21 @@ off(event:'dataChange', listener?: Callback&lt;ChangeNotification&gt;): void
```js ```js
let kvStore; let kvStore;
kvStore.on('dataChange', function (data) { class KvstoreModel {
console.log("callback call data: " + data); call(data) {
}); console.log("dataChange: " + data);
kvStore.off('dataChange', function (data) { }
console.log("callback call data: " + data); subscribeDataChange() {
}); if (kvStore != null) {
kvStore.on('dataChange', distributedData.SubscribeType.SUBSCRIBE_TYPE_REMOTE, this.call);
}
}
unsubscribeDataChange() {
if (kvStore != null) {
kvStore.off('dataChange', this.call);
}
}
}
``` ```
## SyncMode ## SyncMode
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册