-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Components ES6 rewrite #4171
Conversation
Pull Request Test Coverage Report for Build 1088081279
💛 - Coveralls |
}; | ||
XoneK2.EffectUnit.prototype = new components.ComponentContainer(); |
There was a problem hiding this comment.
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 :)
There was a problem hiding this 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.
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); | ||
} | ||
} | ||
}; |
There was a problem hiding this comment.
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?
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]); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do
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); | ||
} |
There was a problem hiding this comment.
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?
var EffectUnit = class extends ComponentContainer { | ||
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Also, we should introduce documentation using JSDoc comments now. |
There was a problem hiding this 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. | ||
**/ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
if (this.midi === undefined || this.midi[0] === undefined || this.midi[1] === undefined) { | ||
return; | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
// 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()"); |
There was a problem hiding this comment.
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.
var EffectUnit = class extends ComponentContainer { | ||
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) { |
There was a problem hiding this comment.
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.
var EffectUnit = class extends ComponentContainer { | ||
constructor(unitNumbers, allowFocusWhenParametersHidden, colors) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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?
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 |
It seems you have forgotten to run pre-commit. |
I have not forgotten. That was intentional, otherwise the Xone K2 commit would be cluttered with a bunch of unrelated automated code cleanup. |
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... |
This PR is marked as stale because it has been open 90 days with no activity. |
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.