diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 22:29:18 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 22:29:18 -0400 |
commit | 11a6a76dc78aa6f30cc6860ba353ef68cf9e21c5 (patch) | |
tree | 457103f8cd08f3f41cd576ac1c384bf50b1140c1 | |
parent | dff7dd72606338f2a29171a50d223ad6286b6e50 (diff) |
data, upd8: auto-provide boundFind on 'find' dependency
-rw-r--r-- | src/data/yaml.js | 28 | ||||
-rwxr-xr-x | src/upd8.js | 4 | ||||
-rw-r--r-- | test/unit/data/things/track.js | 5 |
3 files changed, 28 insertions, 9 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js index 64223662..2420bf71 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -1225,7 +1225,7 @@ export async function loadAndProcessDataDocuments(dataSteps, {dataPath}) { // Data linking! Basically, provide (portions of) wikiData to the Things which // require it - they'll expose dynamically computed properties as a result (many // of which are required for page HTML generation and other expected behavior). -export function linkWikiDataArrays(wikiData) { +export function linkWikiDataArrays(wikiData, {bindFind}) { const linkWikiDataSpec = new Map([ [wikiData.albumData, [ 'albumData', @@ -1299,19 +1299,37 @@ export function linkWikiDataArrays(wikiData) { ]], ]); + const constructorHasFindMap = new Map(); + const boundFind = bindFind(wikiData); + for (const [things, keys] of linkWikiDataSpec.entries()) { if (things === undefined) continue; + for (const thing of things) { if (thing === undefined) continue; + + let hasFind; + if (constructorHasFindMap.has(thing.constructor)) { + hasFind = constructorHasFindMap.get(thing.constructor); + } else { + hasFind = 'find' in thing; + constructorHasFindMap.set(thing.constructor, hasFind); + } + + if (hasFind) { + thing.find = boundFind; + } + for (const key of keys) { if (!(key in wikiData)) continue; + thing[key] = wikiData[key]; } } } } -export function sortWikiDataArrays(dataSteps, wikiData) { +export function sortWikiDataArrays(dataSteps, wikiData, {bindFind}) { for (const [key, value] of Object.entries(wikiData)) { if (!Array.isArray(value)) continue; wikiData[key] = value.slice(); @@ -1327,7 +1345,7 @@ export function sortWikiDataArrays(dataSteps, wikiData) { // slices instead of the original arrays) - this is so that the object // caching system understands that it's working with a new ordering. // We still need to actually provide those updated arrays over again! - linkWikiDataArrays(wikiData); + linkWikiDataArrays(wikiData, {bindFind}); } // Utility function for loading all wiki data from the provided YAML data @@ -1363,7 +1381,7 @@ export async function quickLoadAllFromYAML(dataPath, { } } - linkWikiDataArrays(wikiData); + linkWikiDataArrays(wikiData, {bindFind}); try { reportDirectoryErrors(wikiData, {getAllFindSpecs}); @@ -1389,7 +1407,7 @@ export async function quickLoadAllFromYAML(dataPath, { logWarn`Content text errors found.`; } - sortWikiDataArrays(dataSteps, wikiData); + sortWikiDataArrays(dataSteps, wikiData, {bindFind}); return wikiData; } diff --git a/src/upd8.js b/src/upd8.js index f4c6326a..5c066ab7 100755 --- a/src/upd8.js +++ b/src/upd8.js @@ -1526,7 +1526,7 @@ async function main() { timeStart: Date.now(), }); - linkWikiDataArrays(wikiData); + linkWikiDataArrays(wikiData, {bindFind}); Object.assign(stepStatusSummary.linkWikiDataArrays, { status: STATUS_DONE_CLEAN, @@ -1740,7 +1740,7 @@ async function main() { timeStart: Date.now(), }); - sortWikiDataArrays(yamlDataSteps, wikiData); + sortWikiDataArrays(yamlDataSteps, wikiData, {bindFind}); Object.assign(stepStatusSummary.sortWikiDataArrays, { status: STATUS_DONE_CLEAN, diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js index 983a5537..403dc064 100644 --- a/test/unit/data/things/track.js +++ b/test/unit/data/things/track.js @@ -1,5 +1,6 @@ import t from 'tap'; +import {bindFind} from '#find'; import thingConstructors from '#things'; import { @@ -662,13 +663,13 @@ t.test(`Track.otherReleases`, t => { `otherReleases #2: otherReleases of original release are its rereleases`); wikiData.trackData = [track1, track3, track2, track4]; - linkWikiDataArrays(); + linkWikiDataArrays({bindFind}); t.same(track1.otherReleases, [track3, track2, track4], `otherReleases #3: otherReleases matches trackData order`); wikiData.trackData = [track3, track2, track1, track4]; - linkWikiDataArrays(); + linkWikiDataArrays({bindFind}); t.same(track2.otherReleases, [track1, track3, track4], `otherReleases #4: otherReleases of rerelease are original track then other rereleases (1/3)`); |