Skip to content

Conversation

@gaearon
Copy link
Contributor

@gaearon gaearon commented Aug 2, 2016

Test plan:

import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';

class App extends Component {
  async componentDidMount() {
    try {
      await fetch('http://google.com');
    } catch (lol) {
      alert('oh noes')
    }
  }

  render() {
    return (
      <div className="App">
        <div className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h2>Welcome to React</h2>
        </div>
        <p className="App-intro">
          To get started, edit <code>src/App.js</code> and save to reload.
        </p>
      </div>
    );
  }
}

export default App;

It worked.

@gaearon gaearon added this to the 0.3.0 milestone Aug 2, 2016
@ghost ghost added the CLA Signed label Aug 2, 2016
@gaearon gaearon merged commit fa38991 into master Aug 2, 2016
@gaearon gaearon deleted the async branch August 2, 2016 13:38
@kennetpostigo kennetpostigo mentioned this pull request Aug 2, 2016
'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
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
Contributor Author

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. 😄

@gaearon gaearon modified the milestones: 0.2.3, 0.3.0 Aug 25, 2016
@gaearon gaearon mentioned this pull request Aug 25, 2016
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

3 participants