-
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 onekey
is supplied, then the keys will be tried in succession. The first non-undefined
value will be returned, orundefined
if nothing was found. -
preferences.put(string key, any value)
. Thevalue
needs 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 thekey
from 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.js
Environment.qa.js
Environment.prod.js
Environment.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"}]
}
}
}
};