Add developers to send arbitrary data to the config page

This commit is contained in:
Keegan
2016-03-11 03:36:00 +11:00
parent b1a6f184ba
commit e5496c62d6
6 changed files with 77 additions and 51 deletions
+19 -15
View File
@@ -11,8 +11,10 @@ var deepcopy = require('deepcopy/build/deepcopy.min');
* @param {function} [customFn] - Custom code to run from the config page. Will run
* with the ClayConfig instance as context
* @param {Object} [options] - Additional options to pass to Clay
* @param {boolean} [options.autoHandleEvents] - If false, Clay will not
* @param {boolean} [options.autoHandleEvents=true] - If false, Clay will not
* automatically handle the 'showConfiguration' and 'webviewclosed' events
* @param {*} [options.userData={}] - Arbitrary data to pass to the config page. Will
* be available os `clayConfig.meta.userData`
* @constructor
*/
function Clay(config, customFn, options) {
@@ -34,9 +36,24 @@ function Clay(config, customFn, options) {
self.meta = {
activeWatchInfo: null,
accountToken: '',
watchToken: ''
watchToken: '',
userData: {}
};
/**
* Populate the meta with data from the Pebble object. Make sure to run this inside
* either the "showConfiguration" or "ready" event handler
* @return {void}
*/
function _populateMeta() {
self.meta = {
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
accountToken: Pebble.getAccountToken(),
watchToken: Pebble.getWatchToken(),
userData: deepcopy(options.userData || {})
};
}
// Let Clay handle all the magic
if (options.autoHandleEvents !== false && typeof Pebble !== 'undefined') {
@@ -63,19 +80,6 @@ function Clay(config, customFn, options) {
});
}
/**
* Populate the meta with data from the Pebble object. Make sure to run this inside
* either the "showConfiguration" or "ready" event handler
* @return {void}
*/
function _populateMeta() {
self.meta = {
activeWatchInfo: Pebble.getActiveWatchInfo && Pebble.getActiveWatchInfo(),
accountToken: Pebble.getAccountToken(),
watchToken: Pebble.getWatchToken()
};
}
/**
* @private
* @param {Clay~ConfigItem|Array} item