1
0
Fork 0

fix(core): Don't mutate settings. Fixes #2882

This commit is contained in:
Joost De Cock 2022-09-28 22:30:42 +02:00
parent c97eac9029
commit 911ada1606

View file

@ -581,8 +581,20 @@ Pattern.prototype.__applySettings = function (sets) {
if (!Array.isArray(sets)) throw 'Sets should be an array of settings objects' if (!Array.isArray(sets)) throw 'Sets should be an array of settings objects'
if (sets.length === 0) sets.push({}) // Required to load default settings if (sets.length === 0) sets.push({}) // Required to load default settings
this.settings = [] this.settings = []
for (const set in sets) { for (const i in sets) {
this.settings.push({ ...__loadPatternDefaults(), ...sets[set] }) // Make the user's input immmuatable to avoid weird bugs
sets[i] = Object.freeze(sets[i])
const set = { ...sets[i] }
if (!set.options) set.options = {}
if (!set.measurements) set.measurements = {}
this.settings.push({
...__loadPatternDefaults(),
...set,
// Force creation of a new objects
// so we don't reference the original
options: { ...set.options },
measurements: { ...set.measurements },
})
} }
return this return this