Question

I am new to enyo. I want to save a state of variable (which is boolean) while app executes. Then exit the app. After that I want to get the state (true/false) of the variable when app re-opens. How to save and restore the data in enyo?

Was it helpful?

Solution

I would use localStorage (API Docs here) to save your state every time the change in state occurs in your application:

myStateChange: function() {
    localStorage.myState = this.myState;
}

Note: to ensure that myStateChange is called every time you set it elsewhere, use this.set() method to set it, not this.myState = newValue;.

Then, in rendered() or create() method I would restore that state from localStorage.

rendered: function() {
    this.inherited(arguments);           // Call base rendered method
    this.myState = localStorage.myState; // Restore your saved value from localStorage
}

OTHER TIPS

There are no special hooks for data storage but it's very easy to tie into the native data storage options available for your platform. You might take a look at these options:

http://dev.opera.com/articles/view/taking-your-web-apps-offline-web-storage-appcache-websql/

http://docs.phonegap.com/en/1.0.0/phonegap_storage_storage.md.html

If you're using enyo.Collection you can get the records from it with collection.raw() and then use JSON.stringify() to get something you can put into localStorage.

You could even use cookies. Hope that gives you some places to start looking from.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top