From 58c15f6c8130eadc70bc3f399b277593c382c559 Mon Sep 17 00:00:00 2001 From: Joost De Cock Date: Thu, 8 Sep 2022 11:53:05 +0200 Subject: [PATCH] chore(core): Do not add hide methods to options --- packages/core/src/design.mjs | 26 -------------------------- packages/core/tests/design.test.mjs | 25 ------------------------- 2 files changed, 51 deletions(-) diff --git a/packages/core/src/design.mjs b/packages/core/src/design.mjs index 991d65af3ce..91bc4a791b2 100644 --- a/packages/core/src/design.mjs +++ b/packages/core/src/design.mjs @@ -47,10 +47,6 @@ export function Design(config) { // Replace config.parts with the resolved config config.parts = parts - // Ensure all options have a hide() method and menu property - config.options = completeOptions(config.options) - - const pattern = function (settings) { Pattern.call(this, config) @@ -67,25 +63,3 @@ export function Design(config) { 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 -} - diff --git a/packages/core/tests/design.test.mjs b/packages/core/tests/design.test.mjs index 71ca9caf3f5..afa54a29efe 100644 --- a/packages/core/tests/design.test.mjs +++ b/packages/core/tests/design.test.mjs @@ -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 - }) - })