Renamed ClayConfig.getSettings() to ClayConfig.serialize()

This commit is contained in:
Keegan
2016-03-10 21:00:44 +11:00
parent 0873f5eba2
commit 1142d1adee
4 changed files with 12 additions and 12 deletions
+2 -2
View File
@@ -523,7 +523,7 @@ Eg: If you run the `.show()` manipulator on an item that is already visible, the
| Method | Returns | Event Fired | Description | | Method | Returns | Event Fired | Description |
|--------|---------|-------------| ------------| |--------|---------|-------------| ------------|
| `.set( [boolean\|int] value)` | `ClayItem` | `change` | Check/uncheck the state of this item. | | `.set( [boolean\|int] value)` | `ClayItem` | `change` | Check/uncheck the state of this item. |
| `.get()` | `boolean` | | `true` if checked, `false` if not. **NOTE** this will be converted to a `1` or `0` when sent to the watch. See [`ClayConfig.getSettings()`](#methods) | | `.get()` | `boolean` | | `true` if checked, `false` if not. **NOTE** this will be converted to a `1` or `0` when sent to the watch. See [`Clay.getSettings()`](#methods) |
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. | | `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. |
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. | | `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. |
| `.hide()` | `ClayItem` | `hide` | Hides the item | | `.hide()` | `ClayItem` | `hide` | Hides the item |
@@ -556,7 +556,7 @@ Eg: If you run the `.show()` manipulator on an item that is already visible, the
| Method | Returns | Event Fired | Description | | Method | Returns | Event Fired | Description |
|--------|---------|-------------| ------------| |--------|---------|-------------| ------------|
| `.set( [array] value)` | `ClayItem` | `change` | Checks the checkboxes that corresponds to the provided list of values. | | `.set( [array] value)` | `ClayItem` | `change` | Checks the checkboxes that corresponds to the provided list of values. |
| `.get()` | `Array.<string>` | | Gets an array of strings representing the list of the values of the checked items. **NOTE:** each item in the array will be separated by a zero when sent to the watch. See [`ClayConfig.getSettings()`](#methods) | | `.get()` | `Array.<string>` | | Gets an array of strings representing the list of the values of the checked items. **NOTE:** each item in the array will be separated by a zero when sent to the watch. See [`Clay.getSettings()`](#methods) |
| `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. | | `.disable()` | `ClayItem` | `disabled` | Prevents this item from being edited by the user. |
| `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. | | `.enable()` | `ClayItem` | `enabled` | Allows this item to be edited by the user. |
| `.hide()` | `ClayItem` | `hide` | Hides the item | | `.hide()` | `ClayItem` | `hide` | Hides the item |
+1 -1
View File
@@ -28,7 +28,7 @@ var clayConfig = new ClayConfig(settings, config, $mainForm, clayMeta);
$mainForm.on('submit', function() { $mainForm.on('submit', function() {
// Set the return URL depending on the runtime environment // Set the return URL depending on the runtime environment
location.href = returnTo + location.href = returnTo +
encodeURIComponent(JSON.stringify(clayConfig.getSettings())); encodeURIComponent(JSON.stringify(clayConfig.serialize()));
}); });
// Run the custom function in the context of the ClayConfig // Run the custom function in the context of the ClayConfig
+2 -2
View File
@@ -155,8 +155,8 @@ function ClayConfig(settings, config, $rootContainer, meta) {
/** /**
* @returns {Object} * @returns {Object}
*/ */
self.getSettings = function() { self.serialize = function() {
_checkBuilt('getSettings'); _checkBuilt('serialize');
_.eachObj(_itemsByAppKey, function(appKey, item) { _.eachObj(_itemsByAppKey, function(appKey, item) {
_settings[appKey] = item.get(); _settings[appKey] = item.get();
}); });
+7 -7
View File
@@ -15,7 +15,7 @@ describe('ClayConfig', function() {
'getItemByAppKey', 'getItemByAppKey',
'getItemById', 'getItemById',
'getItemsByType', 'getItemsByType',
'getSettings', 'serialize',
'registerComponent', 'registerComponent',
'build', 'build',
'on', 'on',
@@ -39,7 +39,7 @@ describe('ClayConfig', function() {
'getItemByAppKey', 'getItemByAppKey',
'getItemById', 'getItemById',
'getItemsByType', 'getItemsByType',
'getSettings' 'serialize'
].forEach(function(method) { ].forEach(function(method) {
it('.' + method + '()', function() { it('.' + method + '()', function() {
var clayConfig = fixtures.clayConfig(['input', 'text'], false); var clayConfig = fixtures.clayConfig(['input', 'text'], false);
@@ -99,7 +99,7 @@ describe('ClayConfig', function() {
}); });
}); });
describe('.getSettings()', function() { describe('.serialize()', function() {
it('returns the correct settings', function() { it('returns the correct settings', function() {
var config = [ var config = [
{type: 'input', appKey: 'test1', defaultValue: 'default val'}, {type: 'input', appKey: 'test1', defaultValue: 'default val'},
@@ -120,7 +120,7 @@ describe('ClayConfig', function() {
var clayConfig = fixtures.clayConfig(config, true, true, settings); var clayConfig = fixtures.clayConfig(config, true, true, settings);
assert.deepEqual(clayConfig.getSettings(), { assert.deepEqual(clayConfig.serialize(), {
test1: 'default val', test1: 'default val',
test2: 'val-2', test2: 'val-2',
test3: false, test3: false,
@@ -131,17 +131,17 @@ describe('ClayConfig', function() {
clayConfig.getItemByAppKey('test3').set(true); clayConfig.getItemByAppKey('test3').set(true);
clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']); clayConfig.getItemByAppKey('test4').set(['cb-1', 'cb-3']);
assert.deepEqual(clayConfig.getSettings(), { assert.deepEqual(clayConfig.serialize(), {
test1: 'val-1', test1: 'val-1',
test2: 'val-2', test2: 'val-2',
test3: true, test3: true,
test4: ['cb-1', 'cb-3'] test4: ['cb-1', 'cb-3']
}); });
// make sure the result of getSettings() can actually be fed back in to // make sure the result of serialize() can actually be fed back in to
// a new instance of ClayConfig // a new instance of ClayConfig
assert.doesNotThrow(function() { assert.doesNotThrow(function() {
settings = clayConfig.getSettings(); settings = clayConfig.serialize();
fixtures.clayConfig(config, true, true, settings); fixtures.clayConfig(config, true, true, settings);
}); });
}); });