Skip to content

Commit 1f3a62c

Browse files
committed
fix: convert property bag to args
1 parent 253d313 commit 1f3a62c

File tree

5 files changed

+47
-197
lines changed

5 files changed

+47
-197
lines changed

packages/core/accessibility/index.android.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ function accessibilityEventHelper(view: View, eventType: number) {
5656
*/
5757
if (SDK_VERSION >= 26) {
5858
// Trigger all tap handlers on this view.
59-
new DOMEvent('tap').dispatchTo({
60-
target: view as View,
61-
data: {
59+
new DOMEvent('tap').dispatchTo(
60+
view as View,
61+
{
6262
android: view.android,
6363
eventName: 'tap',
6464
ios: null,
6565
object: view,
6666
type: GestureTypes.tap,
6767
view,
68-
} as GestureEventData,
69-
});
68+
} as GestureEventData
69+
);
7070
}
7171

7272
return;

packages/core/data/dom-events/dom-event.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,9 @@ export class DOMEvent implements Event {
290290
* event's cancelable attribute value is false or its preventDefault()
291291
* method was not invoked, and false otherwise.
292292
*/
293-
dispatchTo({ target, data, getGlobalEventHandlersPreHandling, getGlobalEventHandlersPostHandling }: { target: Observable; data: EventData; getGlobalEventHandlersPreHandling?: () => MutationSensitiveArray<ListenerEntry>; getGlobalEventHandlersPostHandling?: () => MutationSensitiveArray<ListenerEntry> }): boolean {
293+
// Taking multiple params rather than a single property bag saves about 100
294+
// nanoseconds per call.
295+
dispatchTo(target: Observable, data: EventData, getGlobalEventHandlersPreHandling?: () => MutationSensitiveArray<ListenerEntry>, getGlobalEventHandlersPostHandling?: () => MutationSensitiveArray<ListenerEntry>): boolean {
294296
if (this.eventPhase !== DOMEvent.NONE) {
295297
throw new Error('Tried to dispatch a dispatching event');
296298
}

packages/core/data/observable/index.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -377,12 +377,12 @@ export class Observable implements EventTarget {
377377
* @param options Options for the event, in line with DOM Standard.
378378
*/
379379
public notify<T extends EventData>(data: T, options?: CustomEventInit): void {
380-
new DOMEvent(data.eventName, options).dispatchTo({
381-
target: this,
380+
new DOMEvent(data.eventName, options).dispatchTo(
381+
this,
382382
data,
383-
getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(data, 'First'),
384-
getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(data, ''),
385-
});
383+
() => this._getGlobalEventHandlers(data, 'First'),
384+
() => this._getGlobalEventHandlers(data, '')
385+
);
386386
}
387387

388388
dispatchEvent(event: DOMEvent): boolean {
@@ -392,12 +392,12 @@ export class Observable implements EventTarget {
392392
detail: event.detail,
393393
};
394394

395-
return event.dispatchTo({
396-
target: this,
395+
return event.dispatchTo(
396+
this,
397397
data,
398-
getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(data, 'First'),
399-
getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(data, ''),
400-
});
398+
() => this._getGlobalEventHandlers(data, 'First'),
399+
() => this._getGlobalEventHandlers(data, '')
400+
);
401401
}
402402

403403
private _getGlobalEventHandlers(data: EventData, eventType: 'First' | ''): MutationSensitiveArray<ListenerEntry> {

packages/core/ui/gestures/index.android.ts

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -63,32 +63,23 @@ function initializeTapAndDoubleTapGestureListener() {
6363

6464
public onLongPress(motionEvent: android.view.MotionEvent): void {
6565
if (this._type & GestureTypes.longPress && this._observer?.callback) {
66-
new DOMEvent('longPress').dispatchTo({
67-
target: this._target,
68-
data: _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent),
69-
});
66+
new DOMEvent('longPress').dispatchTo(this._target, _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent));
7067
}
7168
}
7269

7370
private _handleSingleTap(motionEvent: android.view.MotionEvent): void {
7471
if (this._target.getGestureObservers(GestureTypes.doubleTap).length) {
7572
this._tapTimeoutId = timer.setTimeout(() => {
7673
if (this._type & GestureTypes.tap && this._observer?.callback) {
77-
new DOMEvent('tap').dispatchTo({
78-
target: this._target,
79-
data: _getTapArgs(GestureTypes.tap, this._target, motionEvent),
80-
});
74+
new DOMEvent('tap').dispatchTo(this._target, _getTapArgs(GestureTypes.tap, this._target, motionEvent));
8175
}
8276
timer.clearTimeout(this._tapTimeoutId);
8377
}, TapAndDoubleTapGestureListenerImpl.DoubleTapTimeout);
8478
return;
8579
}
8680

8781
if (this._type & GestureTypes.tap && this._observer?.callback) {
88-
new DOMEvent('tap').dispatchTo({
89-
target: this._target,
90-
data: _getTapArgs(GestureTypes.tap, this._target, motionEvent),
91-
});
82+
new DOMEvent('tap').dispatchTo(this._target, _getTapArgs(GestureTypes.tap, this._target, motionEvent));
9283
}
9384
}
9485

@@ -97,10 +88,7 @@ function initializeTapAndDoubleTapGestureListener() {
9788
timer.clearTimeout(this._tapTimeoutId);
9889
}
9990
if (this._type & GestureTypes.doubleTap && this._observer?.callback) {
100-
new DOMEvent('doubleTap').dispatchTo({
101-
target: this._target,
102-
data: _getTapArgs(GestureTypes.doubleTap, this._target, motionEvent),
103-
});
91+
new DOMEvent('doubleTap').dispatchTo(this._target, _getTapArgs(GestureTypes.doubleTap, this._target, motionEvent));
10492
}
10593
}
10694
}
@@ -137,10 +125,7 @@ function initializePinchGestureListener() {
137125
this._scale = detector.getScaleFactor();
138126

139127
if (this._observer?.callback) {
140-
new DOMEvent('pinch').dispatchTo({
141-
target: this._target,
142-
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.began),
143-
});
128+
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.began));
144129
}
145130

146131
return true;
@@ -150,10 +135,7 @@ function initializePinchGestureListener() {
150135
this._scale *= detector.getScaleFactor();
151136

152137
if (this._observer?.callback) {
153-
new DOMEvent('pinch').dispatchTo({
154-
target: this._target,
155-
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.changed),
156-
});
138+
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.changed));
157139
}
158140

159141
return true;
@@ -163,10 +145,7 @@ function initializePinchGestureListener() {
163145
this._scale *= detector.getScaleFactor();
164146

165147
if (this._observer?.callback) {
166-
new DOMEvent('pinch').dispatchTo({
167-
target: this._target,
168-
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.ended),
169-
});
148+
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.ended));
170149
}
171150
}
172151
}
@@ -212,19 +191,13 @@ function initializeSwipeGestureListener() {
212191
if (Math.abs(deltaX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
213192
if (deltaX > 0) {
214193
if (this._observer?.callback) {
215-
new DOMEvent('swipe').dispatchTo({
216-
target: this._target,
217-
data: _getSwipeArgs(SwipeDirection.right, this._target, initialEvent, currentEvent),
218-
});
194+
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.right, this._target, initialEvent, currentEvent));
219195
}
220196

221197
result = true;
222198
} else {
223199
if (this._observer?.callback) {
224-
new DOMEvent('swipe').dispatchTo({
225-
target: this._target,
226-
data: _getSwipeArgs(SwipeDirection.left, this._target, initialEvent, currentEvent),
227-
});
200+
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.left, this._target, initialEvent, currentEvent));
228201
}
229202
result = true;
230203
}
@@ -233,18 +206,12 @@ function initializeSwipeGestureListener() {
233206
if (Math.abs(deltaY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
234207
if (deltaY > 0) {
235208
if (this._observer?.callback) {
236-
new DOMEvent('swipe').dispatchTo({
237-
target: this._target,
238-
data: _getSwipeArgs(SwipeDirection.down, this._target, initialEvent, currentEvent),
239-
});
209+
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.down, this._target, initialEvent, currentEvent));
240210
}
241211
result = true;
242212
} else {
243213
if (this._observer?.callback) {
244-
new DOMEvent('swipe').dispatchTo({
245-
target: this._target,
246-
data: _getSwipeArgs(SwipeDirection.up, this._target, initialEvent, currentEvent),
247-
});
214+
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.up, this._target, initialEvent, currentEvent));
248215
}
249216
result = true;
250217
}
@@ -372,10 +339,7 @@ export class GesturesObserver extends GesturesObserverBase {
372339
this._eventData.prepare(this.target, motionEvent);
373340

374341
if (this.callback) {
375-
new DOMEvent('touch').dispatchTo({
376-
target: this.target,
377-
data: this._eventData,
378-
});
342+
new DOMEvent('touch').dispatchTo(this.target, this._eventData);
379343
}
380344
}
381345

@@ -504,10 +468,7 @@ class CustomPanGestureDetector {
504468
private trackStop(currentEvent: android.view.MotionEvent, cacheEvent: boolean) {
505469
if (this.isTracking) {
506470
if (this.observer?.callback) {
507-
new DOMEvent('pan').dispatchTo({
508-
target: this.target,
509-
data: _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.ended, null, currentEvent),
510-
});
471+
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.ended, null, currentEvent));
511472
}
512473

513474
this.deltaX = undefined;
@@ -529,10 +490,7 @@ class CustomPanGestureDetector {
529490
this.isTracking = true;
530491

531492
if (this.observer?.callback) {
532-
new DOMEvent('pan').dispatchTo({
533-
target: this.target,
534-
data: _getPanArgs(0, 0, this.target, GestureStateTypes.began, null, currentEvent),
535-
});
493+
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(0, 0, this.target, GestureStateTypes.began, null, currentEvent));
536494
}
537495
}
538496

@@ -542,10 +500,7 @@ class CustomPanGestureDetector {
542500
this.deltaY = current.y - this.initialY;
543501

544502
if (this.observer?.callback) {
545-
new DOMEvent('pan').dispatchTo({
546-
target: this.target,
547-
data: _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.changed, null, currentEvent),
548-
});
503+
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.changed, null, currentEvent));
549504
}
550505
}
551506

@@ -665,10 +620,7 @@ class CustomRotateGestureDetector {
665620
};
666621

667622
if (this.observer?.callback) {
668-
new DOMEvent('rotation').dispatchTo({
669-
target: this.target,
670-
data: args,
671-
});
623+
new DOMEvent('rotation').dispatchTo(this.target, args);
672624
}
673625
}
674626

0 commit comments

Comments
 (0)