Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common-controller-scripts.js: Convert "script" to freezed object, and remove global "controller", "deck", "control", "button" definitions #11625

Open
wants to merge 19 commits into
base: 2.5
Choose a base branch
from

Conversation

JoergAtGithub
Copy link
Member

@JoergAtGithub JoergAtGithub commented Jun 4, 2023

  • Silenced eslint warnings vor unused vars
  • Use console.log instead of deprecated print function
  • Made global functions const.

@JoergAtGithub JoergAtGithub changed the title common-controller-scripts.js: Convert empty function to es2015 classe syntax common-controller-scripts.js: Convert empty function to es2015 class syntax Jun 4, 2023
@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch from 180edac to 210248a Compare June 4, 2023 17:42
…yntax

Silenced eslint warnings or unused vars
@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch from 210248a to b36c378 Compare June 4, 2023 18:27
Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

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

LGTM, However I am unable to test this.
Can we risk to merge it and see what happens during the remaining 5 Weeks beta?

@JoergAtGithub
Copy link
Member Author

I think it's unecessary risk for 2.4 now.

@JoergAtGithub JoergAtGithub marked this pull request as draft July 2, 2023 11:34
@JoergAtGithub JoergAtGithub added this to the 2.5.0 milestone Jul 5, 2023
@github-actions
Copy link

github-actions bot commented Oct 4, 2023

This PR is marked as stale because it has been open 90 days with no activity.

@github-actions github-actions bot added the stale Stale issues that haven't been updated for a long time. label Oct 4, 2023
@github-actions github-actions bot removed the stale Stale issues that haven't been updated for a long time. label Feb 22, 2024
@daschuer
Copy link
Member

daschuer commented May 8, 2024

Oh sorry this one slipped through. Can you fix the conflicts and than we can merge?

@daschuer
Copy link
Member

daschuer commented Jun 2, 2024

CI fails. I like to move this either to 2.5.0 or 2.6-alpha milestone. Does this have an impact on mapping interface regarding documentation?

@JoergAtGithub
Copy link
Member Author

No impact on documentation. I currently don't know how to fix this.

@christophehenry
Copy link
Contributor

christophehenry commented Jul 16, 2024

Let's wait for the end of the CI but I believe ac4ab33 solves this CI error. At least it solves it locally here. I think the error comes from that const declarations do not create properties on globalThis when declared at the top level of a script. so const script won't dump script into the global namespace. I enclosed the whole code into a (function(global) { … }(this)); to solve this.
I also changed script's method definitions to ES6 methods synctatic sugar.

I don't know why reverting to var didn't solve the problem, though.

Edit: yup, that fixes the tests. You can cherry pick ac4ab335b5831f7d1e2a885c7d014b04e3e8c2bd.

@Swiftb0y
Copy link
Member

Great. Thanks for investigating.

@JoergAtGithub
Copy link
Member Author

Unfortunately the (function(global) { … }(this)); breaks the IDE support for me. Not a single symbol from common-controller-scripts.js is recognized anymore and I get spamed with errors.

@JoergAtGithub
Copy link
Member Author

Now everything is Pass!
The reason was that variable objects in JavaScript exist from the start - as undefined, while const objects do not exist before completion of their initialization.
The function script.deepMerge contains recursive calls of itself. While initializing script.deepMerge it fails, because the recursive called function script.deepMerge does not exist yet.

@Swiftb0y
Copy link
Member

Swiftb0y commented Jul 17, 2024

great. the only remaining comments are the ones from above suggesting the use of default parameters. Have you looked into that?

EDIT: I just double-checked myself. It does support default parameters. So it be nice to see them used in the spots highlighted.

@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch from 3c59fb1 to d94fffb Compare July 17, 2024 23:10
@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch from 4f3a8af to acb1d93 Compare July 18, 2024 06:23
@JoergAtGithub
Copy link
Member Author

Done!

@JoergAtGithub JoergAtGithub changed the title common-controller-scripts.js: Convert "script" to const object, and remove global "controller", "deck", "control", "button" definitions common-controller-scripts.js: Convert "script" to freezed object, and remove global "controller", "deck", "control", "button" definitions Jul 18, 2024
@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch 2 times, most recently from e314d95 to 12e8bc1 Compare July 18, 2024 16:24
@JoergAtGithub JoergAtGithub force-pushed the ConvertEmptyFunctionToES2015Classes branch from ec64440 to dbe9a26 Compare July 18, 2024 16:40
}
}
// Add instance bpm of bpmClass to the Global JavaScript object
this.bpm = new bpmClass();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why didn't you keep the IIFE in my fix?

Copy link
Member

Choose a reason for hiding this comment

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

iiuc because it broke editor support for Joerg.

Copy link
Contributor

@christophehenry christophehenry Jul 23, 2024

Choose a reason for hiding this comment

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

What about using JSDoc's @global?

Suggested change
this.bpm = new bpmClass();
(function(global){
class bpmClass { }
/** @global */
const bpm = new bpmClass();
global.bpm = bpm;
})(this);

I used it here. @JoergAtGithub did it do the trick for you?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just tried it again, with the proposed code the symbol bpm becomes invisible outside of the function statement. Neither code completion, pop-up help nor type checking work anymore. While with the code of this PR everything works.
this.bpm = new bpmClass(); is not a new code pattern, it's already used in the hid-parser of 2.4 and seems to work for everybody.

Copy link
Contributor

@christophehenry christophehenry Jul 24, 2024

Choose a reason for hiding this comment

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

Weird. But ok then.

Edit: but you don't have any problem with Lodash? 🤔

Comment on lines +131 to 133
const colorCodeFromObject = function(color) {
return ((color.red & 0xFF) << 16 | (color.green & 0xFF) << 8 | (color.blue & 0xFF));
};
Copy link
Member

Choose a reason for hiding this comment

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

did you double check the const here didn't break anything?

Comment on lines +561 to +562
// @ts-ignore Same identifier for class and instance needed for backward compatibility
class bpmClass {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// @ts-ignore Same identifier for class and instance needed for backward compatibility
class bpmClass {
class bpmClass {

I also just noticed that we now have [ChannelN],tempo_tap which essentially deprecates script.bpm, right? cc @ronso0

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.

5 participants