diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-08-26 20:38:27 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-09-05 21:02:52 -0300 |
commit | 12b8040b05e81a523ef59ba583dde751206f2e1d (patch) | |
tree | 79dea816bdcbce593cf919809f27ec57d600d4cf | |
parent | 25beb8731d756bfa4fe6babb9e4b0a707c7823e0 (diff) |
data, test: retain validator for Track.color
-rw-r--r-- | src/data/things/thing.js | 20 | ||||
-rw-r--r-- | src/data/things/track.js | 4 | ||||
-rw-r--r-- | test/unit/data/things/track.js | 5 |
3 files changed, 21 insertions, 8 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js index 2af06904..2adba5c4 100644 --- a/src/data/things/thing.js +++ b/src/data/things/thing.js @@ -1116,9 +1116,11 @@ export default class Thing extends CacheableObject { // Exposes a dependency exactly as it is; this is typically the base of a // composition which was created to serve as one property's descriptor. - // Since this serves as a base, specify {update: true} to indicate that - // the property as a whole updates (and some previous compositional step - // works with that update value). + // Since this serves as a base, specify a value for {update} to indicate + // that the property as a whole updates (and some previous compositional + // step works with that update value). Set {update: true} to only enable + // the update flag, or set update to an object to specify a descriptor + // (e.g. for custom value validation). // // Please note that this *doesn't* verify that the dependency exists, so // if you provide the wrong name or it hasn't been set by a previous @@ -1127,17 +1129,23 @@ export default class Thing extends CacheableObject { // expose: (dependency, {update = false} = {}) => ({ annotation: `Thing.composite.expose`, - flags: {expose: true, update}, + flags: {expose: true, update: !!update}, expose: { mapDependencies: {dependency}, compute: ({dependency}) => dependency, }, + + update: + (typeof update === 'object' + ? update + : null), }), // Exposes the update value of an {update: true} property, or continues if // it's unavailable. By default, "unavailable" means value === null, but - // set {mode: 'empty'} to + // set {mode: 'empty'} to check with empty() instead, continuing for empty + // arrays also. exposeUpdateValueOrContinue({mode = 'null'} = {}) { if (mode !== 'null' && mode !== 'empty') { throw new TypeError(`Expected mode to be null or empty`); @@ -1156,7 +1164,7 @@ export default class Thing extends CacheableObject { : value === null); if (shouldContinue) { - return continuation(); + return continuation(value); } else { return continuation.exit(value); } diff --git a/src/data/things/track.js b/src/data/things/track.js index 15a48bb4..8d0a7ad4 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -47,7 +47,9 @@ export class Track extends Thing { color: Thing.composite.from(`Track.color`, [ Thing.composite.exposeUpdateValueOrContinue(), Track.composite.withAlbumProperty('color'), - Thing.composite.expose('#album.color', {update: true}), + Thing.composite.expose('#album.color', { + update: {validate: isColor}, + }), ]), // Disables presenting the track as though it has its own unique artwork. diff --git a/test/unit/data/things/track.js b/test/unit/data/things/track.js index 08e91732..dbc8434f 100644 --- a/test/unit/data/things/track.js +++ b/test/unit/data/things/track.js @@ -97,7 +97,7 @@ t.test(`Track.album`, t => { }); t.test(`Track.color`, t => { - t.plan(3); + t.plan(4); const {track, album} = stubTrackAndAlbum(); @@ -119,6 +119,9 @@ t.test(`Track.color`, t => { t.equal(track.color, '#123456', `color #3: is own value`); + + t.throws(() => { track.color = '#aeiouw'; }, TypeError, + `color #4: must be set to valid color`); }); t.test(`Track.coverArtDate`, t => { |