Skip to content

chore: generic EventData type for object property #10489

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion packages/core/application/application-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface ApplicationEventData {
/**
* Event data containing information for launch event.
*/
export interface LaunchEventData extends EventData {
export interface LaunchEventData extends EventData<ApplicationCommon> {
/**
* The root view for this Window on iOS or Activity for Android.
* If not set a new Frame will be created as a root view in order to maintain backwards compatibility.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/data/observable-array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class ChangeType {
/**
* Event args for "changed" event.
*/
export interface ChangedData<T> extends EventData {
export interface ChangedData<T, U = Observable> extends EventData<U> {
/**
* Change type.
*/
Expand Down
16 changes: 8 additions & 8 deletions packages/core/data/observable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { Optional } from '../../utils/typescript-utils';
/**
* Base event data.
*/
export interface EventData {
export interface EventData<T = Observable> {
/**
* The name of the event.
*/
eventName: string;
/**
* The Observable instance that has raised the event.
*/
object: Observable;
object: T;
}

export interface EventDataValue extends EventData {
export interface EventDataValue<T = Observable> extends EventData<T> {
value?: boolean;
}

/**
* Data for the "propertyChange" event.
*/
export interface PropertyChangeData extends EventData {
export interface PropertyChangeData<T = Observable> extends EventData<T> {
/**
* The name of the property that has changed.
*/
Expand All @@ -36,8 +36,8 @@ export interface PropertyChangeData extends EventData {
oldValue?: any;
}

interface ListenerEntry {
callback: (data: EventData) => void;
interface ListenerEntry<T = Observable> {
callback: (data: EventData<T>) => void;
thisArg: any;
once?: true;
}
Expand Down Expand Up @@ -106,7 +106,7 @@ export class Observable {
*/
public _isViewBase: boolean;

private readonly _observers: { [eventName: string]: ListenerEntry[] } = {};
private readonly _observers: { [eventName: string]: ListenerEntry<any>[] } = {};

/**
* Gets the value of the specified property.
Expand Down Expand Up @@ -465,7 +465,7 @@ export class Observable {
return list;
}

private static _indexOfListener(list: Array<ListenerEntry>, callback: (data: EventData) => void, thisArg?: any): number {
private static _indexOfListener<T = Observable>(list: Array<ListenerEntry<T>>, callback: (data: EventData<T>) => void, thisArg?: any): number {
for (let i = 0; i < list.length; i++) {
const entry = list[i];
if (thisArg) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/data/virtual-array/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChangedData, ChangeType } from '../observable-array';
/**
* Event args for "itemsLoading" event.
*/
export interface ItemsLoading extends EventData {
export interface ItemsLoading<T = Observable> extends EventData<T> {
/**
* Start index.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/core/ui/gestures/gestures-common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { GesturesObserver as GesturesObserverDefinition } from '.';
import type { View } from '../core/view';
import type { EventData } from '../../data/observable';
import type { EventData, Observable } from '../../data/observable';

export * from './touch-manager';

Expand Down Expand Up @@ -133,7 +133,7 @@ export enum TouchAction {
/**
* Provides gesture event data.
*/
export interface GestureEventData extends EventData {
export interface GestureEventData<T = Observable> extends EventData<T> {
/**
* Gets the type of the gesture.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ui/page/page-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ActionBar } from '../action-bar';
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
import { profile } from '../../profiling';

interface NavigatedData extends EventData {
interface NavigatedData extends EventData<PageDefinition> {
context: any;
isBackNavigation: boolean;
}
Expand Down
3 changes: 2 additions & 1 deletion packages/core/ui/placeholder/placeholder-common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Placeholder } from '.';
import { EventData } from '../../data/observable';

export interface CreateViewEventData extends EventData {
export interface CreateViewEventData extends EventData<Placeholder> {
/**
* The native view that should be added to the visual tree.
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/core/ui/web-view/web-view-interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { WebView } from '.';
import { EventData } from '../../data/observable';
import { EventData, Observable } from '../../data/observable';
import type { WebViewBase } from './web-view-common';

export type WebViewNavigationType = 'linkClicked' | 'formSubmitted' | 'backForward' | 'reload' | 'formResubmitted' | 'other' | undefined;

export interface LoadEventData extends EventData {
export interface LoadEventData<T = WebViewBase> extends EventData<T> {
url: string;
navigationType: WebViewNavigationType;
error: string;
Expand Down