Skip to content

Commit

Permalink
check parameters of milo.createComponentClass
Browse files Browse the repository at this point in the history
  • Loading branch information
epoberezkin committed Mar 2, 2015
1 parent 7d1cb37 commit ec1311f
Show file tree
Hide file tree
Showing 3 changed files with 620 additions and 610 deletions.
25 changes: 15 additions & 10 deletions lib/util/create_component_class.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
'use strict';

var _ = require('milo-core').proto;
var miloCore = require('milo-core')
, _ = miloCore.proto
, check = miloCore.util.check
, Match = check.Match
, componentRegistry = require('../components/c_registry');


module.exports = createComponentClass;
Expand All @@ -16,23 +20,24 @@ module.exports = createComponentClass;
* @param {object=} config.staticMethods - Static methods of the new component (Hash of function name {string} to function {function})
*/
function createComponentClass(config) {
var componentRegistry = milo.registry.components;
check(config, {
superClassName: Match.Optional(String),
className: String,
facets: Match.Optional(Object),
methods: Match.Optional(Match.ObjectHash(Function)),
staticMethods: Match.Optional(Match.ObjectHash(Function)),
});
var SuperClass = componentRegistry.get(config.superClassName || 'Component');
var ComponentClass = SuperClass.createComponentClass(config.className, config.facets);

if(config.methods) {
_.extendProto(ComponentClass, config.methods);
}

if(config.staticMethods) {
if(config.staticMethods.super !== undefined) throw '\'super\' is a reserved keyword';
if (config.methods) _.extendProto(ComponentClass, config.methods);

if (config.staticMethods) {
if (config.staticMethods.super !== undefined) throw '\'super\' is a reserved keyword';
_.extend(ComponentClass, config.staticMethods);
}

ComponentClass.super = SuperClass.prototype;

componentRegistry.add(ComponentClass);

return ComponentClass;
}
Loading

0 comments on commit ec1311f

Please sign in to comment.