From 65a21b6718c0c1486adf9e7c179650b5473edb6a Mon Sep 17 00:00:00 2001 From: cha0s Date: Thu, 25 Jun 2020 09:53:27 -0500 Subject: [PATCH] refactor: type liberalism --- packages/behavior/type.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/behavior/type.js b/packages/behavior/type.js index 3933cdc..b7fba87 100644 --- a/packages/behavior/type.js +++ b/packages/behavior/type.js @@ -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; } }