Skip to content

Commit

Permalink
remove duplicate class members
Browse files Browse the repository at this point in the history
Summary:
Flow currently allows duplicate members on classes. At runtime the "last" member wins out and all previous values for the member are discarded.
This diff manually removes duplicate members, and fixes resulting flow errors by converting methods to arrow function properties.

Reviewed By: pieterv

Differential Revision: D33664966

fbshipit-source-id: 0f712ac96af4df593c0918fcbadd70624ddde4a6
  • Loading branch information
bradzacher authored and facebook-github-bot committed Jan 19, 2022
1 parent b13e41d commit c0e489b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 37 deletions.
6 changes: 2 additions & 4 deletions Libraries/Animated/AnimatedEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ function validateMapping(argMapping, args) {
class AnimatedEvent {
_argMapping: $ReadOnlyArray<?Mapping>;
_listeners: Array<Function> = [];
_callListeners: Function;
_attachedEvent: ?{detach: () => void, ...};
__isNative: boolean;

Expand All @@ -160,7 +159,6 @@ class AnimatedEvent {
if (config.listener) {
this.__addListener(config.listener);
}
this._callListeners = this._callListeners.bind(this);
this._attachedEvent = null;
this.__isNative = shouldUseNativeDriver(config);
}
Expand Down Expand Up @@ -245,9 +243,9 @@ class AnimatedEvent {
};
}

_callListeners(...args: any) {
_callListeners = (...args: any) => {
this._listeners.forEach(listener => listener(...args));
}
};
}

module.exports = {AnimatedEvent, attachNativeEvent};
1 change: 0 additions & 1 deletion Libraries/Network/XMLHttpRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class XMLHttpRequest extends (EventTarget(...XHR_EVENTS): any) {
_lowerCaseResponseHeaders: Object;
_method: ?string = null;
_perfKey: ?string = null;
_response: string | ?Object;
_responseType: ResponseType;
_response: string = '';
_sent: boolean;
Expand Down
18 changes: 6 additions & 12 deletions packages/rn-tester/js/examples/AnimatedGratuitousApp/AnExApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,16 @@ const NUM_CIRCLES = 30;
class Circle extends React.Component<any, any> {
longTimer: number;

_onLongPress: () => void;
_toggleIsActive: () => void;
constructor(props: Object): void {
super();
this._onLongPress = this._onLongPress.bind(this);
this._toggleIsActive = this._toggleIsActive.bind(this);
this.state = {
isActive: false,
pan: new Animated.ValueXY(), // Vectors reduce boilerplate. (step1: uncomment)
pop: new Animated.Value(0), // Initial value. (step2a: uncomment)
};
}

_onLongPress(): void {
_onLongPress = (): void => {
const config = {tension: 40, friction: 3};
this.state.pan.addListener(value => {
// Async listener for state changes (step1: uncomment)
Expand Down Expand Up @@ -90,7 +86,7 @@ class Circle extends React.Component<any, any> {
this.props.onActivate();
},
);
}
};

render(): React.Node {
let handlers;
Expand Down Expand Up @@ -193,7 +189,7 @@ class Circle extends React.Component<any, any> {
</Animated.View>
);
}
_toggleIsActive(velocity) {
_toggleIsActive = velocity => {
const config = {tension: 30, friction: 7};
if (this.state.isActive) {
Animated.spring(this.props.openVal, {
Expand All @@ -215,11 +211,10 @@ class Circle extends React.Component<any, any> {
}).start(); // (step4: uncomment)
});
}
}
};
}

class AnExApp extends React.Component<any, any> {
_onMove: (position: Point) => void;
constructor(props: any): void {
super(props);
const keys = [];
Expand All @@ -231,7 +226,6 @@ class AnExApp extends React.Component<any, any> {
restLayouts: [],
openVal: new Animated.Value(0),
};
this._onMove = this._onMove.bind(this);
}

render(): React.Node {
Expand Down Expand Up @@ -297,13 +291,13 @@ class AnExApp extends React.Component<any, any> {
);
}

_onMove(position: Point): void {
_onMove = (position: Point): void => {
const newKeys = moveToClosest(this.state, position);
if (newKeys !== this.state.keys) {
LayoutAnimation.easeInEaseOut(); // animates layout update as one batch (step3: uncomment)
this.setState({keys: newKeys});
}
}
};
}

type Point = {
Expand Down
20 changes: 0 additions & 20 deletions packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,16 +339,6 @@ class MultipleSourcesExample extends React.Component<
});
};

increaseImageSize = () => {
if (this.state.width >= 100) {
return;
}
this.setState({
width: this.state.width + 10,
height: this.state.height + 10,
});
};

decreaseImageSize = () => {
if (this.state.width <= 10) {
return;
Expand Down Expand Up @@ -480,16 +470,6 @@ class OnLayoutExample extends React.Component<
});
};

increaseImageSize = () => {
if (this.state.width >= 100) {
return;
}
this.setState({
width: this.state.width + 10,
height: this.state.height + 10,
});
};

decreaseImageSize = () => {
if (this.state.width <= 10) {
return;
Expand Down

0 comments on commit c0e489b

Please sign in to comment.