1
0
Fork 0

chore(core): Do not add hide methods to options

This commit is contained in:
Joost De Cock 2022-09-08 11:53:05 +02:00
parent 07b814c254
commit 58c15f6c81
2 changed files with 0 additions and 51 deletions

View file

@ -47,10 +47,6 @@ export function Design(config) {
// Replace config.parts with the resolved config // Replace config.parts with the resolved config
config.parts = parts config.parts = parts
// Ensure all options have a hide() method and menu property
config.options = completeOptions(config.options)
const pattern = function (settings) { const pattern = function (settings) {
Pattern.call(this, config) Pattern.call(this, config)
@ -67,25 +63,3 @@ export function Design(config) {
return pattern return pattern
} }
/*
* A default hide() method for options that lack it
* As this always return false, the option will never be hidden
*/
const hide = () => false
/*
* Helper method to add the default hide() method to options who lack one
* as well as set the `menu` property to false (if it's missing)
*/
const completeOptions = options => {
if (options) {
for (const option in options) {
if (typeof options[option] === 'object') {
options[option] = { hide, menu: false, ...options[option] }
}
}
}
return options
}

View file

@ -109,30 +109,5 @@ describe('Design', () => {
*/ */
it("Pattern constructor should add default hide() method to options", () => {
const design = new Design({
foo: "bar",
options: {
constant: 2,
percentage: { pct: 30, min: 0, max: 100 },
degree: { deg: 5, min: 0, max: 10 },
withHide: {
dflt: 'foo',
list: ['foo', 'bar'],
hide: ({ options }) => (options.degree < 6)
}
}
})
const pattern = new design().init();
expect(typeof pattern.config.options.constant === 'number').to.be.true
expect(typeof pattern.config.options.percentage === 'object').to.be.true
expect(typeof pattern.config.options.degree === 'object').to.be.true
expect(typeof pattern.config.options.withHide === 'object').to.be.true
expect(pattern.config.options.percentage.hide()).to.be.false
expect(pattern.config.options.degree.hide()).to.be.false
expect(pattern.config.options.withHide.hide(pattern.settings)).to.be.true
})
}) })