From 95bd943d62473e53de11cd6368e540cd48e4231a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 12 Feb 2022 17:38:27 -0400 Subject: bam (Thing subclasses: several steps, one file) --- src/thing/thing.js | 62 ------------------------------------------------------ 1 file changed, 62 deletions(-) delete mode 100644 src/thing/thing.js (limited to 'src/thing/thing.js') diff --git a/src/thing/thing.js b/src/thing/thing.js deleted file mode 100644 index 2d6def6..0000000 --- a/src/thing/thing.js +++ /dev/null @@ -1,62 +0,0 @@ -// Base class for Things. No, we will not come up with a better name. -// Sorry not sorry! :) - -import CacheableObject from './cacheable-object.js'; - -import { - validateArrayItems, -} from './validators.js'; - -import { getKebabCase } from '../util/wiki-data.js'; -import find from '../util/find.js'; - -export default class Thing extends CacheableObject { - 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 genContribsExpose(contribsByRefProperty) { - return { - dependencies: ['artistData', contribsByRefProperty], - compute: ({ artistData, [contribsByRefProperty]: contribsByRef }) => ( - (contribsByRef && artistData - ? (contribsByRef - .map(({ who: ref, what }) => ({ - who: find.artist(ref, {wikiData: {artistData}}), - what - })) - .filter(({ who }) => who)) - : []) - ) - }; - } - - static genWikiDataProperty(thingClass) { - return { - flags: {update: true}, - update: { - validate: validateArrayItems(x => x instanceof thingClass) - } - }; - } - - static getReference(thing) { - if (!thing.constructor[Thing.referenceType]) - throw TypeError(`Passed Thing is ${thing.constructor.name}, which provides no [Thing.referenceType]`); - - if (!thing.directory) - throw TypeError(`Passed ${thing.constructor.name} is missing its directory`); - - return `${thing.constructor[Thing.referenceType]}:${thing.directory}`; - } -} -- cgit 1.3.0-6-gf8a5