@@ -82,50 +82,54 @@ export const pointerLockMovement = (
82
82
}
83
83
84
84
const move : CoData < MoveContext , PointerEvent > = ( context , effect ) => payload => {
85
- if ( payload . defaultPrevented ) {
86
- return move ( context , effect )
85
+ const contextPatch : Pick < MoveContext , 'event' | 'movementX' | 'movementY' | 'x' | 'y' | 'status' > = {
86
+ event : payload ,
87
+ movementX : payload . movementX ,
88
+ movementY : payload . movementY ,
89
+ x : context . x + context . movementX ,
90
+ y : context . y + context . movementY ,
91
+ status : 'moving' ,
87
92
}
88
93
89
- context . event = payload
90
- context . movementX = payload . movementX
91
- context . movementY = payload . movementY
92
- context . x += context . movementX
93
- context . y += context . movementY
94
- context . status = 'moving'
95
-
96
94
if ( options . loopBehavior === 'loop' ) {
97
- if ( context . x > context . maxWidth ) {
98
- context . x -= context . maxWidth
99
- } else if ( context . x < 0 ) {
100
- context . x += context . maxWidth
95
+ if ( contextPatch . x > context . maxWidth ) {
96
+ contextPatch . x -= context . maxWidth
97
+ } else if ( contextPatch . x < 0 ) {
98
+ contextPatch . x += context . maxWidth
101
99
}
102
100
103
- if ( context . y > context . maxHeight ) {
104
- context . y -= context . maxHeight
105
- } else if ( context . y < 0 ) {
106
- context . y += context . maxHeight
101
+ if ( contextPatch . y > context . maxHeight ) {
102
+ contextPatch . y -= context . maxHeight
103
+ } else if ( contextPatch . y < 0 ) {
104
+ contextPatch . y += context . maxHeight
107
105
}
108
106
} else if ( options . loopBehavior === 'stop' ) {
109
- if ( context . x > context . maxWidth ) {
110
- context . x = context . maxWidth
111
- context . status = 'stopped'
112
- } else if ( context . x < 0 ) {
113
- context . x = 0
107
+ if ( contextPatch . x > context . maxWidth ) {
108
+ contextPatch . x = context . maxWidth
114
109
context . status = 'stopped'
110
+ } else if ( contextPatch . x < 0 ) {
111
+ contextPatch . x = 0
112
+ contextPatch . status = 'stopped'
115
113
}
116
114
117
- if ( context . y > context . maxHeight ) {
118
- context . y = context . maxHeight
119
- context . status = 'stopped'
120
- } else if ( context . y < 0 ) {
121
- context . y = 0
115
+ if ( contextPatch . y > context . maxHeight ) {
116
+ contextPatch . y = context . maxHeight
122
117
context . status = 'stopped'
118
+ } else if ( contextPatch . y < 0 ) {
119
+ contextPatch . y = 0
120
+ contextPatch . status = 'stopped'
123
121
}
124
122
}
125
123
126
- effect ( context )
124
+ const newContext = { ...context , ...contextPatch }
125
+
126
+ effect ( newContext )
127
+
128
+ if ( newContext . event . defaultPrevented ) {
129
+ return move ( context , effect )
130
+ }
127
131
128
- return move ( context , effect )
132
+ return move ( newContext , effect )
129
133
}
130
134
131
135
function startup ( ) {
0 commit comments