ember-async-action-container

1.0.1 • Public • Published

ember-async-action-container

npm version Build Status

An async state wrapper

Inspired by https://github.com/DockYard/ember-async-button

Installation

ember install ember-async-action-container

Usage

{{#async-action-container
  action=(action "myAction")
  as |action promise|
}}
  <button
    disabled={{promise.isPending}}
    {{action action}}
  >
    {{#if promise.isPending}}
      Submitting
    {{else}}
      Submit
    {{/if}}
  </button>
{{/async-action-container}}

If you want reset state:

{{#async-action-container
  action=(action "myAction")
  callback=(action (mut myPromise))
  promise=myPromise
  as |action promise|
}}
  <button
    disabled={{or
      promise.isPending
      promise.isFulfilled
    }}
    {{action action}}
  >
    {{#if promise.isPending}}
      Submitting
    {{else if promise.isRejected}}
      Submit again
    {{else if promise.isFulfilled}}
      Submitted
    {{else}}
      Submit
    {{/if}}
  </button>
{{/async-action-container}}

Then

this.set('myPromise', null);

to reset.

The CSS classes exposed are default, pending, settled, rejected, and fulfilled.

Contributing

Installation

  • git clone <repository-url>
  • cd ember-async-action-container
  • npm install

Linting

  • npm run lint:js
  • npm run lint:js -- --fix

Running tests

  • ember test – Runs the test suite on the current Ember version
  • ember test --server – Runs the test suite in "watch mode"
  • ember try:each – Runs the test suite against multiple Ember versions

Running the dummy application

For more information on using ember-cli, visit https://ember-cli.com/.

License

This project is licensed under the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i ember-async-action-container

Weekly Downloads

2

Version

1.0.1

License

MIT

Unpacked Size

7.27 kB

Total Files

8

Last publish

Collaborators

  • kellyselden