Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pixelhandler opened this issue Aug 3, 2015 · 10 comments
Closed

Comments

@pixelhandler
Copy link

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'});
}
@Gaurav0
Copy link
Contributor

Gaurav0 commented Aug 3, 2015

I would actually like to at least see an addon that restores all the ArrayController / ObjectController / reduceComputed / ObjectProxy / ArrayProxy etc. behavior. This could really help some enterprises with large codebases move to 2.0 at some point in the current century. :)

@mixonic
Copy link
Member

mixonic commented Aug 3, 2015

@Gaurav0 there is an addon for controllers (ember-legacy-controllers) and views (ember-legacy-views). array/reduce computed are gone, but the macros that represented nearly all of the usage are still present. Just the direct API access to the array/reduce computed classes is gone.

Please keep this issue focused on the original topic, object and array proxies.

@workmanw
Copy link
Contributor

workmanw commented Aug 3, 2015

👍 I use both ArrayProxy and ObjectProxy on occasion. I think quite a few people also use ember-buffered-proxy which relies on them.

@DingoEatingFuzz
Copy link

We also use ObjectProxy and ArrayProxy with the PromiseProxyMixin in places where ED doesn't make sense.

Our PromiseArray is as simple as

import Ember from 'ember';

export default Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);

pixelhandler pushed a commit to pixelhandler/ember.js that referenced this issue Aug 3, 2015
@pixelhandler
Copy link
Author

Wait, I see some changes already:

So ObjectProxy is already public, nice.

Just need ArrayProxy to be public as well

@mmun
Copy link
Member

mmun commented Aug 5, 2015

One caveat with ObjectProxy is that it is not compatible with removing Ember.get in favor of ES5 getters.

@mixonic
Copy link
Member

mixonic commented Aug 7, 2015

@pixelhandler I've merged emberjs/ember.js#11970, should this be closed then or are there additional parts to discuss?

@pixelhandler
Copy link
Author

@mixonic awesome thank you sir! all set, closing this up 👍

rwjblue pushed a commit to rwjblue/ember.js that referenced this issue Aug 8, 2015
See: RFC/issue emberjs#80
- emberjs/rfcs#80

(cherry picked from commit 97e4441)
rwjblue pushed a commit to emberjs/ember.js that referenced this issue Aug 9, 2015
See: RFC/issue #80
- emberjs/rfcs#80

(cherry picked from commit 97e4441)
@pixelhandler
Copy link
Author

@rwjblue
Copy link
Member

rwjblue commented Sep 29, 2015

@pixelhandler - Ember.ObjectProxy is marked as @public (see here on master). The API docs you linked to are for 2.0.1 which are somewhat behind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants