diff --git a/packages/core/abortcontroller/abortsignal.ts b/packages/core/abortcontroller/abortsignal.ts index 07d0c3d8a..24a4ab89d 100644 --- a/packages/core/abortcontroller/abortsignal.ts +++ b/packages/core/abortcontroller/abortsignal.ts @@ -1,4 +1,3 @@ - import { Observable } from '../data/observable'; // Known Limitation @@ -6,75 +5,71 @@ import { Observable } from '../data/observable'; // to make assignable our `AbortSignal` into that. // https://github.com/Microsoft/TSJS-lib-generator/pull/623 type Events = { - abort: any // Event & Type<"abort"> -} + abort: any; // Event & Type<"abort"> +}; type EventAttributes = { - onabort: any // Event & Type<"abort"> -} + onabort: any; // Event & Type<"abort"> +}; /** * The signal class. * @see https://dom.spec.whatwg.org/#abortsignal */ export default class AbortSignal extends Observable { - /** - * AbortSignal cannot be constructed directly. - */ - public constructor() { - super() - } + /** + * AbortSignal cannot be constructed directly. + */ + public constructor() { + super(); + } - /** - * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise. - */ - public get aborted(): boolean { - const aborted = abortedFlags.get(this) - if (typeof aborted !== "boolean") { - throw new TypeError( - `Expected 'this' to be an 'AbortSignal' object, but got ${ - this === null ? "null" : typeof this - }`, - ) - } - return aborted - } + /** + * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise. + */ + public get aborted(): boolean { + const aborted = abortedFlags.get(this); + if (typeof aborted !== 'boolean') { + throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? 'null' : typeof this}`); + } + return aborted; + } } /** * Create an AbortSignal object. */ export function createAbortSignal(): AbortSignal { - const signal = new AbortSignal(); - abortedFlags.set(signal, false) - return signal + const signal = new AbortSignal(); + abortedFlags.set(signal, false); + return signal; } /** * Abort a given signal. */ export function abortSignal(signal: AbortSignal): void { - if (abortedFlags.get(signal) !== false) { - return - } + if (abortedFlags.get(signal) !== false) { + return; + } - abortedFlags.set(signal, true) - signal.notify({ eventName: "abort", type: "abort" }) + abortedFlags.set(signal, true); + signal.notify({ eventName: 'abort', type: 'abort', object: this }); } /** * Aborted flag for each instances. */ -const abortedFlags = new WeakMap() +const abortedFlags = new WeakMap(); // Properties should be enumerable. Object.defineProperties(AbortSignal.prototype, { - aborted: { enumerable: true }, -}) + aborted: { enumerable: true }, +}); // `toString()` should return `"[object AbortSignal]"` -if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") { - Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, { - configurable: true, - value: "AbortSignal", - }) -} \ No newline at end of file +if (typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol') { + Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, { + configurable: true, + value: 'AbortSignal', + }); +} diff --git a/packages/core/accessibility/accessibility-common.ts b/packages/core/accessibility/accessibility-common.ts index 4d5cff4e9..7ca9cdfd9 100644 --- a/packages/core/accessibility/accessibility-common.ts +++ b/packages/core/accessibility/accessibility-common.ts @@ -19,7 +19,7 @@ export const accessibilityPerformEscapeEvent = 'accessibilityPerformEscape'; * @param {boolean} receivedFocus * @param {boolean} lostFocus */ -export function notifyAccessibilityFocusState(view: Partial, receivedFocus: boolean, lostFocus: boolean): void { +export function notifyAccessibilityFocusState(view: View, receivedFocus: boolean, lostFocus: boolean): void { if (!receivedFocus && !lostFocus) { return; } diff --git a/packages/core/accessibility/index.android.ts b/packages/core/accessibility/index.android.ts index cae004e42..29431eeee 100644 --- a/packages/core/accessibility/index.android.ts +++ b/packages/core/accessibility/index.android.ts @@ -14,8 +14,8 @@ export * from './font-scale'; let clickableRolesMap = new Set(); -let lastFocusedView: WeakRef>; -function accessibilityEventHelper(view: Partial, eventType: number) { +let lastFocusedView: WeakRef; +function accessibilityEventHelper(view: View, eventType: number) { const eventName = accessibilityEventTypeMap.get(eventType); if (!isAccessibilityServiceEnabled()) { if (Trace.isEnabled()) { @@ -105,7 +105,7 @@ function accessibilityEventHelper(view: Partial, eventType: number) { let TNSAccessibilityDelegate: android.view.View.androidviewViewAccessibilityDelegate; -const androidViewToTNSView = new WeakMap>>(); +const androidViewToTNSView = new WeakMap>(); let accessibilityEventMap: Map; let accessibilityEventTypeMap: Map; @@ -440,11 +440,11 @@ export function isAccessibilityServiceEnabled(): boolean { return accessibilityServiceEnabled; } -export function setupAccessibleView(view: Partial): void { +export function setupAccessibleView(view: View): void { updateAccessibilityProperties(view); } -export function updateAccessibilityProperties(view: Partial): void { +export function updateAccessibilityProperties(view: View): void { if (!view.nativeViewProtected) { return; } @@ -540,7 +540,7 @@ export function updateContentDescription(view: View, forceUpdate?: boolean): str return applyContentDescription(view, forceUpdate); } -function setAccessibilityDelegate(view: Partial): void { +function setAccessibilityDelegate(view: View): void { if (!view.nativeViewProtected) { return; } @@ -566,7 +566,7 @@ function setAccessibilityDelegate(view: Partial): void { androidView.setAccessibilityDelegate(TNSAccessibilityDelegate); } -function applyContentDescription(view: Partial, forceUpdate?: boolean) { +function applyContentDescription(view: View, forceUpdate?: boolean) { let androidView = view.nativeViewProtected as android.view.View; if (!androidView || (androidView instanceof android.widget.TextView && !view._androidContentDescriptionUpdated)) { return null; diff --git a/packages/core/accessibility/index.d.ts b/packages/core/accessibility/index.d.ts index 2a3e78307..cb7a9d825 100644 --- a/packages/core/accessibility/index.d.ts +++ b/packages/core/accessibility/index.d.ts @@ -9,7 +9,7 @@ export * from './font-scale'; /** * Initialize accessibility for View. This should be called on loaded-event. */ -export function setupAccessibleView(view: Partial): void; +export function setupAccessibleView(view: View): void; /** * Update accessibility properties on nativeView diff --git a/packages/core/data/observable/index.ts b/packages/core/data/observable/index.ts index 1de1b6746..c400f0fc5 100644 --- a/packages/core/data/observable/index.ts +++ b/packages/core/data/observable/index.ts @@ -3,23 +3,39 @@ import { DOMEvent } from '../dom-events/dom-event'; import { Observable as ObservableDefinition, WrappedValue as WrappedValueDefinition } from '.'; +/** + * Base event data. + */ export interface EventData { + /** + * The name of the event. + */ eventName: string; - object: Partial; + /** + * The Observable instance that has raised the event. + */ + object: Observable; } export interface EventDataValue extends EventData { value?: boolean; } -export interface NotifyData extends Partial { - eventName: string; - object?: Partial; -} - +/** + * Data for the "propertyChange" event. + */ export interface PropertyChangeData extends EventData { + /** + * The name of the property that has changed. + */ propertyName: string; + /** + * The new value of the property. + */ value: any; + /** + * The previous value of the property. + */ oldValue?: any; } @@ -288,18 +304,12 @@ export class Observable implements ObservableDefinition { * @param data The data associated with the event. * @param options Options for the event, in line with DOM Standard. */ - public notify(data: T, options?: CustomEventInit): void { - data.object = data.object || this; - - // Now that we've filled in the `object` field (that was optional in - // NotifyData), `data` can be treated as EventData. - const eventData = data as EventData; - + public notify(data: T, options?: CustomEventInit): void { new DOMEvent(data.eventName, options).dispatchTo({ target: this, - data: eventData, - getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(eventData, 'First'), - getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(eventData, ''), + data, + getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(data, 'First'), + getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(data, ''), }); } diff --git a/packages/core/ui/core/view/view-helper/index.d.ts b/packages/core/ui/core/view/view-helper/index.d.ts index 213f91596..0635b7415 100644 --- a/packages/core/ui/core/view/view-helper/index.d.ts +++ b/packages/core/ui/core/view/view-helper/index.d.ts @@ -46,21 +46,21 @@ export namespace IOSHelper { * Returns a view with viewController or undefined if no such found along the view's parent chain. * @param view The view form which to start the search. */ - export function getParentWithViewController(view: Partial): View; - export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: Partial): void; - export function updateConstraints(controller: any /* UIViewController */, owner: Partial): void; - export function layoutView(controller: any /* UIViewController */, owner: Partial): void; + export function getParentWithViewController(view: View): View; + export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void; + export function updateConstraints(controller: any /* UIViewController */, owner: View): void; + export function layoutView(controller: any /* UIViewController */, owner: View): void; export function getPositionFromFrame(frame: any /* CGRect */): { left; top; right; bottom }; export function getFrameFromPosition(position: { left; top; right; bottom }, insets?: { left; top; right; bottom }): any; /* CGRect */ - export function shrinkToSafeArea(view: Partial, frame: any /* CGRect */): any; /* CGRect */ - export function expandBeyondSafeArea(view: Partial, frame: any /* CGRect */): any; /* CGRect */ + export function shrinkToSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */ + export function expandBeyondSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */ export class UILayoutViewController { - public static initWithOwner(owner: WeakRef>): UILayoutViewController; + public static initWithOwner(owner: WeakRef): UILayoutViewController; } export class UIAdaptivePresentationControllerDelegateImp { - public static initWithOwnerAndCallback(owner: WeakRef>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp; + public static initWithOwnerAndCallback(owner: WeakRef, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp; } export class UIPopoverPresentationControllerDelegateImp { - public static initWithOwnerAndCallback(owner: WeakRef>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp; + public static initWithOwnerAndCallback(owner: WeakRef, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp; } } diff --git a/packages/core/ui/core/weak-event-listener/index.ts b/packages/core/ui/core/weak-event-listener/index.ts index 7b419826a..f487786b5 100644 --- a/packages/core/ui/core/weak-event-listener/index.ts +++ b/packages/core/ui/core/weak-event-listener/index.ts @@ -1,7 +1,7 @@ import { Observable, EventData } from '../../../data/observable'; const handlersForEventName = new Map void>(); -const sourcesMap = new WeakMap, Map>>(); +const sourcesMap = new WeakMap>>(); class TargetHandlerPair { tagetRef: WeakRef; diff --git a/packages/core/ui/editable-text-base/index.android.ts b/packages/core/ui/editable-text-base/index.android.ts index 4c090a054..546d797b8 100644 --- a/packages/core/ui/editable-text-base/index.android.ts +++ b/packages/core/ui/editable-text-base/index.android.ts @@ -533,6 +533,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon { this.notify({ eventName: EditableTextBase.blurEvent, + object: this, }); dismissSoftInput(this); } diff --git a/packages/core/ui/gestures/index.d.ts b/packages/core/ui/gestures/index.d.ts index 52a92f948..157db988a 100644 --- a/packages/core/ui/gestures/index.d.ts +++ b/packages/core/ui/gestures/index.d.ts @@ -140,7 +140,7 @@ export interface GestureEventData extends EventData { /** * Gets the view which originates the gesture. */ - view: Partial; + view: View; /** * Gets the underlying native iOS specific [UIGestureRecognizer](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/). */ @@ -287,7 +287,7 @@ export class GesturesObserver { * @param callback - A function that will be executed when a gesture is received. * @param context - default this argument for the callbacks. */ - constructor(target: Partial, callback: (args: GestureEventData) => void, context: any); + constructor(target: View, callback: (args: GestureEventData) => void, context: any); /** * Registers a gesture observer to a view and gesture.