ember-promises-helpers

0.0.2 • Public • Published

ember-promises-helpers Build Status

Installation

ember install ember-promises-helpers

Usage

await

{{#if (await model.author)}}
  {{get (await model.author) 'name'}}
{{else}}
  No author!
{{/if}}

The await helper also works anywhere, because it's just a Handlebars subexpression. For example, you can pass it to another helper...

{{#each (await model.comments) as |comment|}}
  {{comment.author}} wrote {{comment.text}}
{{/each}}

Or pass it to a component:

{{twitter-timeline users=(await user.following)}}

Or use it by itself:

{{await model.title}}

is-pending

Resolves with false if the promise resolved or rejected, otherwise true until the promise resolves or rejects.

{{#if (is-pending promise)}}
  <img src="loading.gif"/>
{{else}}
  Loaded!
{{/if}}

is-rejected

Resolves with true if the promise rejects or fails, false otherwise. Initial value is false until the promise is resolved.

{{#unless (is-pending promise)}}
  {{#if (is-rejected promise)}}
    rejected!
  {{/if}}
{{/unless}}

is-fulfilled

Resolves with true if the promise resolved successfully, false otherwise. Initial value is false until the promise is resolved.

{{#unless (is-pending promise)}}
  {{#if (is-fulfilled promise)}}
    It works!
  {{else}}
    Oops!
  {{/if}}
{{/unless}}

promise-all

Uses the Ember.RSVP.all function to create a promise. It also accepts 1..n promises as arguments or an array as first argument.

{{#if (is-pending (promise-all promise1 promise2))}}
  <img src="loading.gif"/>
{{else}}
  Loaded!
{{/if}}
{{#if (is-pending (promise-all promiseArray))}}
  <img src="loading.gif"/>
{{else}}
  Loaded!
{{/if}}

promise-hash

Uses the Ember.RSVP.hash function to create a promise.

{{#if (is-pending (promise-hash foo=promise1 bar=promise2))}}
  <img src="loading.gif"/>
{{else}}
  Loaded!
{{/if}}

Package Sidebar

Install

npm i ember-promises-helpers

Weekly Downloads

4

Version

0.0.2

License

MIT

Unpacked Size

8.72 kB

Total Files

18

Last publish

Collaborators

  • alexey.bedonik