Skip to content

fix(core): Added missing parameter for once event listeners #10715

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/data/observable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ export class Observable {
* @param eventName Name of the event to attach to.
* @param callback A function to be called when some of the specified event(s) is raised.
* @param thisArg An optional parameter which when set will be used as "this" in callback method call.
* @param once An optional parameter which when set will cause the event listener to fire once.
*/
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
once = once || undefined;
Expand Down
4 changes: 2 additions & 2 deletions packages/core/media-query-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ class MediaQueryListImpl extends Observable implements MediaQueryList {
}

// @ts-ignore
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any): void {
public addEventListener(eventName: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
this._throwInvocationError?.();

const hasChangeListeners = this.hasListeners(MediaQueryListImpl.changeEvent);

// Call super method first since it throws in the case of bad parameters
super.addEventListener(eventName, callback, thisArg);
super.addEventListener(eventName, callback, thisArg, once);

if (eventName === MediaQueryListImpl.changeEvent && !hasChangeListeners) {
mediaQueryLists.push(this);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ export class View extends ViewCommon {
}
}

addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
super.addEventListener(eventNames, callback, thisArg);
addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean) {
super.addEventListener(eventNames, callback, thisArg, once);
const isLayoutEvent = typeof eventNames === 'string' ? eventNames.indexOf(ViewCommon.layoutChangedEvent) !== -1 : false;

if (this.isLoaded && !this.layoutChangeListenerIsSet && isLayoutEvent) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/core/view/view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return this._gestureObservers[type];
}

public addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any) {
public addEventListener(eventNames: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean) {
thisArg = thisArg || undefined;

// TODO: Remove this once we fully switch to the new event system
Expand All @@ -330,7 +330,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
return;
}

super.addEventListener(normalizedName, callback, thisArg);
super.addEventListener(normalizedName, callback, thisArg, once);
}

public removeEventListener(eventNames: string, callback?: (data: EventData) => void, thisArg?: any) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/scroll-view/scroll-view-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export abstract class ScrollViewBase extends ContentView implements ScrollViewDe

private _addedScrollEvent = false;

public addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any): void {
public addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
const hasExistingScrollListeners: boolean = this.hasListeners(ScrollViewBase.scrollEvent);

super.addEventListener(arg, callback, thisArg);
super.addEventListener(arg, callback, thisArg, once);

// This indicates that a scroll listener was added for first time
if (!hasExistingScrollListeners && this.hasListeners(ScrollViewBase.scrollEvent)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/text-base/span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ export class Span extends ViewBase implements SpanDefinition {
return this._tappable;
}

addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any): void {
super.addEventListener(arg, callback, thisArg);
addEventListener(arg: string, callback: (data: EventData) => void, thisArg?: any, once?: boolean): void {
super.addEventListener(arg, callback, thisArg, once);
this._setTappable(this.hasListeners(Span.linkTapEvent));
}

Expand Down