Skip to content

Deprecate lodash.mixxx.js, and script.deepMerge#13460

Merged
JoergAtGithub merged 2 commits into
mixxxdj:mainfrom
christophehenry:depreciate-lodash
Jul 22, 2024
Merged

Deprecate lodash.mixxx.js, and script.deepMerge#13460
JoergAtGithub merged 2 commits into
mixxxdj:mainfrom
christophehenry:depreciate-lodash

Conversation

@christophehenry
Copy link
Copy Markdown
Contributor

As decided in #13457.

Comment on lines +679 to +702
setLayer(newLayer, reconnectComponents) {
if (reconnectComponents !== false) {
reconnectComponents = true;
}
if (reconnectComponents === true) {
this.forEachComponent(function(component) {
component.disconnect();
});
}

Object.assign(this, newLayer);

if (reconnectComponents === true) {
this.forEachComponent(function(component) {
component.connect();
component.trigger();
});
}

},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to create a copy with the new behavior so that it is more explicit that the implementation changes.

};

/** @deprecated Use {@link Object.assign} instead */
script.deepMerge = deepMerge;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn this file need a big refactoring…

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you elaborate?

Copy link
Copy Markdown
Contributor Author

@christophehenry christophehenry Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is declared using var sothat variables endup in the global scope. script should be declared as such:

(function(global) {
    const script = Object.freeze({
        LIBRARY_COLUMNS: Object.freeze({}),
        debug() {  }
    });
    global.script = script;
})(this)

That would improve readability IMHO.

Maybe even globalThis can be used? I need to check if implemented in QJSEngine.

Edit: well, no globalThis is not defined. I expected this. Sad.

Copy link
Copy Markdown
Contributor Author

@christophehenry christophehenry Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also print() is still used everywhere (could be remove in 2.60 too).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean global.script = ...? But yeah, employing that pattern would probably be better, even though I don't find it to improve readability particularly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you mean global.script = ...?

I yes, sorry, let me edit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn this file need a big refactoring…

Are you aware of #11625? Help to fix the build failure there is appreciated.

Comment thread res/controllers/midi-components-0.0.js Outdated
Comment on lines +659 to +660
applyLayer: function(newLayer, reconnectComponents) {
console.warn("Components.applyLayer is deprecated; use Component.setLayer instead");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applyLayer is used extensively. Do you think its feasible to transition some code to setLayer in certain mappings?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR? Sure! Every mapping or just one or two?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure. I'd say every one where you can be sure that the change to Object.assign does not cause regressions. Ideally any hardware you have on hand to test/verify that it didn't break anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh. I only have 2 Denon DN-S3700 here, sorry.

Copy link
Copy Markdown
Contributor Author

@christophehenry christophehenry Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an idea aboutwhat are the two most used controllers? I propose to start by them and them ask the community to test. And rollback on any issue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure. I'm guessing many pioneer controllers. Apart from that I could test on my NS6II and there are several people in the mixxx team that have a traktor S4MK3 (though that uses its own ComponentsJS implementation IIRC).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just switch it for all mappings before a beta and see if we receive complaints during the beta phase... Thats what betas are for IMO.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we switch the mappings in a seperate PR ?

Comment thread res/controllers/lodash.mixxx.js Outdated
*/
;(function() {
const DEPRECATION_MSG = (
"Lodash is deprecated and will be removed in Mixxx 2.6.0; refer to the page " +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Lodash is deprecated and will be removed in Mixxx 2.6.0; refer to the page " +
"Lodash is deprecated and will be removed in a future release of Mixxx; refer to the page " +

I'm in favor of deprecating Lodash and printing a warning, but we should not remove it to early. Third party mappings might break due to this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thank you.

Copy link
Copy Markdown
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. wdyt @JoergAtGithub?

Comment thread res/controllers/midi-components-0.0.js Outdated
@christophehenry
Copy link
Copy Markdown
Contributor Author

christophehenry commented Jul 14, 2024

@Swiftb0y @JoergAtGithub Uh wait. There's one more typo.

Edit: Done.

}
};

/** @deprecated Use {@link Object.assign} instead */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This @deprecated is not recognized. I think it only works before the function definition.

Copy link
Copy Markdown
Contributor Author

@christophehenry christophehenry Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it? What IDE are you on? This is correctly interpreted on CLion:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It neither work with VisualStudio nor VS Code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if i write:

/**
 * 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
 * @deprecated Use {@link Object.assign} instead
 */
script.deepMerge = function(target, source) {
    console.warn("script.deepMerge is deprecated; use Object.assign instead");

}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Than it warns in line script.deepMerge = deepMerge; that deepMerge is deprecated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My last commit should fix this. Can you test (I don't know how to tell to VSCode "there are global definitions in these files, plz source")?

return obj !== null && typeof obj === "object" && obj.constructor.name === "Object";
};

script.isSimpleObject = isSimpleObject;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be exported.

@christophehenry
Copy link
Copy Markdown
Contributor Author

I think it's ready for a merge, isn't it?

@JoergAtGithub
Copy link
Copy Markdown
Member

I adapted the changes in res/controllers/common-controller-scripts.js in #11625 in a way that works with IDEs too. This was the only issue I had.

Thank you!

@JoergAtGithub JoergAtGithub merged commit a9b3e7f into mixxxdj:main Jul 22, 2024
@christophehenry christophehenry deleted the depreciate-lodash branch July 22, 2024 06:55
@christophehenry
Copy link
Copy Markdown
Contributor Author

Oh that was fast! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants