refactor: type liberalism
This commit is contained in:
parent
83ca91d3b8
commit
65a21b6718
|
@ -82,15 +82,15 @@ export function description(type, instance) {
|
||||||
const allTypes = types();
|
const allTypes = types();
|
||||||
const defaults = {
|
const defaults = {
|
||||||
children: {},
|
children: {},
|
||||||
type,
|
|
||||||
};
|
};
|
||||||
const splitTypes = type.split('|');
|
const splitTypes = type.split('|');
|
||||||
for (let i = 0; i < splitTypes.length; i++) {
|
for (let i = 0; i < splitTypes.length; i++) {
|
||||||
const type = splitTypes[i];
|
const splitType = splitTypes[i];
|
||||||
if (allTypes[type]) {
|
if (allTypes[splitType]) {
|
||||||
return {
|
return {
|
||||||
...defaults,
|
...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 candidates = candidate.split('|');
|
||||||
const references = candidate.split('|');
|
const references = reference.split('|');
|
||||||
for (let i = 0; i < references.length; i++) {
|
for (let i = 0; i < references.length; i++) {
|
||||||
if ('any' === references[i]) {
|
if (-1 !== ['any'].indexOf(references[i])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (let j = 0; j < candidates.length; j++) {
|
for (let j = 0; j < candidates.length; j++) {
|
||||||
const refer = candidates[j];
|
if (eq(references[i], candidates[j])) {
|
||||||
if (references[i] === candidates[j]) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user