diff --git a/index.js b/index.js index 587b14a..a77ec45 100755 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ var configPageHtml = require('./tmp/config-page.html'); var toSource = require('tosource'); var standardComponents = require('./src/scripts/components'); var utils = require('./src/scripts/lib/utils'); -var _ = require('./src/scripts/vendor/minified')._; + /** * @param {Array} config - the Clay config * @param {function} [customFn] - Custom code to run from the config page. Will run @@ -165,13 +165,7 @@ Clay.prototype.getSettings = function(response, convert) { localStorage.setItem('clay-settings', JSON.stringify(settings)); - if (convert === false) { - return settings; - } else { - return _.mapObj(settings, function(key, value) { - return utils.prepareForAppMessage(value); - }); - } + return convert === false ? settings : utils.prepareSettingsForAppMessage(settings); }; /** diff --git a/src/scripts/lib/utils.js b/src/scripts/lib/utils.js index 46ca729..156a3c4 100644 --- a/src/scripts/lib/utils.js +++ b/src/scripts/lib/utils.js @@ -53,3 +53,18 @@ module.exports.prepareForAppMessage = function(val) { return result; }; + +/** + * Converts a Clay settings dict into one that is compatible with + * Pebble.sendAppMessage(); + * @see {prepareForAppMessage} + * @param {Object} settings + * @returns {{}} + */ +module.exports.prepareSettingsForAppMessage = function(settings) { + var result = {}; + Object.keys(settings).forEach(function(key) { + result[key] = module.exports.prepareForAppMessage(settings[key]); + }); + return result; +}; diff --git a/src/scripts/vendor/minified.js b/src/scripts/vendor/minified.js index bfb2cd8..a9816fb 100644 --- a/src/scripts/vendor/minified.js +++ b/src/scripts/vendor/minified.js @@ -1,8 +1,8 @@ // minified.js config start -- use this comment to re-create a configuration in the Builder // - Only sections add, always, amdsupport, copyobj, dollardollar, // - each, eachobj, equals, error, extend, find, format, formathtml, get, ht, -// - html, isobject, mapobj, off, on, ready, request, select, set, template, -// - trigger, underscore, wait. +// - html, isobject, off, on, ready, request, select, set, template, trigger, +// - underscore, wait. // WARNING! This file is autogenerated from minified-master.js and others. @@ -2774,46 +2774,6 @@ define('minified', function() { */ 'eachObj': eachObj, - /*$ - * @id mapobj - * @group OBJECT - * @requires - * @configurable default - * @name _.mapObj() - * @syntax _.mapObj(obj, callback) - * @syntax _.mapObj(obj, callback, ctx) - * @module UTIL - * Creates a new object with the same properties but different values using the given callback function. The function is called - * for each property of the input object to provice a new value for the property. - * - * @example Increases the values of all properties. - *
-     * var r = _.mapObj({a: 1, b: 5, c: 2}, function(key, value) {
-     *     return value + 1;
-     * });
-     * // r is now {a: 2, b: 6, c: 2}
-     * 
- * - * @param obj the object to use - * @param callback The callback function(key, value) to invoke for each property. - *
key
The name of the current property.
- *
value
The value of the current property.
- *
this
The given context. If not set, the object itself.
- *
(callback return value)
This value will replace the original value in the new object.
- * @param ctx optional a context to pass to the callback as 'this'. - * @return the new object - * - * @see ##_.filterObj() filters an object. - * @see ##map() maps a list. - */ - 'mapObj': function(obj, mapFunc, ctx) { - var result = {}; - eachObj(obj, function(key, value) { - result[key] = mapFunc.call(ctx || obj, key, value); - }); - return result; - }, - /*$ * @id isobject * @group TYPE diff --git a/test/spec/lib/utils.js b/test/spec/lib/utils.js index bf0bf5a..22127e9 100644 --- a/test/spec/lib/utils.js +++ b/test/spec/lib/utils.js @@ -56,4 +56,30 @@ describe('Utils', function() { assert.strictEqual(utils.prepareForAppMessage(123), 123); }); }); + + describe('.prepareSettingsForAppMessage', function() { + it('converts the settings correctly', function() { + var settings = { + test1: false, + test2: 'val-2', + test3: true, + test4: ['cb-1', 'cb-3'], + test5: 12345, + test6: [1, 2, 3, 4], + test7: [true, false, true] + }; + var expected = { + test1: 0, + test2: 'val-2', + test3: 1, + test4: ['cb-1', 0, 'cb-3', 0], + test5: 12345, + test6: [1, 2, 3, 4], + test7: [1, 0, 1] + }; + + assert.deepEqual(utils.prepareSettingsForAppMessage(settings), expected); + }); + }); }); +