Skip to content

Make Ember.ObjectProxy and Ember.ArrayProxy Public (not private) #80

@pixelhandler

Description

@pixelhandler

Ember.ObjectProxy and Ember.ArrayProxy are great to use in combination with Ember.PromiseProxyMixin like Ember Data uses them. However ObjectProxy and ArrayProxy are marked Private API.

It would be great for addon developers and app developers alike to be able to use ObjectProxy and ArrayProxy combined with Ember.PromiseProxyMixin to compose attributes of an object that depend on promises e.g. XHR.

Please make ObjectProxy and ArrayProxy public API. I don't believe this combo is only unique to Ember Data. Anyone writing custom data persistence benefits from the same pattern as Ember Data does. Why does this need to be private API?

I understand ObjectController and ArrayController are deprecated and extend ObjectProxy and ArrayProxy respectively. I understand the confusion for new developers using those proxied controllers and I understand that Controllers will be replace with Components in 2.0. However I don't see why the ObjectProxy and ArrayProxy need to be private API.

Is there another way to use PromiseProxyMixin aside from combining a proxy object/array?

Below is the use case I have for a data persistence library…

A utility object (RelatedProxyUtil) with a factory creates proxies, to be used in a computed property:

/**
  Proxy for the requested relation, resolves w/ content from fulfilled promise
  @method createProxy
  @param {Resource} resource
  @param {Ember.ObjectProxy|Ember.ArrayProxy} proxyFactory
  @return {PromiseProxy} proxy
*/
createProxy: function (resource, proxyFactory) {
  const relation = this.get('relationship');
  const url = this.proxyUrl(resource, relation);
  const service = resource.container.lookup('service:' + pluralize(relation));
  let promise = this.promiseFromCache(resource, relation, service);
  promise = promise || service.findRelated(relation, url);
  let proxy = proxyFactory.extend(Ember.PromiseProxyMixin, {
    'promise': promise, 'type': relation
  });
  proxy = proxy.create();
  proxy.then(
    function (resources) {
      proxy.set('content', resources);
    },
    function (error) {
      console.error(error);
      throw error;
    }
  );
  return proxy;
}

A helper that uses the proxy util and returns a computed property:

/**
  Helper to setup a has one relationship to another resource
  @method hasOne
  @param {String} relation
*/
export function hasOne(relation) {
  let util = RelatedProxyUtil.create({'relationship': relation});
  let path = ['relationships', relation, 'links', 'related'].join('.');
  return Ember.computed(path, function () {
    return util.createProxy(this, Ember.ObjectProxy);
  }).meta({relation: relation, kind: 'hasOne'});
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions