« get me outta code hell

flag.js « wiki-properties « composite « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-properties/flag.js
blob: fa787f925305d03e1011a8c814236557c5ab1783 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Straightforward flag descriptor for a variety of property purposes.
// Provide a default value, true or false!

import {input, templateCompositeFrom} from '#composite';
import {isBoolean} from '#validators';

export default templateCompositeFrom({
  annotation: 'flag',

  compose: false,

  inputs: {
    default: input({type: 'boolean'}),
  },

  update: {
    validate: isBoolean,
  },

  steps: () => [
    {
      dependencies: [input('default')],
      transform: (value, {[input('default')]: defaultValue}) =>
        value ?? defaultValue,
    },
  ],
});