On this page
Class PromiseProxyMixin
publicDefined in: | packages/ember-runtime/lib/mixins/promise_proxy.js:39 |
---|---|
Module: | @ember/object |
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin';
A low level mixin making ObjectProxy promise-aware.
let ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);
let proxy = ObjectPromiseProxy.create({
promise: Ember.RSVP.resolve($.getJSON('/some/remote/data.json'))
});
proxy.then(function(json){
// the json
}, function(reason) {
// the reason why you have no json
});
the proxy has bindable attributes which track the promises life cycle
proxy.get('isPending') //=> true
proxy.get('isSettled') //=> false
proxy.get('isRejected') //=> false
proxy.get('isFulfilled') //=> false
When the $.getJSON completes, and the promise is fulfilled with json, the life cycle attributes will update accordingly. Note that $.getJSON doesn't return an ECMA specified promise, it is useful to wrap this with an RSVP.resolve
so that it behaves as a spec compliant promise.
proxy.get('isPending') //=> false
proxy.get('isSettled') //=> true
proxy.get('isRejected') //=> false
proxy.get('isFulfilled') //=> true
As the proxy is an ObjectProxy, and the json now its content, all the json properties will be available directly from the proxy.
// Assuming the following json:
{
firstName: 'Stefan',
lastName: 'Penner'
}
// both properties will accessible on the proxy
proxy.get('firstName') //=> 'Stefan'
proxy.get('lastName') //=> 'Penner'
Methods
Properties
Events
No documented items
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/2.18/classes/PromiseProxyMixin