Coder Social home page Coder Social logo

ember-promise-block's Introduction

ember-promise-block

This is an Ember Addon that exposes a component promise-block which shows a loader while a given promise is being resolved.

Installing

Install as an Ember-CLI addon:

ember install ember-promise-block

Usage

// templates/posts.hbs
{{#promise-block promise=postsPromise loaderTemplate='helpers/loader'}}
  {{#each posts as |post|}}
    {{post.title}}
  {{/each}}
{{/promise-block}}

The component will show the partial in loaderTemplate while promise is not resolved. It then shows the block when it resolves. The default value for loaderTemplate is helpers/loader.

Example controller:

// controllers/posts.js
import Ember from 'ember';

export default Ember.Controller.extend({
  postsPromise: function() {
    return this.get('store').query('post');
  }.property(),
  posts: Ember.computed.reads('postsPromise.content')
});

Example model:

// models/post.js
import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr('string')
});

Example

Below is a (fast) example of what the addon does. The loader is displayed until the data is loaded, i.e. the Promise gets resolved.

ember-promise-block behavior

Building yourself

  • git clone this repository
  • npm install
  • bower install

Running Tests

  • npm test (Runs ember try:testall to test your addon against multiple Ember versions)
  • ember test
  • ember test --server

ember-promise-block's People

Contributors

yoranbrondsema avatar ember-tomster avatar

Stargazers

Jared Short avatar Denys Slipetskyy avatar Nicholas Kircher avatar Steve Axthelm avatar

Watchers

Fernando Guillen avatar James Cloos avatar  avatar

ember-promise-block's Issues

Doesn't work with raw Ember.RSVP.Promise

The code seems to rely on setting of the isFulfilled property to determine if the promise is complete. Trouble is, this isn't a property of Ember.RSVP.Promise itself, but rather Ember.PromiseProxyMixin.

Ember-Data models use this mixin, so this addon works great for that use-case, but for raw promises (e.g. things returned by Ember-Ajax, in my case), fulfillment is never detected and the loader template is displayed forever.

Demo site

I was not able to make it work. A demo site would be great.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.