Skip to content

Commit 1f296c1

Browse files
committed
Use prefix _ convention to prevent unintended global exposure of custom actions
1 parent 3d5c2cf commit 1f296c1

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

src/core/environment.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,8 +784,8 @@ function environment(p5, fn, lifecycles){
784784
this.windowWidth = getWindowWidth();
785785
this.windowHeight = getWindowHeight();
786786
let executeDefault;
787-
if (this.customActions.windowResized) {
788-
executeDefault = this.customActions.windowResized(e);
787+
if (this._customActions.windowResized) {
788+
executeDefault = this._customActions.windowResized(e);
789789
if (executeDefault !== undefined && !executeDefault) {
790790
e.preventDefault();
791791
}

src/core/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class p5 {
9999
console.log(`You just changed the value of "${property}", which was a p5 global value. This could cause problems later if you're not careful.`);
100100
}
101101
}
102-
})
102+
});
103103
};
104104
// If the user has created a global setup or draw function,
105105
// assume "global" mode and make everything global (i.e. on the window)
@@ -178,7 +178,7 @@ class p5 {
178178
}
179179

180180
#customActions = {};
181-
customActions = new Proxy({}, {
181+
_customActions = new Proxy({}, {
182182
get: (target, prop) => {
183183
if(!this.#customActions[prop]){
184184
const context = this._isGlobal ? window : this;

src/events/acceleration.js

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

660-
if (this.customActions.deviceMoved) {
660+
if (this._customActions.deviceMoved) {
661661
if (
662662
Math.abs(this.accelerationX - this.pAccelerationX) > move_threshold ||
663663
Math.abs(this.accelerationY - this.pAccelerationY) > move_threshold ||
664664
Math.abs(this.accelerationZ - this.pAccelerationZ) > move_threshold
665665
) {
666-
this.customActions.deviceMoved();
666+
this._customActions.deviceMoved();
667667
}
668668
}
669669

670-
if (this.customActions.deviceTurned) {
670+
if (this._customActions.deviceTurned) {
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.
@@ -688,7 +688,7 @@ function acceleration(p5, fn, lifecycles){
688688
if (Math.abs(wRX - wSAX) > 90 && Math.abs(wRX - wSAX) < 270) {
689689
wSAX = wRX;
690690
this.turnAxis = 'X';
691-
this.customActions.deviceTurned();
691+
this._customActions.deviceTurned();
692692
}
693693
this.pRotateDirectionX = rotateDirectionX;
694694
startAngleX = wSAX - 180;
@@ -708,7 +708,7 @@ function acceleration(p5, fn, lifecycles){
708708
if (Math.abs(wRY - wSAY) > 90 && Math.abs(wRY - wSAY) < 270) {
709709
wSAY = wRY;
710710
this.turnAxis = 'Y';
711-
this.customActions.deviceTurned();
711+
this._customActions.deviceTurned();
712712
}
713713
this.pRotateDirectionY = rotateDirectionY;
714714
startAngleY = wSAY - 180;
@@ -737,12 +737,12 @@ function acceleration(p5, fn, lifecycles){
737737
) {
738738
startAngleZ = rotZ;
739739
this.turnAxis = 'Z';
740-
this.customActions.deviceTurned();
740+
this._customActions.deviceTurned();
741741
}
742742
this.pRotateDirectionZ = rotateDirectionZ;
743743
this.turnAxis = undefined;
744744
}
745-
if (this.customActions.deviceShaken) {
745+
if (this._customActions.deviceShaken) {
746746
let accelerationChangeX;
747747
let accelerationChangeY;
748748
// Add accelerationChangeZ if acceleration change on Z is needed
@@ -751,7 +751,7 @@ function acceleration(p5, fn, lifecycles){
751751
accelerationChangeY = Math.abs(this.accelerationY - this.pAccelerationY);
752752
}
753753
if (accelerationChangeX + accelerationChangeY > shake_threshold) {
754-
this.customActions.deviceShaken();
754+
this._customActions.deviceShaken();
755755
}
756756
}
757757
};

src/events/keyboard.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ function keyboard(p5, fn, lifecycles){
486486
this._downKeyCodes[e.code] = true;
487487
this._downKeys[e.key] = true;
488488

489-
if (this.customActions.keyPressed && !e.charCode) {
490-
const executeDefault = this.customActions.keyPressed(e);
489+
if (this._customActions.keyPressed && !e.charCode) {
490+
const executeDefault = this._customActions.keyPressed(e);
491491
if (executeDefault === false) {
492492
e.preventDefault();
493493
}
@@ -651,8 +651,8 @@ function keyboard(p5, fn, lifecycles){
651651
* </div>
652652
*/
653653
fn._onkeyup = function(e) {
654-
if (this.customActions.keyReleased) {
655-
const executeDefault = this.customActions.keyReleased(e);
654+
if (this._customActions.keyReleased) {
655+
const executeDefault = this._customActions.keyReleased(e);
656656
if (executeDefault === false) {
657657
e.preventDefault();
658658
}
@@ -814,8 +814,8 @@ function keyboard(p5, fn, lifecycles){
814814
this._lastKeyCodeTyped = e.which; // track last keyCode
815815
this.key = e.key || String.fromCharCode(e.which) || e.which;
816816

817-
if (this.customActions.keyTyped) {
818-
const executeDefault = this.customActions.keyTyped(e);
817+
if (this._customActions.keyTyped) {
818+
const executeDefault = this._customActions.keyTyped(e);
819819
if (executeDefault === false) {
820820
e.preventDefault();
821821
}

src/events/pointer.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,13 @@ function pointer(p5, fn, lifecycles){
11801180
this._activePointers.set(e.pointerId, e);
11811181
this._setMouseButton(e);
11821182

1183-
if (!this.mouseIsPressed && this.customActions.mouseMoved) {
1184-
executeDefault = this.customActions.mouseMoved(e);
1183+
if (!this.mouseIsPressed && this._customActions.mouseMoved) {
1184+
executeDefault = this._customActions.mouseMoved(e);
11851185
if (executeDefault === false) {
11861186
e.preventDefault();
11871187
}
1188-
} else if (this.mouseIsPressed && this.customActions.mouseDragged) {
1189-
executeDefault = this.customActions.mouseDragged(e);
1188+
} else if (this.mouseIsPressed && this._customActions.mouseDragged) {
1189+
executeDefault = this._customActions.mouseDragged(e);
11901190
if (executeDefault === false) {
11911191
e.preventDefault();
11921192
}
@@ -1343,8 +1343,8 @@ function pointer(p5, fn, lifecycles){
13431343
this._setMouseButton(e);
13441344
this._updatePointerCoords(e);
13451345

1346-
if (this.customActions.mousePressed) {
1347-
executeDefault = this.customActions.mousePressed(e);
1346+
if (this._customActions.mousePressed) {
1347+
executeDefault = this._customActions.mousePressed(e);
13481348
if (executeDefault === false) {
13491349
e.preventDefault();
13501350
}
@@ -1503,8 +1503,8 @@ function pointer(p5, fn, lifecycles){
15031503

15041504
this._updatePointerCoords(e);
15051505

1506-
if (this.customActions.mouseReleased) {
1507-
executeDefault = this.customActions.mouseReleased(e);
1506+
if (this._customActions.mouseReleased) {
1507+
executeDefault = this._customActions.mouseReleased(e);
15081508
if (executeDefault === false) {
15091509
e.preventDefault();
15101510
}
@@ -1658,8 +1658,8 @@ function pointer(p5, fn, lifecycles){
16581658
* </div>
16591659
*/
16601660
fn._onclick = function(e) {
1661-
if (this.customActions.mouseClicked) {
1662-
const executeDefault = this.customActions.mouseClicked(e);
1661+
if (this._customActions.mouseClicked) {
1662+
const executeDefault = this._customActions.mouseClicked(e);
16631663
if (executeDefault === false) {
16641664
e.preventDefault();
16651665
}
@@ -1788,8 +1788,8 @@ function pointer(p5, fn, lifecycles){
17881788
*/
17891789

17901790
fn._ondblclick = function(e) {
1791-
if (this.customActions.doubleClicked) {
1792-
const executeDefault = this.customActions.doubleClicked(e);
1791+
if (this._customActions.doubleClicked) {
1792+
const executeDefault = this._customActions.doubleClicked(e);
17931793
if (executeDefault === false) {
17941794
e.preventDefault();
17951795
}
@@ -1936,9 +1936,9 @@ function pointer(p5, fn, lifecycles){
19361936
*/
19371937
fn._onwheel = function(e) {
19381938
this._mouseWheelDeltaY = e.deltaY;
1939-
if (this.customActions.mouseWheel) {
1939+
if (this._customActions.mouseWheel) {
19401940
e.delta = e.deltaY;
1941-
const executeDefault = this.customActions.mouseWheel(e);
1941+
const executeDefault = this._customActions.mouseWheel(e);
19421942
if (executeDefault === false) {
19431943
e.preventDefault();
19441944
}

0 commit comments

Comments
 (0)