From c3dfb1d5607627e45595347628f39eb7546009da Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sun, 23 Jan 2022 01:31:37 -0400 Subject: track data --- src/thing/thing.js | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'src/thing/thing.js') diff --git a/src/thing/thing.js b/src/thing/thing.js index dd3126c1..54a278d1 100644 --- a/src/thing/thing.js +++ b/src/thing/thing.js @@ -1,30 +1,32 @@ // Base class for Things. No, we will not come up with a better name. // Sorry not sorry! :) -// -// NB: Since these methods all involve processing a variety of input data, some -// of which will pass and some of which may fail, any failures should be thrown -// together as an AggregateError. See util/sugar.js for utility functions to -// make writing code around this easier! import CacheableObject from './cacheable-object.js'; +import { getKebabCase } from '../util/wiki-data.js'; + export default class Thing extends CacheableObject { - static propertyDescriptors = Symbol('Thing property descriptors'); + static referenceType = Symbol('Thing.referenceType'); + + static directoryExpose = { + dependencies: ['name'], + transform(directory, { name }) { + if (directory === null && name === null) + return null; + else if (directory === null) + return getKebabCase(name); + else + return directory; + } + }; + + static getReference(thing) { + if (!thing.constructor[Thing.referenceType]) + throw TypeError(`Passed Thing is ${thing.constructor.name}, which provides no [Thing.referenceType]`); - // Called when collecting the full list of available things of that type - // for wiki data; this method determine whether or not to include it. - // - // This should return whether or not the object is complete enough to be - // used across the wiki - not whether every optional attribute is provided! - // (That is, attributes required for postprocessing & basic page generation - // are all present.) - checkComplete() {} + if (!thing.directory) + throw TypeError(`Passed ${thing.constructor.name} is missing its directory`); - // Called when adding the thing to the wiki data list, and when its source - // data is updated (provided checkComplete() passes). - // - // This should generate any cached object references, across other wiki - // data; for example, building an array of actual track objects - // corresponding to an album's track list ('track:cool-track' strings). - postprocess({wikiData}) {} + return `${thing.constructor[Thing.referenceType]}:${thing.directory}`; + } } -- cgit 1.3.0-6-gf8a5