Persistent session variables for maintaining an application state inbetween user sessions. I'm using this for a mobile app so that I can record a user's application state and restore it when the user reloads the page, closes the app, etc.
Install with component(1):
$ component install bmcmahen/session-variables
Create a new session variables instance.
Set a key to a value, emitting a change:key
event. Options: { silent: true}
to silence emitter events and { noStore: true }
to avoid using localstorage for that particular setter.
Return the current value of the key.
Unset a key, emitting a change:key
event.
Clear all of the current session variables.
Sets the key to value, only if that key has not been set. This is useful when restoring an application state from localstorage. Options are the same as for set
.
Retrieves all values from localstorage, and populates your session variables.
var Session = require('session-variables');
var session = new Session();
session.on('change:layout', function(value, previousValue){
// render my layout.
});
session.setDefault('layout', 'browse');
MIT