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

Components ES6 rewrite #4171

Closed
wants to merge 2 commits into from
Closed

Components ES6 rewrite #4171

wants to merge 2 commits into from

Conversation

Be-ing
Copy link
Contributor

@Be-ing Be-ing commented Aug 1, 2021

This is a stopgap measure to improve the developer experience until we rewrite the controller system. The rewrite is in a separate file to avoid breaking old mappings.

@coveralls
Copy link

coveralls commented Aug 1, 2021

Pull Request Test Coverage Report for Build 1088081279

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.003%) to 26.014%

Totals Coverage Status
Change from base Build 1087078133: 0.003%
Covered Lines: 20005
Relevant Lines: 76902

💛 - Coveralls

};
XoneK2.EffectUnit.prototype = new components.ComponentContainer();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no more of this gooblygook :)

Copy link
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.

Didn't take look at the changes for the K2 as well the EffectUnit yet. This is already plenty to discuss for now.

res/controllers/midi-components-0.1.js Show resolved Hide resolved
res/controllers/midi-components-0.1.js Show resolved Hide resolved
res/controllers/midi-components-0.1.js Show resolved Hide resolved
res/controllers/midi-components-0.1.js Show resolved Hide resolved
Comment on lines +364 to +375
this.input = function(channel, control, value, status, _group) {
if (this.isPress(channel, control, value, status)) {
if (engine.getValue(this.group, "track_loaded") === 0) {
engine.setValue(this.group, "LoadSelectedTrack", 1);
} else {
if (this.volumeByVelocity) {
engine.setValue(this.group, "volume", this.inValueScale(value));
}
engine.setValue(this.group, "cue_gotoandplay", 1);
}
}
};
Copy link
Member

Choose a reason for hiding this comment

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

I know this is from components-0.0 but I'm confused why this even worked back then. If I understand JS correctly, the this of the new handler does not refer to the SamplerButton instance but the function object instance being created?

res/controllers/midi-components-0.1.js Show resolved Hide resolved
Comment on lines +496 to +520
forEachComponent(operation, recursive) {
if (typeof operation !== "function") {
throw "ComponentContainer.forEachComponent requires a function argument";
}
if (recursive === undefined) { recursive = true; }

var that = this;
var applyOperationTo = function(obj) {
if (obj instanceof Component) {
operation.call(that, obj);
} else if (recursive && obj instanceof ComponentContainer) {
obj.forEachComponent(operation);
} else if (Array.isArray(obj)) {
obj.forEach(function(element) {
applyOperationTo(element);
});
}
};

for (var memberName in this) {
if (ComponentContainer.prototype.hasOwnProperty.call(this, memberName)) {
applyOperationTo(this[memberName]);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using a generator? This way the consuming code could look a little more easy to understand for beginners. Eg:

for (const comp of container.iter()) {
    // insert function body here
}

Copy link
Member

Choose a reason for hiding this comment

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

I'd be willing to submit a PR implementing it if you don't want to bother researching generators first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

please do

Comment on lines +571 to +579
if (component instanceof Button
&& (component.type === Button.prototype.types.push
|| component.type === undefined)
&& component.input === Button.prototype.input
&& typeof component.inKey === "string"
&& typeof component.group === "string") {
if (engine.getValue(component.group, component.inKey) !== 0) {
engine.setValue(component.group, component.inKey, 0);
}
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't the button component be responsible for handling this special case?

Comment on lines +685 to +686
var EffectUnit = class extends ComponentContainer {
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) {
Copy link
Member

Choose a reason for hiding this comment

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

This is very convoluted. I'll be looking at the entire EffectUnit code some other time.

Copy link
Member

Choose a reason for hiding this comment

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

There is no other time. Once we merge this, we can't change it. Or maybe we can, but when beta period starts we will have to stick with this API forever.

Copy link
Member

Choose a reason for hiding this comment

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

FWIW it sucks that JS has no keyword args like Python. We sometimes take an options object, sometimes individual parameters. Can we use one style consistently?

Copy link
Member

Choose a reason for hiding this comment

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

There is no other time. Once we merge this, we can't change it.

I meant some other time in the future before merging. I just wanted to submit the comments I had so far so Be does not have to wait 3 weeks for a review.

@Swiftb0y
Copy link
Member

Swiftb0y commented Aug 2, 2021

Also, we should introduce documentation using JSDoc comments now.

Copy link
Member

@Holzhaus Holzhaus left a comment

Choose a reason for hiding this comment

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

Thanks. Some initial comments.

by calling this.disconnect(). This can be helpful for multicolor LEDs that show a
different color depending on the state of different Mixxx COs. Refer to
SamplerButton.connect() and SamplerButton.output() for an example.
**/
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the same commenting style as we do for CPP code, i.e. move the comment out of the body and put it above the function. And maybe use ///. Not sure if that works with doxygen.

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about using JSDoc in JS sources instead?

Comment on lines +136 to +138
if (this.midi === undefined || this.midi[0] === undefined || this.midi[1] === undefined) {
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this expected or an error? If the latter we should throw an exception.

return value > 0;
}
input(channel, control, value, status, _group) {
if (this.type === undefined || this.type === Button.prototype.types.push) {
Copy link
Member

Choose a reason for hiding this comment

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

type can never be undefined right? Please use a switch case and throw an error in the default case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is JavaScript. Everything and anything can be undefined.

Copy link
Member

Choose a reason for hiding this comment

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

It is defined in the constructor though

res/controllers/midi-components-0.1.js Show resolved Hide resolved
// Sends the color from the colorCode to the controller. This
// method will not be called if no colorKey has been specified.
if (colorCode === undefined || colorCode < 0 || colorCode > 0xFFFFFF) {
print("Ignoring invalid color code '" + colorCode + "' in outputColor()");
Copy link
Member

Choose a reason for hiding this comment

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

This should thow an exception IMHO. Because it cannot happen unless the user makes a mistake in the JS code.

Comment on lines +685 to +686
var EffectUnit = class extends ComponentContainer {
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) {
Copy link
Member

Choose a reason for hiding this comment

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

There is no other time. Once we merge this, we can't change it. Or maybe we can, but when beta period starts we will have to stick with this API forever.

Comment on lines +685 to +686
var EffectUnit = class extends ComponentContainer {
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW it sucks that JS has no keyword args like Python. We sometimes take an options object, sometimes individual parameters. Can we use one style consistently?

this.focusChooseModeActive = false;

// This is only connected if allowFocusWhenParametersHidden is false.
this.onShowParametersChange = function(value) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a method instead of function expression property? (also applies to the rest of the code)


// Do not enable soft takeover upon EffectUnit construction
// so initial values can be loaded from knobs.
if (this.hasInitialized === true) {
Copy link
Member

Choose a reason for hiding this comment

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

isInitialized?

});
this.effectFocusButton.setColor();

this.init = function() {
Copy link
Member

Choose a reason for hiding this comment

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

where is this called? why is is this not part of the constructor?

@Be-ing
Copy link
Contributor Author

Be-ing commented Aug 3, 2021

To clarify my intention with this PR, I only intend to refactor the existing Components library so it can be used with ES6 classes without copying and pasting arcane JS magic from Stack Overflow the wiki. I am open to making some minor API changes and code cleanup as well but I am not looking to do a major overhaul of the library right now.

@Swiftb0y
Copy link
Member

Swiftb0y commented Aug 3, 2021

It seems you have forgotten to run pre-commit.

@Be-ing
Copy link
Contributor Author

Be-ing commented Aug 3, 2021

I have not forgotten. That was intentional, otherwise the Xone K2 commit would be cluttered with a bunch of unrelated automated code cleanup.

@Be-ing
Copy link
Contributor Author

Be-ing commented Aug 3, 2021

I included the Xone K2 commit in this PR as an example of how to use the modified library. It is not the focus here. If you want, I can split it to another PR.

@Swiftb0y
Copy link
Member

Swiftb0y commented Aug 3, 2021

I included the Xone K2 commit in this PR as an example of how to use the modified library. It is not the focus here. If you want, I can split it to another PR.

I guess its useful to develop alongside of... though I'd prefer to merge it separate. I don't know how that would be achieved best with Git though...

@github-actions
Copy link

github-actions bot commented Nov 3, 2021

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 Nov 3, 2021
@Be-ing Be-ing closed this Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controller mappings stale Stale issues that haven't been updated for a long time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants