Skip to content

Commit

Permalink
Another try on reducing the complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Feb 7, 2021
1 parent a37cfdc commit dd7c72f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/helpers/helpers.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,8 @@ function createSubResolver(parentScopes, prop, value) {
const set = new Set([value]);
const {keys, includeParents} = _resolveSubKeys(parentScopes, prop, value);
for (const key of keys) {
for (const item of parentScopes) {
const scope = resolveObjectKey(item, key);
if (scope) {
set.add(scope);
} else if (key !== prop && scope === false) {
// If any of the fallback scopes is explicitly false, return false
// For example, options.hover falls back to options.interaction, when
// options.interaction is false, options.hover will also resolve as false.
return false;
}
if (addScopes(set, prop, key, parentScopes) === false) {
return false;
}
}
if (includeParents) {
Expand All @@ -175,6 +167,20 @@ function createSubResolver(parentScopes, prop, value) {
return _createResolver([...set]);
}

function addScopes(set, prop, key, parentScopes) {
for (const item of parentScopes) {
const scope = resolveObjectKey(item, key);
if (scope) {
set.add(scope);
} else if (key !== prop && scope === false) {
// If any of the fallback scopes is explicitly false, return false
// For example, options.hover falls back to options.interaction, when
// options.interaction is false, options.hover will also resolve as false.
return false;
}
}
}

function _resolveSubKeys(parentScopes, prop, value) {
const fallback = _resolve('_fallback', parentScopes.map(scope => scope[prop] || scope));
const keys = [prop];
Expand Down

0 comments on commit dd7c72f

Please sign in to comment.