From 690a7b53a72ac71f9f76260fa50c634566c4e984 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Mon, 28 Nov 2022 23:25:05 -0400 Subject: divide things.js into modular files (hilariously) --- src/data/things/homepage-layout.js | 114 +++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/data/things/homepage-layout.js (limited to 'src/data/things/homepage-layout.js') diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js new file mode 100644 index 00000000..5948ff46 --- /dev/null +++ b/src/data/things/homepage-layout.js @@ -0,0 +1,114 @@ +import Thing from './thing.js'; + +import find from '../../util/find.js'; + +export class HomepageLayout extends Thing { + static [Thing.getPropertyDescriptors] = ({ + HomepageLayoutRow, + + validators: { + validateArrayItems, + validateInstanceOf, + }, + }) => ({ + // Update & expose + + sidebarContent: Thing.common.simpleString(), + + rows: { + flags: {update: true, expose: true}, + + update: { + validate: validateArrayItems(validateInstanceOf(HomepageLayoutRow)), + }, + }, + }) +} + +export class HomepageLayoutRow extends Thing { + static [Thing.getPropertyDescriptors] = ({ + Album, + Group, + }) => ({ + // Update & expose + + name: Thing.common.name('Unnamed Homepage Row'), + + type: { + flags: {update: true, expose: true}, + + update: { + validate() { + throw new Error(`'type' property validator must be overridden`); + }, + }, + }, + + color: Thing.common.color(), + + // Update only + + // These aren't necessarily used by every HomepageLayoutRow subclass, but + // for convenience of providing this data, every row accepts all wiki data + // arrays depended upon by any subclass's behavior. + albumData: Thing.common.wikiData(Album), + groupData: Thing.common.wikiData(Group), + }); +} + +export class HomepageLayoutAlbumsRow extends HomepageLayoutRow { + static [Thing.getPropertyDescriptors] = (opts, { + Album, + Group, + + validators: { + isCountingNumber, + isString, + validateArrayItems, + }, + } = opts) => ({ + ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts), + + // Update & expose + + type: { + flags: {update: true, expose: true}, + update: { + validate(value) { + if (value !== 'albums') { + throw new TypeError(`Expected 'albums'`); + } + + return true; + }, + }, + }, + + sourceGroupByRef: Thing.common.singleReference(Group), + sourceAlbumsByRef: Thing.common.referenceList(Album), + + countAlbumsFromGroup: { + flags: {update: true, expose: true}, + update: {validate: isCountingNumber}, + }, + + actionLinks: { + flags: {update: true, expose: true}, + update: {validate: validateArrayItems(isString)}, + }, + + // Expose only + + sourceGroup: Thing.common.dynamicThingFromSingleReference( + 'sourceGroupByRef', + 'groupData', + find.group + ), + + sourceAlbums: Thing.common.dynamicThingsFromReferenceList( + 'sourceAlbumsByRef', + 'albumData', + find.album + ), + }); +} -- cgit 1.3.0-6-gf8a5