-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Ember.Array methods return Array rather than Ember.Array #12003
Comments
Until we can subclass natives, there isn't a reasonable & performant way to do this. There are two potential ideas:
I believe that making this work for please note. I began working to alleviate this internal dependency, making |
Okay. So I should be using Is there a way to get the property-based ease of |
Unsure, i do know some of the mappers support deep properties in lodash.
If there is a missing feature, i think this might make good addon territory for now. A set of helpers similar to the following might be interesting.
|
|
When prototype extensions are disabled as they are in an Ember addon you lose all ability to chain the Ember enumerable functions. This adds a set of helper functions that will apply the Ember enumerable functions when needed. For more information on this see this discussion: emberjs/ember.js#12003
When prototype extensions are disabled as they are in an Ember addon you lose all ability to chain the Ember enumerable functions. This adds a set of helper functions that will apply the Ember enumerable functions when needed. For more information on this see this discussion: emberjs/ember.js#12003
@stefanpenner, You said:
Does this mean Ember will have a version of lodash included? I think that perhaps there is a context confusion here. I ran in to the problem of chaining and using
The first one seems like a disservice to ember addon authors and the second seems like an insidious expectation on the consumers of such an addon. Advice? Also here is how I managed to handle array manipulation in my ember addon. The down side is I could not find a way to accomplish this with out // Ember Addons need to be coded as if Ember.EXTEND_PROTOTYPES = false
// Because of this we need to make our own proxy functions to apply as one offs
// to native arrays.
const emberArrayFunc = function(method) {
return function(ctx, ...args) {
// We have to look this up in the context of the returned function. The properties
// are not initialized (available) when evaluating the ES6 module. They are only
// available at the time the helper functions are called.
const props = Ember.Enumerable.mixins[0].properties; // Wow this was deep in there
// Ember.Enumerable.____ does not exist, 'cause it is a mixin.
Ember.assert(
`Ember.Enumerable has no method ${method}`,
Ember.typeOf(props[method]) === 'function'
);
const result = props[method].apply(Ember.A(ctx), args);
if (Ember.typeOf(result) === 'array') {
return Ember.A(result);
} else {
return result;
}
};
};
const _contains = emberArrayFunc('contains');
const _mapBy = emberArrayFunc('mapBy');
const _filterBy = emberArrayFunc('filterBy');
const _findBy = emberArrayFunc('findBy');
const _uniq = emberArrayFunc('uniq');
const _compact = emberArrayFunc('compact'); |
no, it means using lodash will be pay as you go as that PR explains. |
the final solution is two fold.
|
Ember.Array methods that return an array, like
filterBy
, return a bare JS Array rather than an Ember.Array. This makes chaining Ember.Array methods impossible with prototype extensions disabled. Here's an example:I can't find any discussion of this in the documentation, so I'm opening an issue. It seems like it would make sense for Ember.Array methods that return an array to return an Ember.Array, so that chaining Ember.Array methods becomes possible.
The text was updated successfully, but these errors were encountered: