diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-06-11 12:50:47 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-06-11 12:50:47 -0300 |
commit | bd2862e1b194d72fd403626897bf559a1eba9107 (patch) | |
tree | 52927dd93aa51026dd742b458cf925c77f829e48 | |
parent | 57aeed75e5ed503f5b79c3df730ae6b898652dc3 (diff) |
infra: reuse invalidatingDependencyKeys instead of reconstructing
-rw-r--r-- | src/content-function.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/content-function.js b/src/content-function.js index 18ede8e8..7b975e6a 100644 --- a/src/content-function.js +++ b/src/content-function.js @@ -49,6 +49,7 @@ export default function contentFunction({ expectedExtraDependencyKeys, missingContentDependencyKeys: new Set(expectedContentDependencyKeys), missingExtraDependencyKeys: new Set(expectedExtraDependencyKeys), + invalidatingDependencyKeys: new Set(), fulfilledDependencyKeys: new Set(), fulfilledDependencies: {}, }); @@ -66,6 +67,7 @@ export function expectDependencies({ expectedExtraDependencyKeys, missingContentDependencyKeys, missingExtraDependencyKeys, + invalidatingDependencyKeys, fulfilledDependencyKeys, fulfilledDependencies, }) { @@ -73,11 +75,6 @@ export function expectDependencies({ const hasRelationsFunction = !!relations; const hasDataFunction = !!data; - const invalidatingDependencyKeys = - Object.entries(fulfilledDependencies) - .filter(([key, value]) => value?.fulfilled === false) - .map(([key]) => key); - const isInvalidated = !empty(invalidatingDependencyKeys); const isMissingContentDependencies = !empty(missingContentDependencyKeys); const isMissingExtraDependencies = !empty(missingExtraDependencyKeys); @@ -86,7 +83,7 @@ export function expectDependencies({ if (isInvalidated) { wrappedGenerate = function() { - throw new Error(`Generate invalidated because unfulfilled dependencies provided: ${invalidatingDependencyKeys.join(', ')}`); + throw new Error(`Generate invalidated because unfulfilled dependencies provided: ${[...invalidatingDependencyKeys].join(', ')}`); }; annotateFunction(wrappedGenerate, {name: generate, trait: 'invalidated'}); @@ -150,6 +147,7 @@ export function expectDependencies({ // calls to this same `fulfill`. const newlyMissingContentDependencyKeys = new Set(missingContentDependencyKeys); const newlyMissingExtraDependencyKeys = new Set(missingExtraDependencyKeys); + const newlyInvalidatingDependencyKeys = new Set(invalidatingDependencyKeys); const newlyFulfilledDependencyKeys = new Set(fulfilledDependencyKeys); const newlyFulfilledDependencies = {...fulfilledDependencies}; @@ -157,6 +155,7 @@ export function expectDependencies({ fulfillDependencies(dependencies, { missingContentDependencyKeys: newlyMissingContentDependencyKeys, missingExtraDependencyKeys: newlyMissingExtraDependencyKeys, + invalidatingDependencyKeys: newlyInvalidatingDependencyKeys, fulfilledDependencyKeys: newlyFulfilledDependencyKeys, fulfilledDependencies: newlyFulfilledDependencies, }); @@ -175,6 +174,7 @@ export function expectDependencies({ expectedExtraDependencyKeys, missingContentDependencyKeys: newlyMissingContentDependencyKeys, missingExtraDependencyKeys: newlyMissingExtraDependencyKeys, + invalidatingDependencyKeys: newlyInvalidatingDependencyKeys, fulfilledDependencyKeys: newlyFulfilledDependencyKeys, fulfilledDependencies: newlyFulfilledDependencies, }); @@ -192,6 +192,7 @@ export function expectDependencies({ export function fulfillDependencies(dependencies, { missingContentDependencyKeys, missingExtraDependencyKeys, + invalidatingDependencyKeys, fulfilledDependencyKeys, fulfilledDependencies, }) { @@ -228,12 +229,18 @@ export function fulfillDependencies(dependencies, { errors.push(new Error(`Content dependency ${key} is not a content function (got ${value})`)); continue; } + + if (!value.fulfilled) { + invalidatingDependencyKeys.add(key); + } + missingContentDependencyKeys.delete(key); } else if (isExtraKey) { if (isContentFunction) { errors.push(new Error(`Extra dependency ${key} is a content function`)); continue; } + missingExtraDependencyKeys.delete(key); } |