Skip to content

Conversation

@erikhaandrikman
Copy link

@erikhaandrikman erikhaandrikman commented Sep 26, 2019

Resolve #48

@woutermeek woutermeek requested a review from g-zachar October 3, 2019 17:16
}

registerKeyupHandler(keyhandler){
this._keyupListener = e => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessarily a style issue, but I'd prefer this arrow function to have () around arguments.

}

/**
* register and starts a timer for the pressed key. Timer will be cleared when the key is released
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Registers and starts (...)

* before the timer goes off.
*
* If key is not release (keyup) the longpress handler will be fired.
* configuration can be via the Components template:
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Configuration

Comment on lines 292 to 293
const focusPath = this.__getFocusPath();
const consumer = focusPath.pop();
Copy link
Contributor

Choose a reason for hiding this comment

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

I it possible to use this.focusPath instead to avoid recalculation?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, we can indeed grab the current calculated focus path

this._updateAttachedFlag();
this._updateEnabledFlag();

if (this.__keypressTimers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this.__keypressTimers is a Map object created in constructor and never reassigned, this will always yield true. You may also want to call this._keypressTimers.clear() to get rid of dangling references.

Copy link
Author

Choose a reason for hiding this comment

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

valid point, changed the condition to validate map size and clear the map

class TestApp extends lng.Application {
static _template(){
return {
A:{type: ComponentA}
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing space after A:

});

describe('Component', function() {
it('should handle keydown', function(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing space after ()

chai.assert(a.handled.indexOf("_handleUp") !== -1);
});

it('should handle keyup', function(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

chai.assert(a.handled.indexOf("_handleUpRelease") !== -1);
});

it('should handle captureKey', function(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Comment on lines 10 to 18
static _template(){
return {
A:{
type: ComponentA,
// configuration how long a key should be pressed before it's longpress counterpart fires
longpress:{up:700, down:600, left:800, right:900}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Inconsistent styling.

@erikhaandrikman
Copy link
Author

Code style updated


this.updateFocusPath();

const consumer = [...path].pop();
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't path[path.length - 1] simpler?

Copy link
Author

Choose a reason for hiding this comment

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

good point, is updated now


before(() => {
class TestApp extends lng.Application {
static _template(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing space before {

});

describe('Component', function() {
const repeat = (iterations)=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing spaces before and after =>


describe('Component', function() {
const repeat = (iterations)=>{
return new Promise((resolve)=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

}
}

class ComponentA extends lng.Component{
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing space before {

if (config[lookup]) {
const timeout = config[lookup];
if (!Utils.isNumber(timeout)) {
element._throwError("config value for longpress must be a number")
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: Missing ;

if (!Utils.isNumber(timeout)) {
element._throwError("config value for longpress must be a number")
} else {
this.__keypressTimers.set(key,setTimeout(()=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing spaces between and after =>

window.addEventListener('keydown', this._keydownListener);
}

registerKeyupHandler(keyhandler){
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing space before {


class ComponentA extends lng.Component {
static _template() {
return {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Style: missing ;

Copy link
Contributor

@g-zachar g-zachar left a comment

Choose a reason for hiding this comment

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

Updated comments

@g-zachar g-zachar merged commit 0971296 into master Oct 10, 2019
@g-zachar g-zachar deleted the feature/Longpress branch November 5, 2019 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Will you have some native "longpress handleKey" support?

3 participants