mirror of
https://github.com/pebble-dev/clay.git
synced 2026-09-06 09:07:19 -04:00
Yell at developer if they try and use appKeys
This commit is contained in:
@@ -82,23 +82,50 @@ function Clay(config, customFn, options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* If this function returns true then the callback will be executed
|
||||||
|
* @callback _scanConfig_testFn
|
||||||
|
* @param {Clay~ConfigItem} item
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @callback _scanConfig_callback
|
||||||
|
* @param {Clay~ConfigItem} item
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scan over the config and run the callback if the testFn resolves to true
|
||||||
* @private
|
* @private
|
||||||
* @param {Clay~ConfigItem|Array} item
|
* @param {Clay~ConfigItem|Array} item
|
||||||
|
* @param {_scanConfig_testFn} testFn
|
||||||
|
* @param {_scanConfig_callback} callback
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
function _registerStandardComponents(item) {
|
function _scanConfig(item, testFn, callback) {
|
||||||
if (Array.isArray(item)) {
|
if (Array.isArray(item)) {
|
||||||
item.forEach(function(item) {
|
item.forEach(function(item) {
|
||||||
_registerStandardComponents(item);
|
_scanConfig(item, testFn, callback);
|
||||||
});
|
});
|
||||||
} else if (item.type === 'section') {
|
} else if (item.type === 'section') {
|
||||||
_registerStandardComponents(item.items);
|
_scanConfig(item.items, testFn, callback);
|
||||||
} else if (standardComponents[item.type]) {
|
} else if (testFn(item)) {
|
||||||
self.registerComponent(standardComponents[item.type]);
|
callback(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_registerStandardComponents(self.config);
|
// register standard components
|
||||||
|
_scanConfig(self.config, function(item) {
|
||||||
|
return standardComponents[item.type];
|
||||||
|
}, function(item) {
|
||||||
|
self.registerComponent(standardComponents[item.type]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// validate config against teh use of appKeys
|
||||||
|
_scanConfig(self.config, function(item) {
|
||||||
|
return item.appKey;
|
||||||
|
}, function() {
|
||||||
|
throw new Error('appKeys are no longer supported. ' +
|
||||||
|
'Please follow the migration guide to upgrade your project');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,6 +31,15 @@ describe('Clay', function() {
|
|||||||
}, /must be an Array/i);
|
}, /must be an Array/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws if the config contains appKeys', function() {
|
||||||
|
assert.throws(function() {
|
||||||
|
fixture.clay([
|
||||||
|
{type: 'input', appKey: 'foo'},
|
||||||
|
{type: 'someCustomComponent', appKey: 'bar'}
|
||||||
|
]);
|
||||||
|
}, /appKeys are no longer supported/i);
|
||||||
|
});
|
||||||
|
|
||||||
it('throws if customFn is not a function', function() {
|
it('throws if customFn is not a function', function() {
|
||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
fixture.clay([], {});
|
fixture.clay([], {});
|
||||||
|
|||||||
Reference in New Issue
Block a user