-
Notifications
You must be signed in to change notification settings - Fork 25.1k
refactor: Convert Animated directory to use ESModule imports/exports #34539
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
| * @emails oncall+react_native | ||
| */ | ||
|
|
||
| import AnimatedProps from '../nodes/AnimatedProps'; | ||
| import TestRenderer from 'react-test-renderer'; | ||
| import * as React from 'react'; | ||
|
|
||
|
|
@@ -21,7 +20,8 @@ jest.mock('../../BatchedBridge/NativeModules', () => ({ | |
| }, | ||
| })); | ||
|
|
||
| let Animated = require('../Animated'); | ||
| let AnimatedProps = require('../nodes/AnimatedProps').default; | ||
| let Animated = require('../Animated').default; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept it like this because using ES module imports here breaks jest mocks |
||
|
|
||
| describe('Animated tests', () => { | ||
| beforeEach(() => { | ||
|
|
@@ -692,7 +692,7 @@ describe('Animated tests', () => { | |
|
|
||
| beforeEach(() => { | ||
| jest.mock('../../Interaction/InteractionManager'); | ||
| Animated = require('../Animated'); | ||
| Animated = require('../Animated').default; | ||
| InteractionManager = require('../../Interaction/InteractionManager'); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,8 @@ jest | |
| import TestRenderer from 'react-test-renderer'; | ||
| import * as React from 'react'; | ||
|
|
||
| const Animated = require('../Animated'); | ||
| const NativeAnimatedHelper = require('../NativeAnimatedHelper'); | ||
| const Animated = require('../Animated').default; | ||
| const NativeAnimatedHelper = require('../NativeAnimatedHelper').default; | ||
|
Comment on lines
+29
to
+30
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept it like this because using ES module imports here breaks jest mocks
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @javache please let me know if this approach is ok for test files of if we should do something different
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be possible to "fix" jest mocks to work with ES module imports too, but I'm no expert.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have to dynamically import module and reset it for some reason after each test you have to stick to the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we won't be able to replace any of these
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tests don't matter so much. It's the Animated module syntax that I have to edit every time I sync code to React Native for Web.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gabrieldonadel Sorry, but I haven't spotted |
||
|
|
||
| describe('Native Animated', () => { | ||
| const NativeAnimatedModule = require('../NativeAnimatedModule').default; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,9 @@ | |
|
|
||
| 'use strict'; | ||
|
|
||
| const createAnimatedComponent = require('../createAnimatedComponent'); | ||
| const createAnimatedComponent = require('../createAnimatedComponent').default; | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using import here also breaks jest |
||
| const createAnimatedComponentInjection = require('../createAnimatedComponentInjection'); | ||
| const React = require('react'); | ||
| import * as React from 'react'; | ||
|
|
||
| function injected<TProps: {...}, TInstance>( | ||
| Component: React.AbstractComponent<TProps, TInstance>, | ||
|
|
||
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 think we'll want to keep this, as it enables lazy initialization of these modules (if you don't have the inline-requires transform enabled)
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, I'll revert this
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.
@javache What do you mean by this
if you don't have the inline-requires transform enabled? Could you explain it a little bit more ?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.
Reverted
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.
@TMaszko see https://reactnative.dev/docs/ram-bundles-inline-requires for details on inline-requires. It's an important transform we apply to improve bundle init time.
Uh oh!
There was an error while loading. Please reload this page.
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.
@javache I know that optimization technique. My question is why getters do enable lazy initialization when inline-requires transform is disabled? I thought it will work only when this transform is enabled that's why I wanted you to explain 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.
Ah, sorry for misunderstanding. In this case the
requireis manually inlined, and we would only invoke the module factory for that module once the getter is invoked. When usingimportsyntax, that manual inlining is not possible.When the inline-requires transform is enabled, you get this behaviour for free (as long as you're using a getter in this case)