var Promise = Ember.RSVP.Promise;
var get = Ember.get;

/**
  A `PromiseArray` is an object that acts like both an `Ember.Array`
  and a promise. When the promise is resolved the resulting value
  will be set to the `PromiseArray`'s `content` property. This makes
  it easy to create data bindings with the `PromiseArray` that will be
  updated when the promise resolves.

  For more information see the [Ember.PromiseProxyMixin
  documentation](/api/classes/Ember.PromiseProxyMixin.html).

  Example

  ```javascript
  var promiseArray = DS.PromiseArray.create({
    promise: $.getJSON('/some/remote/data.json')
  });

  promiseArray.get('length'); // 0

  promiseArray.then(function() {
    promiseArray.get('length'); // 100
  });
  ```

  @class PromiseArray
  @namespace DS
  @extends Ember.ArrayProxy
  @uses Ember.PromiseProxyMixin
*/
var PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);

/**
  A `PromiseObject` is an object that acts like both an `Ember.Object`
  and a promise. When the promise is resolved, then the resulting value
  will be set to the `PromiseObject`'s `content` property. This makes
  it easy to create data bindings with the `PromiseObject` that will
  be updated when the promise resolves.

  For more information see the [Ember.PromiseProxyMixin
  documentation](/api/classes/Ember.PromiseProxyMixin.html).

  Example

  ```javascript
  var promiseObject = DS.PromiseObject.create({
    promise: $.getJSON('/some/remote/data.json')
  });

  promiseObject.get('name'); // null

  promiseObject.then(function() {
    promiseObject.get('name'); // 'Tomster'
  });
  ```

  @class PromiseObject
  @namespace DS
  @extends Ember.ObjectProxy
  @uses Ember.PromiseProxyMixin
*/
var PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin);

var promiseObject = function(promise, label) {
  return PromiseObject.create({
    promise: Promise.resolve(promise, label)
  });
};

var promiseArray = function(promise, label) {
  return PromiseArray.create({
    promise: Promise.resolve(promise, label)
  });
};

/**
  A PromiseManyArray is a PromiseArray that also proxies certain method calls
  to the underlying manyArray.
  Right now we proxy:
    `reload()`
    `createRecord()`
    `on()`
    `one()`
    `trigger()`
    `off()`
    `has()`
*/

function proxyToContent(method) {
  return function() {
    var content = get(this, 'content');
    return content[method].apply(content, arguments);
  };
}

var PromiseManyArray = PromiseArray.extend({
  reload: function() {
    //I don't think this should ever happen right now, but worth guarding if we refactor the async relationships
    Ember.assert('You are trying to reload an async manyArray before it has been created', get(this, 'content'));
    return PromiseManyArray.create({
      promise: get(this, 'content').reload()
    });
  },

  createRecord: proxyToContent('createRecord'),

  on: proxyToContent('on'),

  one: proxyToContent('one'),

  trigger: proxyToContent('trigger'),

  off: proxyToContent('off'),

  has: proxyToContent('has')
});

var promiseManyArray = function(promise, label) {
  return PromiseManyArray.create({
    promise: Promise.resolve(promise, label)
  });
};


export {
  PromiseArray,
  PromiseObject,
  PromiseManyArray,
  promiseArray,
  promiseObject,
  promiseManyArray
};

@@ -2186,19 +2186,22 @@
  proxy:%0A
+%0A
    
+ *
  %60reload
@@ -2207,16 +2207,18 @@
 d()%60%0A   
+ *
  %60create
@@ -2226,24 +2226,26 @@
 ecord()%60%0A   
+ *
  %60on()%60%0A    
@@ -2243,16 +2243,18 @@
 n()%60%0A   
+ *
  %60one()%60
@@ -2257,16 +2257,18 @@
 e()%60%0A   
+ *
  %60trigge
@@ -2275,16 +2275,18 @@
 r()%60%0A   
+ *
  %60off()%60
@@ -2293,16 +2293,18 @@
 %0A   
+ *
  %60has()%60
 %0A*/%0A
@@ -2299,16 +2299,87 @@
  %60has()%60
+%0A%0A  @class PromiseManyArray%0A  @namespace DS%0A  @extends Ember.ArrayProxy
 %0A*/%0A%0Afun

Add page for `DS.PromiseManyArray`