Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ember-cli-fetch-async-button

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-cli-fetch-async-button

Button states, disabling, and promise handling for async actions. Built to support ember-fetch async calls.

  • 0.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by75%
Maintainers
1
Weekly downloads
 
Created
Source

Ember-cli-fetch-async-button

This addon is based on the Dockyard ember-cli addon 'ember-cli-async-button'... https://github.com/dockyard/ember-async-button

Implemented with support for fetch. You can read more about fetch here. http://updates.html5rocks.com/2015/03/introduction-to-fetch

& the github polyfill which ember-fetch uses... https://github.com/github/fetch

This adds the initial 'then' handler, which validates the response status before either throwing that response as an error to the 'catch' handler, or returning onto the successful 'then' handler.

Hashes and Arrays of promises

v0.2.0 adds support to validate hashes and arrays of promises. The component will initialize the button's rejected state if any of the promises in the array or hash cause a throw.

To use fetch with your ember application, I recommend installing stefanpenner's ember-fetch. https://github.com/stefanpenner/ember-fetch

Usage

Basic Usage

Template

{{fetch-async-button class="button"
  asyncAction=(action "save")
  default="Save"
  pending="Saving..."
  fulfilled="Saved!" }}

Controller

save(cb) {
  const user = Ember.Object.create({
    user: {
      name: this.get('name')
    }
  });

  const promise = fetch(`/api/v2/users/${this.get('model.id')}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      'Data-Type': 'json'
    },
    body: JSON.stringify(user),
    credentials: 'include'
  });

  cb(promise);

  promise
    .then(response => {
      if (response.status >= 200 && response.status < 300) {
        return response;
      } else {
        throw response;
      }
    })
    .then(() => {
      console.log('Successfully updated User');
    })
    .catch(err => {
      console.log('Error updating user', err);
    });
},

Installation

  • git clone this repository
  • npm install
  • bower install

Running

Running Tests

  • ember test
  • ember test --server

Building

  • ember build

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

Keywords

FAQs

Package last updated on 14 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc