minified does not work in the emulator or iOS so move settings iteration to utils.prepareSettingsForAppMessage()

This commit is contained in:
Keegan
2016-03-09 12:24:29 +11:00
parent 34d83de59e
commit 37c64a6e05
4 changed files with 45 additions and 50 deletions
+2 -8
View File
@@ -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);
};
/**
+15
View File
@@ -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;
};
+2 -42
View File
@@ -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.
* <pre>
* var r = _.mapObj({a: 1, b: 5, c: 2}, function(key, value) {
* return value + 1;
* });
* // r is now {a: 2, b: 6, c: 2}
* </pre>
*
* @param obj the object to use
* @param callback The callback <code>function(key, value)</code> to invoke for each property.
* <dl><dt>key</dt><dd>The name of the current property.</dd>
* <dt>value</dt><dd>The value of the current property.</dd>
* <dt class="this">this</dt><dd>The given context. If not set, the object itself.</dd>
* <dt class="returnValue">(callback return value)</dt><dd>This value will replace the original value in the new object.</dd></dl>
* @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
+26
View File
@@ -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);
});
});
});