Skip to content

Commit

Permalink
feat(config-field): Connect and use utils/get-type, so add object-def…
Browse files Browse the repository at this point in the history
…ined type.
  • Loading branch information
CheerlessCloud committed Aug 14, 2017
1 parent 83fe99d commit 0e72e74
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions src/config-field.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Types from './types';
import getType from './utils/get-type';

/**
* @public
Expand Down Expand Up @@ -45,25 +45,10 @@ class ConfigField {
this.required = ((this.default === null || this.default === undefined) &&
(config.required === null || config.required === undefined || config.required === true));

// eslint-disable-next-line import/no-named-as-default-member
if (config.type instanceof Types.ConfigFieldBaseType) {
/**
* @type {ConfigFieldBaseType}
*/
this.type = config.type;
} else if (typeof config.type === 'string') {
const typeName = `${config.type[0].toUpperCase()}${config.type.toLowerCase().slice(1)}Type`;
const CurrentType = Types[typeName];

if (!CurrentType) {
throw new TypeError(`Can't find type ${config.type} (as ${typeName})`);
}

this.type = new CurrentType(config);
} else {
throw new Error('Type of field must be string or object extend from base ConfigFieldType');
}

/**
* @type {ConfigFieldBaseType}
*/
this.type = getType(config);

/**
* @type {{ pre: function[], post: function[] }}
Expand Down

0 comments on commit 0e72e74

Please sign in to comment.