Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b8d50fa

Browse filesBrowse files
committed
fix: simplify EventData typings, drop NotifyData
1 parent 679ef96 commit b8d50fa
Copy full SHA for b8d50fa

File tree

Expand file treeCollapse file tree

9 files changed

+85
-75
lines changed
Filter options
Expand file treeCollapse file tree

9 files changed

+85
-75
lines changed
+37-42Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,75 @@
1-
21
import { Observable } from '../data/observable';
32

43
// Known Limitation
54
// Use `any` because the type of `AbortSignal` in `lib.dom.d.ts` is wrong and
65
// to make assignable our `AbortSignal` into that.
76
// https://github.com/Microsoft/TSJS-lib-generator/pull/623
87
type Events = {
9-
abort: any // Event & Type<"abort">
10-
}
8+
abort: any; // Event & Type<"abort">
9+
};
1110
type EventAttributes = {
12-
onabort: any // Event & Type<"abort">
13-
}
11+
onabort: any; // Event & Type<"abort">
12+
};
1413

1514
/**
1615
* The signal class.
1716
* @see https://dom.spec.whatwg.org/#abortsignal
1817
*/
1918
export default class AbortSignal extends Observable {
20-
/**
21-
* AbortSignal cannot be constructed directly.
22-
*/
23-
public constructor() {
24-
super()
25-
}
19+
/**
20+
* AbortSignal cannot be constructed directly.
21+
*/
22+
public constructor() {
23+
super();
24+
}
2625

27-
/**
28-
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
29-
*/
30-
public get aborted(): boolean {
31-
const aborted = abortedFlags.get(this)
32-
if (typeof aborted !== "boolean") {
33-
throw new TypeError(
34-
`Expected 'this' to be an 'AbortSignal' object, but got ${
35-
this === null ? "null" : typeof this
36-
}`,
37-
)
38-
}
39-
return aborted
40-
}
26+
/**
27+
* Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
28+
*/
29+
public get aborted(): boolean {
30+
const aborted = abortedFlags.get(this);
31+
if (typeof aborted !== 'boolean') {
32+
throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? 'null' : typeof this}`);
33+
}
34+
return aborted;
35+
}
4136
}
4237

4338
/**
4439
* Create an AbortSignal object.
4540
*/
4641
export function createAbortSignal(): AbortSignal {
47-
const signal = new AbortSignal();
48-
abortedFlags.set(signal, false)
49-
return signal
42+
const signal = new AbortSignal();
43+
abortedFlags.set(signal, false);
44+
return signal;
5045
}
5146

5247
/**
5348
* Abort a given signal.
5449
*/
5550
export function abortSignal(signal: AbortSignal): void {
56-
if (abortedFlags.get(signal) !== false) {
57-
return
58-
}
51+
if (abortedFlags.get(signal) !== false) {
52+
return;
53+
}
5954

60-
abortedFlags.set(signal, true)
61-
signal.notify({ eventName: "abort", type: "abort" })
55+
abortedFlags.set(signal, true);
56+
signal.notify({ eventName: 'abort', type: 'abort', object: this });
6257
}
6358

6459
/**
6560
* Aborted flag for each instances.
6661
*/
67-
const abortedFlags = new WeakMap<AbortSignal, boolean>()
62+
const abortedFlags = new WeakMap<AbortSignal, boolean>();
6863

6964
// Properties should be enumerable.
7065
Object.defineProperties(AbortSignal.prototype, {
71-
aborted: { enumerable: true },
72-
})
66+
aborted: { enumerable: true },
67+
});
7368

7469
// `toString()` should return `"[object AbortSignal]"`
75-
if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
76-
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
77-
configurable: true,
78-
value: "AbortSignal",
79-
})
80-
}
70+
if (typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol') {
71+
Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
72+
configurable: true,
73+
value: 'AbortSignal',
74+
});
75+
}

‎packages/core/accessibility/accessibility-common.ts

Copy file name to clipboardExpand all lines: packages/core/accessibility/accessibility-common.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const accessibilityPerformEscapeEvent = 'accessibilityPerformEscape';
1919
* @param {boolean} receivedFocus
2020
* @param {boolean} lostFocus
2121
*/
22-
export function notifyAccessibilityFocusState(view: Partial<View>, receivedFocus: boolean, lostFocus: boolean): void {
22+
export function notifyAccessibilityFocusState(view: View, receivedFocus: boolean, lostFocus: boolean): void {
2323
if (!receivedFocus && !lostFocus) {
2424
return;
2525
}

‎packages/core/accessibility/index.android.ts

Copy file name to clipboardExpand all lines: packages/core/accessibility/index.android.ts
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export * from './font-scale';
1313

1414
let clickableRolesMap = new Set<string>();
1515

16-
let lastFocusedView: WeakRef<Partial<View>>;
17-
function accessibilityEventHelper(view: Partial<View>, eventType: number) {
16+
let lastFocusedView: WeakRef<View>;
17+
function accessibilityEventHelper(view: View, eventType: number) {
1818
const eventName = accessibilityEventTypeMap.get(eventType);
1919
if (!isAccessibilityServiceEnabled()) {
2020
if (Trace.isEnabled()) {
@@ -103,7 +103,7 @@ function accessibilityEventHelper(view: Partial<View>, eventType: number) {
103103

104104
let TNSAccessibilityDelegate: android.view.View.androidviewViewAccessibilityDelegate;
105105

106-
const androidViewToTNSView = new WeakMap<android.view.View, WeakRef<Partial<View>>>();
106+
const androidViewToTNSView = new WeakMap<android.view.View, WeakRef<View>>();
107107

108108
let accessibilityEventMap: Map<AndroidAccessibilityEvent, number>;
109109
let accessibilityEventTypeMap: Map<number, string>;
@@ -438,11 +438,11 @@ export function isAccessibilityServiceEnabled(): boolean {
438438
return accessibilityServiceEnabled;
439439
}
440440

441-
export function setupAccessibleView(view: Partial<View>): void {
441+
export function setupAccessibleView(view: View): void {
442442
updateAccessibilityProperties(view);
443443
}
444444

445-
export function updateAccessibilityProperties(view: Partial<View>): void {
445+
export function updateAccessibilityProperties(view: View): void {
446446
if (!view.nativeViewProtected) {
447447
return;
448448
}
@@ -538,7 +538,7 @@ export function updateContentDescription(view: View, forceUpdate?: boolean): str
538538
return applyContentDescription(view, forceUpdate);
539539
}
540540

541-
function setAccessibilityDelegate(view: Partial<View>): void {
541+
function setAccessibilityDelegate(view: View): void {
542542
if (!view.nativeViewProtected) {
543543
return;
544544
}
@@ -564,7 +564,7 @@ function setAccessibilityDelegate(view: Partial<View>): void {
564564
androidView.setAccessibilityDelegate(TNSAccessibilityDelegate);
565565
}
566566

567-
function applyContentDescription(view: Partial<View>, forceUpdate?: boolean) {
567+
function applyContentDescription(view: View, forceUpdate?: boolean) {
568568
let androidView = view.nativeViewProtected as android.view.View;
569569
if (!androidView || (androidView instanceof android.widget.TextView && !view._androidContentDescriptionUpdated)) {
570570
return null;

‎packages/core/accessibility/index.d.ts

Copy file name to clipboardExpand all lines: packages/core/accessibility/index.d.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export * from './font-scale';
99
/**
1010
* Initialize accessibility for View. This should be called on loaded-event.
1111
*/
12-
export function setupAccessibleView(view: Partial<View>): void;
12+
export function setupAccessibleView(view: View): void;
1313

1414
/**
1515
* Update accessibility properties on nativeView

‎packages/core/data/observable/index.ts

Copy file name to clipboardExpand all lines: packages/core/data/observable/index.ts
+26-12Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
import { Observable as ObservableDefinition, WrappedValue as WrappedValueDefinition } from '.';
22

3+
/**
4+
* Base event data.
5+
*/
36
export interface EventData {
7+
/**
8+
* The name of the event.
9+
*/
410
eventName: string;
5-
object: Partial<Observable>;
11+
/**
12+
* The Observable instance that has raised the event.
13+
*/
14+
object: Observable;
615
}
716

817
export interface EventDataValue extends EventData {
918
value?: boolean;
1019
}
1120

12-
export interface NotifyData extends Partial<EventData> {
13-
eventName: string;
14-
object?: Partial<Observable>;
15-
}
16-
21+
/**
22+
* Data for the "propertyChange" event.
23+
*/
1724
export interface PropertyChangeData extends EventData {
25+
/**
26+
* The name of the property that has changed.
27+
*/
1828
propertyName: string;
29+
/**
30+
* The new value of the property.
31+
*/
1932
value: any;
33+
/**
34+
* The previous value of the property.
35+
*/
2036
oldValue?: any;
2137
}
2238

@@ -271,18 +287,16 @@ export class Observable implements ObservableDefinition {
271287
}
272288
}
273289

274-
public notify<T extends NotifyData>(data: T): void {
275-
const eventData = data as EventData;
276-
eventData.object = eventData.object || this;
290+
public notify<T extends EventData>(data: T): void {
277291
const eventClass = this.constructor.name;
278-
this._globalNotify(eventClass, 'First', eventData);
292+
this._globalNotify(eventClass, 'First', data);
279293

280294
const observers = <Array<ListenerEntry>>this._observers[data.eventName];
281295
if (observers) {
282-
Observable._handleEvent(observers, eventData);
296+
Observable._handleEvent(observers, data);
283297
}
284298

285-
this._globalNotify(eventClass, '', eventData);
299+
this._globalNotify(eventClass, '', data);
286300
}
287301

288302
private static _handleEvent<T extends EventData>(observers: Array<ListenerEntry>, data: T): void {

‎packages/core/ui/core/view/view-helper/index.d.ts

Copy file name to clipboardExpand all lines: packages/core/ui/core/view/view-helper/index.d.ts
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ export namespace IOSHelper {
4646
* Returns a view with viewController or undefined if no such found along the view's parent chain.
4747
* @param view The view form which to start the search.
4848
*/
49-
export function getParentWithViewController(view: Partial<View>): View;
50-
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: Partial<View>): void;
51-
export function updateConstraints(controller: any /* UIViewController */, owner: Partial<View>): void;
52-
export function layoutView(controller: any /* UIViewController */, owner: Partial<View>): void;
49+
export function getParentWithViewController(view: View): View;
50+
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void;
51+
export function updateConstraints(controller: any /* UIViewController */, owner: View): void;
52+
export function layoutView(controller: any /* UIViewController */, owner: View): void;
5353
export function getPositionFromFrame(frame: any /* CGRect */): { left; top; right; bottom };
5454
export function getFrameFromPosition(position: { left; top; right; bottom }, insets?: { left; top; right; bottom }): any; /* CGRect */
55-
export function shrinkToSafeArea(view: Partial<View>, frame: any /* CGRect */): any; /* CGRect */
56-
export function expandBeyondSafeArea(view: Partial<View>, frame: any /* CGRect */): any; /* CGRect */
55+
export function shrinkToSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */
56+
export function expandBeyondSafeArea(view: View, frame: any /* CGRect */): any; /* CGRect */
5757
export class UILayoutViewController {
58-
public static initWithOwner(owner: WeakRef<Partial<View>>): UILayoutViewController;
58+
public static initWithOwner(owner: WeakRef<View>): UILayoutViewController;
5959
}
6060
export class UIAdaptivePresentationControllerDelegateImp {
61-
public static initWithOwnerAndCallback(owner: WeakRef<Partial<View>>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp;
61+
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIAdaptivePresentationControllerDelegateImp;
6262
}
6363
export class UIPopoverPresentationControllerDelegateImp {
64-
public static initWithOwnerAndCallback(owner: WeakRef<Partial<View>>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp;
64+
public static initWithOwnerAndCallback(owner: WeakRef<View>, whenClosedCallback: Function): UIPopoverPresentationControllerDelegateImp;
6565
}
6666
}

‎packages/core/ui/core/weak-event-listener/index.ts

Copy file name to clipboardExpand all lines: packages/core/ui/core/weak-event-listener/index.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Observable, EventData } from '../../../data/observable';
22

33
const handlersForEventName = new Map<string, (eventData: EventData) => void>();
4-
const sourcesMap = new WeakMap<Partial<Observable>, Map<string, Array<TargetHandlerPair>>>();
4+
const sourcesMap = new WeakMap<Observable, Map<string, Array<TargetHandlerPair>>>();
55

66
class TargetHandlerPair {
77
tagetRef: WeakRef<Object>;

‎packages/core/ui/editable-text-base/index.android.ts

Copy file name to clipboardExpand all lines: packages/core/ui/editable-text-base/index.android.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
533533

534534
this.notify({
535535
eventName: EditableTextBase.blurEvent,
536+
object: this,
536537
});
537538
dismissSoftInput(this);
538539
}

‎packages/core/ui/gestures/index.d.ts

Copy file name to clipboardExpand all lines: packages/core/ui/gestures/index.d.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export interface GestureEventData extends EventData {
140140
/**
141141
* Gets the view which originates the gesture.
142142
*/
143-
view: Partial<View>;
143+
view: View;
144144
/**
145145
* Gets the underlying native iOS specific [UIGestureRecognizer](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/).
146146
*/
@@ -287,7 +287,7 @@ export class GesturesObserver {
287287
* @param callback - A function that will be executed when a gesture is received.
288288
* @param context - default this argument for the callbacks.
289289
*/
290-
constructor(target: Partial<View>, callback: (args: GestureEventData) => void, context: any);
290+
constructor(target: View, callback: (args: GestureEventData) => void, context: any);
291291

292292
/**
293293
* Registers a gesture observer to a view and gesture.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.