refactor: type liberalism

This commit is contained in:
cha0s 2020-06-25 09:53:27 -05:00
parent 83ca91d3b8
commit 65a21b6718

View File

@ -82,15 +82,15 @@ export function description(type, instance) {
const allTypes = types();
const defaults = {
children: {},
type,
};
const splitTypes = type.split('|');
for (let i = 0; i < splitTypes.length; i++) {
const type = splitTypes[i];
if (allTypes[type]) {
const splitType = splitTypes[i];
if (allTypes[splitType]) {
return {
...defaults,
...('function' === typeof allTypes[type] ? allTypes[type](instance) : allTypes[type])
type: splitType,
...('function' === typeof allTypes[splitType] ? allTypes[splitType](instance) : allTypes[splitType])
};
}
}
@ -100,16 +100,15 @@ export function description(type, instance) {
};
}
export function fitsInto(candidate, reference) {
export function fitsInto(candidate, reference, eq = (l, r) => l === r) {
const candidates = candidate.split('|');
const references = candidate.split('|');
const references = reference.split('|');
for (let i = 0; i < references.length; i++) {
if ('any' === references[i]) {
if (-1 !== ['any'].indexOf(references[i])) {
return true;
}
for (let j = 0; j < candidates.length; j++) {
const refer = candidates[j];
if (references[i] === candidates[j]) {
if (eq(references[i], candidates[j])) {
return true;
}
}