-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consolidate Array.isArray calls in MutableEvent setters
- Loading branch information
Showing
1 changed file
with
6 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5711bf1
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.
@tejaede why not:
if(Array.isArray(value)) {
if(this._event.touches) {
this._event.touches.splice.apply(this._event.touches, [0, Infinity].concat(value));
}
else {
this._event.touches = value;
}
}
5711bf1
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.
Although the blocks in this case are small enough that readability is not a concern, I find chained if/else statements are more readable than nested ifs as the statement(s) grows. So all things being equal, I'll go with if/else over nested ifs as a standard practice.
5711bf1
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.
All things are not equal here, events, especially touch, can be high frequency, and it's not worth creating a local var to be looked up only twice, especially in such a simple case. Even creating a new [0, Infinity] every time for the sake of calling concat on it should be avoided, it all adds to garbage collection's duty, and related performance consequences
5711bf1
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 suppose there is nothing in Montage code that will use the setter? So perhaps we should remove the array check and splice apply altogether?
I do not see anything in the leaflet code that expects this.