Skip to content
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

[createReactClass, TimerMixin] remove createReactClass and TImerMixin from TimerTest.js #21748

Closed
wants to merge 3 commits into from

Conversation

ronal2do
Copy link
Contributor

@ronal2do ronal2do commented Oct 12, 2018

Related to #21485 (comment)
Remove createReactClass and TimerMixin from IntegrationTests/TimersTest.js

Test Plan:

Flow tests succeed

  • yarn prettier
  • yarn flow-check-android
  • yarn flow-check-ios

Release Notes:

[GENERAL] [ENHANCEMENT] [IntegrationTests/TimersTest.js] Remove createReactClass and TimerMixin

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 12, 2018
_interval = -1;
_timeoutID: ?TimeoutID = null;
// $FlowFixMe
_intervalId: ?IntervalID = -1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheSavior @RSNara

  // $FlowFixMe
_intervalId: ?IntervalID = -1;

I've had issues with Flow here and on the contructor.displayName
because null or undefined is
incompatible with IntervalID,
and number is incompatible with IntervalID

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented below how we can fix this.

{/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This
* comment suppresses an error found when Flow v0.54 was deployed.
* To see the error delete this comment and run Flow. */
this.constructor.displayName + ': \n'}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, the displayName is added on to our components in a babel transform. Flow doesn't know anything about that, so that's probably why it's raising this error.

I think there're three fixes:

  1. Change this.constructor.displayName to this.constructor.name. (Both should be equivalent).
  2. Redundantly define the displayName static property in this class.
  3. Hardcode 'TimerTest' instead of this.constructor.displayName.

Your call. 😄


_incrementInterval() {
if (this.state.count > 3) {
throw new Error('interval incremented past end.');
}
if (this.state.count === 3) {
this.clearInterval(this._interval);
clearInterval(this._intervalId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signature of clearInterval is this:

function clearInterval(interval?: IntervalID) {

So clearInterval expects an argument that is either an IntervalID, undefined, or not present at all. You're passing in a value that's ?IntervalID, which is equivalent to IntervalID, undefined, or null. (The bottom line is that clearInterval does not accept null as an argument). Therefore, If you guard this function call with a null check, your flow error should go away.

if (this.state.count === 3) {
  if (this._intervalId != null) {
    clearInterval(this._intervalId);
  }
}

_interval = -1;
_timeoutID: ?TimeoutID = null;
// $FlowFixMe
_intervalId: ?IntervalID = -1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented below how we can fix this.

@@ -11,98 +11,106 @@
'use strict';

const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of all $FlowFixMes in this file.

},
});
}
}

const styles = StyleSheet.create({
container: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of:

TimersTest.displayName = 'TimersTest';

If we want to define static properties on TimerTest, we should do it using the static keyword inside the TimerTest class. That way, flow will be able to analyze the static property.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RSNara has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@RSNara RSNara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I had some spare time, so I just took care of these changes. 😁

@ronal2do
Copy link
Contributor Author

Thanks again @RSNara

@react-native-bot
Copy link
Collaborator

@ronal2do merged commit 61346d3 into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Oct 18, 2018
@react-native-bot react-native-bot added the Merged This PR has been merged. label Oct 18, 2018
t-nanava pushed a commit to microsoft/react-native-macos that referenced this pull request Jun 17, 2019
)

Summary:
Related to facebook#21485 (comment)
Remove createReactClass and TimerMixin from IntegrationTests/TimersTest.js
Pull Request resolved: facebook#21748

Reviewed By: TheSavior

Differential Revision: D10366418

Pulled By: RSNara

fbshipit-source-id: f7e9a1b62a17cd23374997f99dbfe239172b614f
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants