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

await...then shorthand #957

Closed
Rich-Harris opened this issue Nov 25, 2017 · 2 comments · Fixed by #1001
Closed

await...then shorthand #957

Rich-Harris opened this issue Nov 25, 2017 · 2 comments · Fixed by #1001

Comments

@Rich-Harris
Copy link
Member

Follow-up to #952. This...

{{#await promise then foo}}
  <p>{{foo}}</p>
{{/await}}

...would be a nice shorthand for this:

{{#await promise}}
  <!-- no need to show a pending state -->
{{then foo}}
  <p>{{foo}}</p>
{{catch error}}
  <!-- promise is guaranteed to fulfil -->
{{/await}}
@antony
Copy link
Member

antony commented Dec 3, 2017

I'd recommend an implicit variable as an option, since seeing await and then together seems strange.

Coming from a groovy background we always have it:

Explicit:

def myVariable = 'foo'
myVariable.with { myVariable ->
  myVariable == 'foo'
}

Implicit:

def myVariable = 'foo'
myVariable.with {
  it == 'foo'
}

So this would mean you could either have the implicit:

{{#await foo}}
  {{it}} equals foo
{{/await}}

Or the explicit:

{{#await foo then quux}}
  {{quux}} equals foo
{{/await}}

Sorry about the atrocious code examples, it's been a long day!

@Rich-Harris
Copy link
Member Author

Thanks for the idea. To be honest I think that's a bit more confusing — it's not at all clear at first glance that the {{it}} equals foo fragment is the then block as opposed to the pending block, whereas requiring the then keyword makes it unambiguous and avoids introducing any magic variables (which then have to be deconflicted against any existing uses of it, etc. I've released this as 1.46.1

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

Successfully merging a pull request may close this issue.

2 participants