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

Why use setAll is the most efficient way to do a setEach? #14022

Closed
carlesnunez opened this issue Aug 4, 2016 · 3 comments
Closed

Why use setAll is the most efficient way to do a setEach? #14022

carlesnunez opened this issue Aug 4, 2016 · 3 comments

Comments

@carlesnunez
Copy link

Hi, according to ember documentation Ember.enumerable setEach 'is more
efficient than using other methods defined on this helper':

If we drop down to the ember code we can see a function that uses a vanila JS foreach and set method extracted from ember-metal.

/**
    Sets the value on the named property for each member. This is more
    efficient than using other methods defined on this helper. If the object
    implements Ember.Observable, the value will be changed to `set(),` otherwise
    it will be set directly. `null` objects are skipped.
    @method setEach
    @param {String} key The key to set
    @param {Object} value The object to set
    @return {Object} receiver
    @public
  */
  setEach(key, value) {
    return this.forEach(function(item) {
      set(item, key, value);
    });
  },

Why this is the most 'efficient' way to do that? Its because we use set as a method instead of do item.set?

Thank you

@pixelhandler
Copy link
Contributor

@carlesnunez Thank you for your question. Can you reach out to the ember community via one of the links here - http://emberjs.com/community/

Typically we use github for reporting bugs in Ember. StackOverflow, the discussion forum, and Slack are all great ways to address questions. Also using those resources, you'll be more likely to get an answer.

@stefanpenner
Copy link
Member

this may be a doc error, this is more ergonomic not more efficient.

@pixelhandler
Copy link
Contributor

See http://emberjs.com/api/classes/Ember.Enumerable.html#method_setEach as Stefan mentions the wording could be improved

This is more efficient than using other methods defined on this helper

Perhaps should read

This is more ergonomic than using other methods defined on this helper

Serabe added a commit to Serabe/ember.js that referenced this issue Aug 6, 2016
As suggested in emberjs#14022, `setEach` is a more ergonomic, not more efficient
method.

Fixes emberjs#14022
@Serabe Serabe added the Has PR label Aug 6, 2016
rwjblue pushed a commit that referenced this issue Aug 15, 2016
As suggested in #14022, `setEach` is a more ergonomic, not more efficient
method.

Fixes #14022

(cherry picked from commit 8514612)
rwjblue pushed a commit that referenced this issue Aug 15, 2016
As suggested in #14022, `setEach` is a more ergonomic, not more efficient
method.

Fixes #14022

(cherry picked from commit 8514612)
toddjordan pushed a commit to toddjordan/ember.js that referenced this issue Sep 9, 2016
As suggested in emberjs#14022, `setEach` is a more ergonomic, not more efficient
method.

Fixes emberjs#14022
webark pushed a commit to webark/ember.js that referenced this issue Oct 6, 2016
As suggested in emberjs#14022, `setEach` is a more ergonomic, not more efficient
method.

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

No branches or pull requests

4 participants