From 9e42c9f3773d431bc62fcf76f0da2cc852dfc329 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 4 Nov 2023 20:22:00 -0300 Subject: data: wikiData: use validateWikiData instead of instance checks --- src/data/composite/wiki-properties/wikiData.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/data/composite') diff --git a/src/data/composite/wiki-properties/wikiData.js b/src/data/composite/wiki-properties/wikiData.js index 4ea47785..5965b949 100644 --- a/src/data/composite/wiki-properties/wikiData.js +++ b/src/data/composite/wiki-properties/wikiData.js @@ -1,17 +1,20 @@ // General purpose wiki data constructor, for properties like artistData, // trackData, etc. -import {validateArrayItems, validateInstanceOf} from '#validators'; +import {validateWikiData} from '#validators'; -// TODO: Not templateCompositeFrom. +// TODO: Kludge. +import Thing from '../../things/thing.js'; -// TODO: This should validate with validateWikiData. +// TODO: Not templateCompositeFrom. export default function(thingClass) { + const referenceType = thingClass[Thing.referenceType]; + return { flags: {update: true}, update: { - validate: validateArrayItems(validateInstanceOf(thingClass)), + validate: validateWikiData({referenceType}), }, }; } -- cgit 1.3.0-6-gf8a5 From c4eba52cd5023e3b503937b47e2bc6f77527d5c3 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 4 Nov 2023 20:43:29 -0300 Subject: data: wikiData: port to templateCompositeFrom syntax --- src/data/composite/wiki-properties/wikiData.js | 29 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/data/composite') diff --git a/src/data/composite/wiki-properties/wikiData.js b/src/data/composite/wiki-properties/wikiData.js index 5965b949..5cea49a0 100644 --- a/src/data/composite/wiki-properties/wikiData.js +++ b/src/data/composite/wiki-properties/wikiData.js @@ -1,20 +1,29 @@ // General purpose wiki data constructor, for properties like artistData, // trackData, etc. +import {input, templateCompositeFrom} from '#composite'; import {validateWikiData} from '#validators'; +import {inputThingClass} from '#composite/wiki-data'; + // TODO: Kludge. import Thing from '../../things/thing.js'; -// TODO: Not templateCompositeFrom. +export default templateCompositeFrom({ + annotation: `wikiData`, + + compose: false, + + inputs: { + class: inputThingClass(), + }, -export default function(thingClass) { - const referenceType = thingClass[Thing.referenceType]; + update: ({ + [input.staticValue('class')]: thingClass, + }) => { + const referenceType = thingClass[Thing.referenceType]; + return {validate: validateWikiData({referenceType})}; + }, - return { - flags: {update: true}, - update: { - validate: validateWikiData({referenceType}), - }, - }; -} + steps: () => [], +}); -- cgit 1.3.0-6-gf8a5 From d6672865a59a94a2acdd3ec7e827f96f8c3e67e4 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 5 Nov 2023 17:52:25 -0400 Subject: data: withAlwaysReferenceByDirectory: micro-optimizations --- .../things/track/withAlwaysReferenceByDirectory.js | 29 ++++++++++++++-------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/data/composite') diff --git a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js index d27f7b23..52d72124 100644 --- a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js +++ b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js @@ -53,19 +53,28 @@ export default templateCompositeFrom({ // logic on a completely unrelated context. { dependencies: [input.myself(), 'trackData', 'originalReleaseTrack'], - compute: (continuation, { + compute(continuation, { [input.myself()]: thisTrack, ['trackData']: trackData, ['originalReleaseTrack']: ref, - }) => continuation({ - ['#originalRelease']: - (ref.startsWith('track:') - ? trackData.find(track => track.directory === ref.slice('track:'.length)) - : trackData.find(track => - track !== thisTrack && - !CacheableObject.getUpdateValue(track, 'originalReleaseTrack') && - track.name.toLowerCase() === ref.toLowerCase())), - }) + }) { + let originalRelease; + + if (ref.startsWith('track:')) { + const refDirectory = ref.slice('track:'.length); + originalRelease = + trackData.find(track => track.directory === refDirectory); + } else { + const refName = ref.toLowerCase(); + originalRelease = + trackData.find(track => + track.name.toLowerCase() === refName && + track !== thisTrack && + !CacheableObject.getUpdateValue(track, 'originalReleaseTrack')); + } + + return continuation({['#originalRelease']: originalRelease}); + }, }, exitWithoutDependency({ -- cgit 1.3.0-6-gf8a5 From 7841f97cde6182359bb3f2b0f6117c6379ef18dc Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 5 Nov 2023 18:29:22 -0400 Subject: data, find: use clean-logic, cached find.trackOriginalReleasesOnly --- .../things/track/withAlwaysReferenceByDirectory.js | 60 +++++++--------------- 1 file changed, 19 insertions(+), 41 deletions(-) (limited to 'src/data/composite') diff --git a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js index 52d72124..fac8e213 100644 --- a/src/data/composite/things/track/withAlwaysReferenceByDirectory.js +++ b/src/data/composite/things/track/withAlwaysReferenceByDirectory.js @@ -2,22 +2,15 @@ // just to the track's name, which means you don't have to always reference // some *other* (much more commonly referenced) track by directory instead // of more naturally by name. -// -// See the implementation for an important caveat about matching the original -// track against other tracks, which uses a custom implementation pulling (and -// duplicating) details from #find instead of using withOriginalRelease and the -// usual withResolvedReference / find.track() utilities. -// import {input, templateCompositeFrom} from '#composite'; +import find from '#find'; import {isBoolean} from '#validators'; import {exitWithoutDependency, exposeUpdateValueOrContinue} from '#composite/control-flow'; import {withPropertyFromObject} from '#composite/data'; - -// TODO: Kludge. (The usage of this, not so much the import.) -import CacheableObject from '../../../things/cacheable-object.js'; +import {withResolvedReference} from '#composite/wiki-data'; export default templateCompositeFrom({ annotation: `withAlwaysReferenceByDirectory`, @@ -44,38 +37,23 @@ export default templateCompositeFrom({ value: input.value(false), }), - // "Slow" / uncached, manual search from trackData (with this track - // excluded). Otherwise there end up being pretty bad recursion issues - // (track1.alwaysReferencedByDirectory depends on searching through data - // including track2, which depends on evaluating track2.alwaysReferenced- - // ByDirectory, which depends on searcing through data including track1...) - // That said, this is 100% a kludge, since it involves duplicating find - // logic on a completely unrelated context. - { - dependencies: [input.myself(), 'trackData', 'originalReleaseTrack'], - compute(continuation, { - [input.myself()]: thisTrack, - ['trackData']: trackData, - ['originalReleaseTrack']: ref, - }) { - let originalRelease; - - if (ref.startsWith('track:')) { - const refDirectory = ref.slice('track:'.length); - originalRelease = - trackData.find(track => track.directory === refDirectory); - } else { - const refName = ref.toLowerCase(); - originalRelease = - trackData.find(track => - track.name.toLowerCase() === refName && - track !== thisTrack && - !CacheableObject.getUpdateValue(track, 'originalReleaseTrack')); - } - - return continuation({['#originalRelease']: originalRelease}); - }, - }, + // It's necessary to use the custom trackOriginalReleasesOnly find function + // here, so as to avoid recursion issues - the find.track() function depends + // on accessing each track's alwaysReferenceByDirectory, which means it'll + // hit *this track* - and thus this step - and end up recursing infinitely. + // By definition, find.trackOriginalReleasesOnly excludes tracks which have + // an originalReleaseTrack update value set, which means even though it does + // still access each of tracks' `alwaysReferenceByDirectory` property, it + // won't access that of *this* track - it will never proceed past the + // `exitWithoutDependency` step directly above, so there's no opportunity + // for recursion. + withResolvedReference({ + ref: 'originalReleaseTrack', + data: 'trackData', + find: input.value(find.trackOriginalReleasesOnly), + }).outputs({ + '#resolvedReference': '#originalRelease', + }), exitWithoutDependency({ dependency: '#originalRelease', -- cgit 1.3.0-6-gf8a5