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

Support "Do expressions" #6417

Open
callumlocke opened this issue Jun 5, 2018 · 1 comment
Open

Support "Do expressions" #6417

callumlocke opened this issue Jun 5, 2018 · 1 comment

Comments

@callumlocke
Copy link
Contributor

callumlocke commented Jun 5, 2018

do { ... } expressions are now stage 1 and have been supported by Babel for a while.

They're especially useful in JSX, as they help you avoid nested ternaries. It would be great to be able to use them in a Flow project.

const View = ({ loading, error, ...otherProps }: Props) => (
  <div>
    {do {
      if (loading) {
        <Loading />
      } else if (error) {
        <Error error={error} />
      } else {
        <MyLoadedComponent {...otherProps} />
      };
    }}
  </div>
);

NB. This feature was being tracked as part of a long list in #560, but that issue seems to have been forgotten and buried since 2017. I suggest closing that one and opening individual issues for the few remaining ES-next features if they're still wanted.

@fishythefish
Copy link

Stage 1 is still pretty early, and that proposal very much needs to be fleshed out. It doesn't seem to be a very active proposal. Babel tends to be the playground/reference implementation for new proposals, so I'm not surprised that they have a plugin for it, but I'd like to see at least a draft of a formal semantics before beginning to implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants