Skip to content

Commit 3f16918

Browse files
committed
Perform recommended robust check for custom actions being functions
1 parent 848a4e4 commit 3f16918

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/core/environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ function environment(p5, fn, lifecycles){
784784
this.windowWidth = getWindowWidth();
785785
this.windowHeight = getWindowHeight();
786786
let executeDefault;
787-
if (this._customActions.windowResized) {
787+
if (typeof this._customActions.windowResized === 'function') {
788788
executeDefault = this._customActions.windowResized(e);
789789
if (executeDefault !== undefined && !executeDefault) {
790790
e.preventDefault();

src/events/acceleration.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ function acceleration(p5, fn, lifecycles){
657657
this.deviceOrientation = 'undefined';
658658
}
659659

660-
if (this._customActions.deviceMoved) {
660+
if (typeof this._customActions.deviceMoved === 'function') {
661661
if (
662662
Math.abs(this.accelerationX - this.pAccelerationX) > move_threshold ||
663663
Math.abs(this.accelerationY - this.pAccelerationY) > move_threshold ||
@@ -667,7 +667,7 @@ function acceleration(p5, fn, lifecycles){
667667
}
668668
}
669669

670-
if (this._customActions.deviceTurned) {
670+
if (typeof this._customActions.deviceTurned === 'function') {
671671
// The angles given by rotationX etc is from range [-180 to 180].
672672
// The following will convert them to [0 to 360] for ease of calculation
673673
// of cases when the angles wrapped around.
@@ -742,7 +742,7 @@ function acceleration(p5, fn, lifecycles){
742742
this.pRotateDirectionZ = rotateDirectionZ;
743743
this.turnAxis = undefined;
744744
}
745-
if (this._customActions.deviceShaken) {
745+
if (typeof this._customActions.deviceShaken === 'function') {
746746
let accelerationChangeX;
747747
let accelerationChangeY;
748748
// Add accelerationChangeZ if acceleration change on Z is needed

src/events/keyboard.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ function keyboard(p5, fn, lifecycles){
670670
this._downKeyCodes[e.code] = true;
671671
this._downKeys[e.key] = true;
672672

673-
if (this._customActions.keyPressed && !e.charCode) {
673+
if (typeof this._customActions.keyPressed === 'function' && !e.charCode) {
674674
const executeDefault = this._customActions.keyPressed(e);
675675
if (executeDefault === false) {
676676
e.preventDefault();
@@ -835,7 +835,7 @@ function keyboard(p5, fn, lifecycles){
835835
* </div>
836836
*/
837837
fn._onkeyup = function(e) {
838-
if (this._customActions.keyReleased) {
838+
if (typeof this._customActions.keyReleased === 'function') {
839839
const executeDefault = this._customActions.keyReleased(e);
840840
if (executeDefault === false) {
841841
e.preventDefault();
@@ -998,7 +998,7 @@ function keyboard(p5, fn, lifecycles){
998998
this._lastKeyCodeTyped = e.which; // track last keyCode
999999
this.key = e.key || String.fromCharCode(e.which) || e.which;
10001000

1001-
if (this._customActions.keyTyped) {
1001+
if (typeof this._customActions.keyTyped === 'function') {
10021002
const executeDefault = this._customActions.keyTyped(e);
10031003
if (executeDefault === false) {
10041004
e.preventDefault();

src/events/pointer.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* @requires constants
77
*/
88

9-
import * as constants from '../core/constants';
10-
119
function pointer(p5, fn, lifecycles){
1210
lifecycles.presetup = function(){
1311
const events = [
@@ -1336,7 +1334,7 @@ function pointer(p5, fn, lifecycles){
13361334
this._setMouseButton(e);
13371335
this._updatePointerCoords(e);
13381336

1339-
if (this._customActions.mousePressed) {
1337+
if (typeof this._customActions.mousePressed === 'function') {
13401338
executeDefault = this._customActions.mousePressed(e);
13411339
if (executeDefault === false) {
13421340
e.preventDefault();
@@ -1651,7 +1649,7 @@ function pointer(p5, fn, lifecycles){
16511649
* </div>
16521650
*/
16531651
fn._onclick = function(e) {
1654-
if (this._customActions.mouseClicked) {
1652+
if (typeof this._customActions.mouseClicked === 'function') {
16551653
const executeDefault = this._customActions.mouseClicked(e);
16561654
if (executeDefault === false) {
16571655
e.preventDefault();
@@ -1781,7 +1779,7 @@ function pointer(p5, fn, lifecycles){
17811779
*/
17821780

17831781
fn._ondblclick = function(e) {
1784-
if (this._customActions.doubleClicked) {
1782+
if (typeof this._customActions.doubleClicked === 'function') {
17851783
const executeDefault = this._customActions.doubleClicked(e);
17861784
if (executeDefault === false) {
17871785
e.preventDefault();
@@ -1929,7 +1927,7 @@ function pointer(p5, fn, lifecycles){
19291927
*/
19301928
fn._onwheel = function(e) {
19311929
this._mouseWheelDeltaY = e.deltaY;
1932-
if (this._customActions.mouseWheel) {
1930+
if (typeof this._customActions.mouseWheel === 'function') {
19331931
e.delta = e.deltaY;
19341932
const executeDefault = this._customActions.mouseWheel(e);
19351933
if (executeDefault === false) {

0 commit comments

Comments
 (0)