-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use ES6 classes in ‘Motion.js’ #457
Conversation
👍 |
package.json
Outdated
@@ -73,6 +73,7 @@ | |||
"author": "chenglou", | |||
"license": "MIT", | |||
"dependencies": { | |||
"create-react-class": "15.5.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mmm, probably not intentional
src/Motion.js
Outdated
@@ -20,8 +19,8 @@ type MotionState = { | |||
lastIdealVelocity: Velocity, | |||
}; | |||
|
|||
const Motion = createReactClass({ | |||
propTypes: { | |||
export default class Motion extends Component { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All other files use export default class Demo extends React.Component
way, it would be better to keep this one aligned too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of nits
src/Motion.js
Outdated
@@ -110,7 +117,7 @@ const Motion = createReactClass({ | |||
return; | |||
} | |||
|
|||
this.wasAnimating = true; | |||
this.wasAnimating = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ouch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably why tests fail
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to avoid flow check error(current error message on travis), but I guess it causes karma error... I'm not farmiliar with Flow and internal logic of this file, Could you give me an idea how to fix this flow error?
src/Motion.js
Outdated
animationID: (null: ?number), | ||
prevTime: 0, | ||
accumulatedTime: 0, | ||
wasAnimating: false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably go to constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why flowtype fails. wasAnimating
and others are prototype properties, not instance properties. So as soon as you put them all to constructor like this.wasAnimating = false
, tests will pass (I think so)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I put this.wasAnimating = false
first, and it gets this error
src/Motion.js:120
120: this.wasAnimating = true;
^^^^^^^^^^^^ property `wasAnimating`. Property not found in
22: export default class Motion extends React.Component {
^^^^^^ Motion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update types to include it, I reckon.
I am not doing much of Flow and never used it with JS Classes, so cannot help much in this case. Maybe someone can give you better advice.
Or there must be some examples of using Flow with React Classes somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay! that sounds quite promising, will research on that.
src/Motion.js
Outdated
animationID: (null: ?number), | ||
prevTime: 0, | ||
accumulatedTime: 0, | ||
animationID: ?number = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess all instance properties, not only wasAnimating...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :) I was just testing with one property to see if different travis result comes out compare to my local test.. now I moved them all
src/Types.js
Outdated
@@ -37,6 +37,10 @@ export type MotionProps = { | |||
style: Style, | |||
children: (interpolatedStyle: PlainStyle) => ReactElement, | |||
onRest?: () => void, | |||
wasAnimating?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These properties are not MotionProps, they are instance properties of Motion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, so sounds like I need to declare this
type Motion = {
wasAnimating?: boolean,
animationID?: number,
prevTime: number,
accumulatedTime: number,
}
in the Motion.js
file itself?
hm, here is info on how to use instance props. https://flow.org/en/docs/types/classes/ Looks like it was initially right. Probably needed |
Yeah, that links makes lot of sense! Thank you so much. Learned bit of flow types today. |
Me too. I am going to use flow for react components too. So far was using it for only library code |
Me either.Did not notice the benefit of Flow, just used proptypes in company project so far |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Thank you for supporting this whole journey with me @nkbt. This PR was my first open source contribution |
🎉 |
Test are still broken :/ |
Hi,
npm install
has broken and it seems previous migration PR missed to fix one fileMotion.js
This PR is trying to fix this. I tested
npm start
on my local machine and worked well.Thanks