-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Use reduce in View.configureTriggers #2009
Conversation
👍 |
1 similar comment
👍 |
Hmm, syntactically it could be debated if 👎 Thanks though |
@thejameskyle this reduced intermediate state in the method tho, so I am a fan |
How exactly does it get rid of state? |
In most situations, this method is called a single time – when a view is created – so I wouldn't consider speed to be a top priority for this method. I prefer this more compact version. 👍 |
is internal state to the method that is unneeded. |
@jmeas Actually when uglified, the // _.reduce: 185
function configureTriggers(){if(this.triggers){var r=this.normalizeUIKeys(_.result(this,"triggers"))
return _.reduce(r,function(r,i,e){return r[e]=this._buildViewTrigger(i),r},{},this)}} // _.each: 176
function configureTriggers(){if(this.triggers){var i={},r=this.normalizeUIKeys(_.result(this,"triggers"))
return _.each(r,function(r,e){i[e]=this._buildViewTrigger(r)},this),i}} @samccone using |
Also, @megawac why not add a |
Yup, the two reasons @thejameskyle pointed our was why I mentioned I dig if you want to reject. I would argue that this approach is more functional. Akin to how The performance issue observed with using |
And I've been wanting to add |
Yep this is the same rational I have |
Opened a PR in underscore to add |
While it might be more "functional" (sorry, I have trouble using that word when describing underscore methods), the issue I take with this (besides what I've already mentioned about performance and file size) is that I don't think a |
Discussion happened off thread. The consensus was that this was a nice stylistic change. |
Use reduce in View.configureTriggers
Minor refactor. This is how I'd write this function. Feel free to reject