Skip to content

Conversation

@dmarcos
Copy link
Member

@dmarcos dmarcos commented Oct 15, 2017

It factors out the onButtonEvent method common to all controls. Other methods can be also factored out like onButtonChanged or onAxisMoved. I will do follow up PRs with those. I started with onButtonEvent for easier review

Copy link
Member

@ngokevin ngokevin left a comment

Choose a reason for hiding this comment

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

Is there a plan to eventually make this a registerController API? Otherwise it might eventually become hard to follow code if they all implement a tangle of utils.

@@ -0,0 +1,16 @@
/**
Copy link
Member

Choose a reason for hiding this comment

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

There's a tracked-controls utils where all the controllers share code already

Copy link
Member Author

Choose a reason for hiding this comment

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

It makes sense for me to separate tracked-controls from the higher level controls utils


// Update colors.
color = evtName === 'up' ? this.data.buttonColor : this.data.buttonHighlightColor;
if (Array.isArray(buttonName)) {
Copy link
Member

Choose a reason for hiding this comment

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

Don't need the array handler?

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 don’t think we need it. I don’t see it used anywhere. I believe we went ahead of ourselves and thought we would neef multiple events when a button is pressed. I can reintroduce but I couldn’t find where this code path is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that was originally there for buttons that were aliased to trigger more than one named event (e.g. 'menu' and 'app') but then we resolved the naming such that there were no duplicates. So it should not currently be used anywhere

@dmarcos
Copy link
Member Author

dmarcos commented Oct 15, 2017

I think is a bit premature to do a registerController API. There’s plenty of ad-hoc logic to deal with the specifics of each controller and I don’t feel ready for abstraction. Factoring out a few functions will clean up and make code testable. We can reevaluate anregisterController API a bit later.

@@ -1,5 +1,7 @@
var registerComponent = require('../core/component').registerComponent;
var bind = require('../utils/bind');
var controlsUtils = require('../utils/controls');
Copy link
Member

Choose a reason for hiding this comment

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

We have controlsUtils and controllerUtils, could be confusing

* @param {object} component - reference to the component
* @param {string} hand - handedness of the controller: left or right.
*/
module.exports.onButtonEvent = function (id, evtName, component, hand) {
Copy link
Member

@ngokevin ngokevin Oct 16, 2017

Choose a reason for hiding this comment

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

Concerned about passing in component and having a utility call a bunch of the component's methods.

For example, we did this with checkControllerPresentAndSetup, I found it hard to follow. The utils depends on component.el, component.controllerPresent, component.addEventListeners, component.controllerEventsActive, component.injectTrackedControls, component.removeEventListeners. There's a huge amount of interface expected to be available.

Since we want to make available these shared methods and have the controllers implement this common interface, we might want to think early about a higher level API/prototype mixin early. Splitting out to a util makes it seem refactored, but the util and component are heavily coupled and not any more testable. It might be the wrong road to go down.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree that although the attempt to refactor into utils allowed code reuse, it made it nearly impossible to understand what things were doing without a pretty thorough look

Copy link
Member Author

@dmarcos dmarcos Oct 16, 2017

Choose a reason for hiding this comment

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

You're correct. It's essentially a mixin but passing the this as an argument rather than this.foo(). I want to stay focused on the task of improving controls. My goal is to easily be able to add thumbpadup, thumbstickup methods without having to copy code across controllers. There will be just three methods factored out from controllers. In a separate PR we can think of a mixin mechanism that consolidates checkControllerPresentAndSetup and these factored out methods in a more sustainable pattern.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure the utils improves the code quality of the controls since it makes things hard to understand, I'd favor copy and pasting code. Ideally, if we're refactoring, we might as well refactor in the right direction. We can merge something temporary if we agree on the mechanism and someone promises to do it soon.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps not agree on the specific code, but that we can have a mixin-style refactor instead soon after you are able to finish the thumbpad/stick work. Then mostly OK with something temporary, these methods are at least less coupled than the tracked-controls utils.

Copy link
Member

@ngokevin ngokevin left a comment

Choose a reason for hiding this comment

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

OK, we can go ahead. It's a sideways move, we can do a bigger refactor later.

@dmarcos dmarcos force-pushed the factorOutOnButtonEvent branch from a7b9510 to 58017c7 Compare October 20, 2017 01:26
@dmarcos
Copy link
Member Author

dmarcos commented Oct 20, 2017

I consolidated the new methods in tracked-controls utils

@dmarcos dmarcos merged commit a992d78 into aframevr:master Oct 20, 2017
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