Skip to content

Support async/await - #327

Merged
gaearon merged 2 commits into
masterfrom
async
Aug 2, 2016
Merged

Support async/await#327
gaearon merged 2 commits into
masterfrom
async

Conversation

@gaearon

Copy link
Copy Markdown
Contributor

Test plan:

importReact,{Component}from'react';importlogofrom'./logo.svg';import'./App.css';classAppextendsComponent{asynccomponentDidMount(){try{awaitfetch('http://google.com');}catch(lol){alert('oh noes')}}render(){return(<divclassName="App"><divclassName="App-header"><imgsrc={logo}className="App-logo"alt="logo"/><h2>Welcome to React</h2></div><pclassName="App-intro">
To get started, edit <code>src/App.js</code> and save to reload.
</p></div>);}}exportdefaultApp;

It worked.

@gaearongaearon added this to the 0.3.0 milestone Aug 2, 2016
@ghostghost added the CLA Signed label Aug 2, 2016
@gaearon
gaearon merged commit fa38991 into masterAug 2, 2016
@gaearon
gaearon deleted the async branch August 2, 2016 13:38
@kennetpostigokennetpostigo mentioned this pull request Aug 2, 2016
Comment threadconfig/babel.prod.js
'babel-plugin-transform-react-constant-elements',
].map(require.resolve).concat([
require.resolve('babel-plugin-syntax-trailing-function-commas'),
require.resolve('babel-plugin-transform-async-to-generator'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, is there a reason we use transform-async-to-generator to first transform async functions to generators and then regenerator to transform them to ES5? (Regenerator can also transform async functions directly, in which case the async-to-generator won't be needed.)

I've tested the Regenerator-only solution with following config:

require.resolve('babel-plugin-syntax-async-functions'),[require.resolve('babel-plugin-transform-regenerator'),{asyncGenerators: false,generators: true,async: true}],

and it compiled to more or less the same code except it uses only the regenerator runtime and not the _asyncToGenerator helper from Babel. I don't know, if there are some minor differences in the runtime behaviour of these alternatives.

If you want to switch, I can send a pull request with this config I have.

P.S. It's very cool to have async/await supported by create-react-app! This was the reason I had to eject my config and I've been planning to make a PR to add them, but you beat me to it 😎

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, PR would be welcome. I had no idea what’s the right way to integrate this. 😄

@gaearongaearon modified the milestones: 0.2.3, 0.3.0Aug 25, 2016
@gaearongaearon mentioned this pull request Aug 25, 2016
@timarneytimarney mentioned this pull request Nov 9, 2016
@locklockBot locked and limited conversation to collaborators Jan 22, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@gaearon@fson