Ember.PromiseProxyMixin Class packages/ember-runtime/lib/mixins/promise_proxy.js:36

A low level mixin making ObjectProxy, ObjectController or ArrayController's promise aware.

1
2
3
4
5
6
7
8
9
10
11
var ObjectPromiseController = Ember.ObjectController.extend(Ember.PromiseProxyMixin);

var controller = ObjectPromiseController.create({
  promise: $.getJSON('/some/remote/data.json')
});

controller.then(function(json){
   // the json
}, function(reason) {
   // the reason why you have no json
});

the controller has bindable attributes which track the promises life cycle

1
2
3
4
controller.get('isPending')   //=> true
controller.get('isSettled')  //=> false
controller.get('isRejected')  //=> false
controller.get('isFulfilled') //=> false

When the the $.getJSON completes, and the promise is fulfilled with json, the life cycle attributes will update accordingly.

1
2
3
4
controller.get('isPending')   //=> false
controller.get('isSettled')   //=> true
controller.get('isRejected')  //=> false
controller.get('isFulfilled') //=> true

As the controller is an ObjectController, and the json now its content, all the json properties will be available directly from the controller.

1
2
3
4
5
6
7
8
9
// Assuming the following json:
{
  firstName: 'Stefan',
  lastName: 'Penner'
}

// both properties will accessible on the controller
controller.get('firstName') //=> 'Stefan'
controller.get('lastName')  //=> 'Penner'

If the controller is backing a template, the attributes are bindable from within that template

1
2
3
4
5
6
{{#if isPending}}
  loading...
{{else}}
  firstName: {{firstName}}
  lastName: {{lastName}}
{{/if}}
Show:

Methods

Properties

Show:

catch

(callback) RSVP.Promise

An alias to the proxied promise's catch.

See RSVP.Promise.catch.

Parameters:

callback Function

Returns:

RSVP.Promise

finally

(callback) RSVP.Promise

An alias to the proxied promise's finally.

See RSVP.Promise.finally.

Parameters:

callback Function

Returns:

RSVP.Promise

then

(callback) RSVP.Promise

An alias to the proxied promise's then.

See RSVP.Promise.then.

Parameters:

callback Function

Returns:

RSVP.Promise
Show:

isFulfilled

Will become true if the proxied promise is fulfilled.

Default: false

isPending

Once the proxied promise has settled this will become false.

Default: true

isRejected

Will become true if the proxied promise is rejected.

Default: false

isSettled

Once the proxied promise has settled this will become true.

Default: false

promise

The promise whose fulfillment value is being proxied by this object.

This property must be specified upon creation, and should not be changed once created.

Example:

1
2
3
Ember.ObjectController.extend(Ember.PromiseProxyMixin).create({
  promise: <thenable>
});

reason

If the proxied promise is rejected this will contain the reason provided.

Default: null