Skip to content

Commit

Permalink
Merge pull request #14203 from git-developer/fix/issue-14197
Browse files Browse the repository at this point in the history
Quick fix for #14197 (`TypeError` in `midi-components-0.0.js`)
  • Loading branch information
Swiftb0y authored Jan 28, 2025
2 parents 950f453 + 0f780e3 commit 44e6b7e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
52 changes: 0 additions & 52 deletions res/controllers/common-controller-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,58 +140,6 @@ var colorCodeToObject = function(colorCode) {
var script = function() {
};

/**
* Discriminates whether an object was created using the `{}` synthax.
*
* Returns true when was an object was created using the `{}` synthax.
* False if the object is an instance of a class like Date or Proxy or an Array.
*
* isSimpleObject({}) // true
* isSimpleObject(null) // false
* isSimpleObject(undefined) // false
* isSimpleObject(new Date) // false
* isSimpleObject(new (class {})()) // false
* @param {any} obj Object to test
* @returns {boolean} true if obj was created using the `{}` or `new Object()` synthax, false otherwise
*/
const isSimpleObject = function(obj) {
return obj !== null && typeof obj === "object" && obj.constructor.name === "Object";
};

script.isSimpleObject = isSimpleObject;

/**
* Deeply merges 2 objects (Arrays and Objects only, not Map for instance).
* @param target {object | Array} Object to merge source into
* @param source {object | Array} Object to merge into source
*/
const deepMerge = function(target, source) {
if (target === source || target === undefined || target === null || source === undefined || source === null) {
return;
}

if (Array.isArray(target) && Array.isArray(source)) {
const objTarget = target.reduce((acc, val, idx) => Object.assign(acc, {[idx]: val}), {});
const objSource = source.reduce((acc, val, idx) => Object.assign(acc, {[idx]: val}), {});
deepMerge(objTarget, objSource);
target.length = 0;
target.push(...Object.values(objTarget));
} else if (isSimpleObject(target) && isSimpleObject(source)) {
Object.keys(source).forEach(key => {
if (
Array.isArray(target[key]) && Array.isArray(source[key]) ||
isSimpleObject(target[key]) && isSimpleObject(source[key])
) {
deepMerge(target[key], source[key]);
} else if (source[key] !== undefined && source[key] !== null) {
Object.assign(target, {[key]: source[key]});
}
});
}
};

script.deepMerge = deepMerge;

// ----------------- Mapping constants ---------------------

// Library column value, which can be used to interact with the CO for "[Library] sort_column"
Expand Down
2 changes: 1 addition & 1 deletion res/controllers/midi-components-0.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@
});
}

script.deepMerge(this, newLayer);
Object.assign(this, newLayer);

if (reconnectComponents === true) {
this.forEachComponent(function(component) {
Expand Down

0 comments on commit 44e6b7e

Please sign in to comment.