Deprecates Ember.ArrayProxy#12843
Deprecates Ember.ArrayProxy#12843trek wants to merge 1 commit intoemberjs:masterfrom trek:deprecate-array-proxy
Conversation
There was a problem hiding this comment.
Hm, this isn't better on ENV maybe? Ala Ember.ENV._ENABLE_LEGACY_CONTROLLER_SUPPORT (usage)
There was a problem hiding this comment.
I believe this is correct. Basically, we are only deprecating when not used via Ember Data. This is on a per instance basis, not a global ENV basis.
|
Can you flag the tests with |
|
Can we also get an entry in emberjs/website's deprecation guide? |
|
Why is this being deprecated? |
|
@btecu - Great question! That is exactly what the deprecation guide entry should point out. |
|
I'm also curious about the reason. I use it in a couple places in conjunction with |
😱 |
|
I can't speak for @btecu or @cibernox but my use case is I have a custom I don't have to use One other note, we DO use |
|
I have a dynamic table So I use |
|
The use case I'm aware now, is using const PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin);
export default Ember.Component.extend({
results: computed('foo', function() {
// ...
return PromiseArray.create({ promise, content: previousResults });
})
})That basically gives me a collection-like object that I can iterate that contains some initial elements and also has a I'm not saying this shouldn't be deprecated, I already have rough idea in my head about how to stop using it, I just was curious about the reasons. Performance? I understand there must be some penalty, but I never measured it. |
|
I'm doing basically the same pattern as @cibernox in several places in my app. |
|
Same here. |
|
Just to note, I have converted some ArrayControllers over using this pattern, however, I believe foo: Ember.computed('model', function() {
return Ember.ArrayProxy.extend(Ember.SortableMixin).create({
sortProperties: ['bar'],
sortAscending: false,
content: this.get('model')
});
} |
|
We use it for a few cases where we just want to be notified of an item being added/removed from a collection. The issue is that when a computed prop is dependent on This is similar to the Collection add/remove events in Backbone, which is one thing I missed when moving to Ember. We have also use this type of functionality to insert and item into a sorted list at the right spot, rather than doing a full sort on a full set of data. We have experienced very significant perf gains on using this for large sets of data. |
|
@barneywilliams do you mean an array? Or some arbitrary collection. If it's just an array, normal arrays already track such changes |
|
I'm also interested in why this is going away - one of my data store libraries is using this heavily like ember-data was for basic find/fetch/filtering of models in the store export default ArrayProxy.extend({
store: null,
type: null,
content: computed(function () {
return Ember.A(this.get("source"));
})
});update Use case 1 (model hook from the route)
Use case 2 (relationships) Below is how I currently model a one-to-many relationship using ArrayProxy at the center of it all var User = Model.extend({
role: Ember.computed.alias('belongs_to.firstObject'),
belongs_to: Ember.computed(function() {
const user_id = this.get('id');
const store = this.get('store');
const filter = function(role) {
const users = role.get('users');
return Ember.$.inArray(user_id, users) > -1;
};
return store.find('role', filter, ['users']);
})
})And what the unit test for that relationship looks like (to see it in action) test('role returns associated model or undefined', function(assert) {
let user = store.push('user', {id: 1});
store.push('role', {id: 2, name: 'Admin', users: [1]});
let role = user.get('role');
assert.equal(role.get('id'), 2);
assert.equal(role.get('name'), 'Admin');
store.push('role', {id: 2, users: []}); //update users on role to trigger a change
role = user.get('role');
assert.equal(role, undefined);
});When the ArrayProxy content is updated my "filter" above will recompute the ArrayProxy for "belongs_to" allowing me to change roles in the system for a given user |
|
@stefanpenner I was referring to collections in general.. but arrays are usually what I have dealt with. i know that you can get a notification on when an array changes in size with 'someArray.[]', but that doesn't let you know what item(s) were added/removed... unless there is a trick I don't know about? |
|
@barneywilliams although they are very low level, and must be used with care array observers allow for this. |
|
@toranb makes a good point, until we can subclass arrays decorating them is likely one of the better options. This doesn't mean these proxies can't be extracted, but we should take this into account. |
|
We use Array Proxies in Discourse and we don't use Ember Data. We have our own lightweight data API on top of Ember and we use it for We also use it in a half dozen other places based on a quick grep. I'm also curious what the rationale for this deprecation is? |
I believe the concern is that it is a leaky abstraction, but maybe those concerns need to be fully enumerated. Maybe we can address those issues. I wonder if a counter balance should be applied to the kill all proxies with fire. I believe stateful proxies, or proxies that leak their abstraction are the pain point. We should likely explore this in more detail. |
|
I've used Only way I've found to synchronously load a template and then update the array proxy when the actual promise resolves. Pretty much a |
nah, thats orthogonal |
I would like to (before removing those constructs) make the underlying system correctly understand promises. So ultimately making them pointless before removing them. |
|
Please please, do not deprecate ArrayProxy or ObjectProxy these are super useful for promise proxy objects. Seriously there is a lack of diversity among data solutions in the Ember ecosystem. These three objects are critical to developing data persistence solutions. 👎 So if Ember Data needs these objects, why deprecate for other people not using Ember Data, is that the only data persistence solution that is "blessed" to use these primitives? Will The PromiseProxyMixin, ArrayProxy and Object proxy become an Addon combo for Ember Data and any data persistence solution to utilize? |
|
@trek please add a checkbox and issue for a "way forward" perhaps "[ ] Create Addon for PromiseProxyMixin, ArrayProxy and Object Proxy" |
|
@pixelhandler - |
|
@rwjblue ok so how about "[ ] Create Addon for ArrayProxy" |
|
@toranb Per your suggestion about sharing use cases… I use the ArrayProxy (and ObjectProxy) with the PromiseProxyMixin as a utility for related resources in a data persistence library like so: https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/utils/related-proxy.js#L50-L73 and https://github.com/pixelhandler/ember-jsonapi-resources/blob/master/addon/utils/related-proxy.js#L90-L92 I would be happy to use these same objects if they lived in an Ember CLI addon and no longer were included as primitives in Ember.js proper. I think they are valuable to anyone working with data persistence. I am curious what the proposed "way forward" is? |
|
One thing worth noting, is all basic proxies like promise + object make removing the use of |
Well, for example: One could decorate an array with additional functionality. making it one with the proxy, rather then indirectly a proxy. This is more or less one path nicely aligned with the platform, especially once we are able to subclass native arrays cross platform. Unfortunately until real subclassing is possible that approach isn't really that best. :( |
|
We're using it to implement live queries and hasMany relationships in ember-orbit. It's not something that I often reach for but when needed it is very useful. I'm not sure what the reasoning is behind it's removal but I do see a couple of issues that could perhaps be addressed.
|
|
I use the Example: setting the 'admin' property on the array proxy will set the 'admin' property on all items in the array proxy. |
|
ArrayProxy is something we'd (or at least I'd) like to move away from in Ember Data. Or at least our current usage of it. I don't have an alternate implementation, but an ArrayProxy that had a hidden I don't know if we'd be able to drop it because of backwards compat, but removing the most troubling aspects of ArrayProxy would help a lot. |
|
All: This was great! You might have seen in the notes on the last face to face that the core team is trying to trickle out deprecations on a more, ahem, tolerable time table during this major revision. Part of that process means doing PRs for deprecations early so we can get community comments. I think the core team were occasionally surprised at some of the creative uses of public 1.x API and want to do a better job ensuring alternate APIs exist for all use cases this time around.
@btecu, et al
The three main uses for
Instead of deprecating To aid migration, would having multiple deprecation warnings per ArrayProxy be helpful? That is, would it be useful to know where you were using each of the use cases above? |
This solution will solve it, but I thought I'd reiterate the scenario that I'm considering: In orbit.js we stream updates to live queries(queries whose results are updated in realtime) through an Observable (we're using RxJS under the hood). Ember-orbit uses an ArrayProxy to provide a reference to the latest array of results received from this Observable. |
|
I use a few custom array proxies as well, but I do often reach for this. It's an incredibly useful tool. I think it would make sense at least to provide this as an addon. Like @opsb is using it, I also do not rely on the proxy to arrange / sort / filter the content. However, unlike him I not only use it as a stable reference, but also for running granular operations when content changes. It's much more stable than |
@trek forgive me if I missed something but I don't specifically see a way forward in your reply for this use case. The major place we are still using This seems to always be a thing that comes up but there isn't a best practice that I am aware of. Maybe it would make more sense to just return a promise from the CP that will resolve into an array, and make |
|
☔ The latest upstream changes (presumably #12914) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@raytiley yeah, we generally need better handling for async flow control at the template layer. I'm not sure who suggested it (@stefanpenner maybe?), but an |
|
Ya, I believe many of the cases described here can be replaced with tools that are better suited for the task. Although those may not all be ready yet, hopefully soon they will be. |
|
We've been using ember-data's DS.PromiseArray to do the work @raytiley is talking about in #12843 (comment) So I wasn't too worried about this given the caveat that data would be excepted. However it appears that PromiseArray is actually private in data. Deprecating this doesn't bother me, but before that happens there should be a shared solution to the common problem of needing to put together a set of one or more promises into an array to get passed into a template. Right now it is dirt simple to simple return a DS.PromiseArray from a CP which {{each}} will use and which can also be tested for isFulfilled to provide for a nice loading indication or pre-loaded state. Maybe it is making DS.PromiseArray public warp-drive-data/warp-drive#4163 ? |
|
@trek Is this PR inactive? What is the path forward? To deprecate or not to deprecate? Perhaps this should be closed in favor of an RFC issue. |
|
Closing this PR as inactive. Thank you! |
Includes a legacy flag for Ember Data to continue to use Ember.ArrayProxy internally.
_LEGACY_EMBER_DATA_SUPPORTflag