console.info("Failed to get the value of 'startup'. Cause: "+err);
console.info("Failed to get the value of 'startup'. Cause: "+err);
})
})
}).catch((err)=>{
console.info("Failed to get the preferences.")
});
```
```
5. Store data persistently.
5. Store data persistently.
...
@@ -161,11 +167,12 @@ Use the following APIs to delete a **Preferences** instance or data file.
...
@@ -161,11 +167,12 @@ Use the following APIs to delete a **Preferences** instance or data file.
Specify an observer as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and saved by **flush()**, the observer callback will be invoked to return the new data.
Specify an observer as the callback to subscribe to data changes for an application. When the value of the subscribed key is changed and saved by **flush()**, the observer callback will be invoked to return the new data.
```js
```js
varobserver=function(key){
letobserver=function(key){
console.info("The key"+key+" changed.");
console.info("The key"+key+" changed.");
}
}
preferences.on('change',observer);
preferences.on('change',observer);
preferences.put('startup','auto',function(err){
// The data is changed from 'auto' to 'manual'.
preferences.put('startup','manual',function(err){
if(err){
if(err){
console.info("Failed to put the value of 'startup'. Cause: "+err);
console.info("Failed to put the value of 'startup'. Cause: "+err);