-
Notifications
You must be signed in to change notification settings - Fork 22
app preferences API
jhugman edited this page May 25, 2012
·
2 revisions
A persistent key value storage for scalar values.
This requires a module called Environment to be declared somewhere in your app.
var preferences = require("app-preferences");
preferences.put("latestSuccessfulCheckedAt", Date.now());
preferences.put("latestIdRead", lastId);
preferences.remove("lastError");
// go to native
preferences.commit();var preferences = require("app-preferences");
var url = preferences.get("serverUrl");-
preferences.get(string key...). Returns a value associated with thatkey. If more than onekeyis supplied, then the keys will be tried in succession. The first non-undefinedvalue will be returned, orundefinedif nothing was found. -
preferences.put(string key, any value). Thevalueneeds to be simple type that can be easily serialized – i.e.numbers,strings,booleans. Changes need to be committed to become persistent. -
preferences.remove(key). Remove thekeyfrom store. Changes need to be committed to become persistent.
Build time file selection may be used to good effect to create configurations dependent on built type. e.g.:
Environment.dev.jsEnvironment.qa.jsEnvironment.prod.jsEnvironment.android.prod.js
extension name: "app-preferences"
synonyms: "Settings"
implemented in: kirin-core
api-status: mature
implementations: android, ios
module.exports = {
namespace: "com.futureplatforms.kirin.extensions.preferences",
classes: {
"Settings": {
implementedBy: "javascript",
docs: "mergeOrOverwrite and resetEnviroment is called at onLoad() time",
methods: {
mergeOrOverwrite: [{latestNativePreferences : "object"}],
resetEnvironment: []
}
},
"SettingsBackend": {
implementedBy: "native",
docs: "Called in response to a settings.commit()",
methods: {
"writeStoreWithContents:andDeletes:": [{contents: "object"}, {deletes: "array"}]
}
}
}
};