[Pkg-javascript-commits] [backbone] 103/173: Avoid nested ternary
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 07:44:08 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository backbone.
commit ff555e7664ad5424d5bf34514c024bb24e70c111
Author: Jordan Eldredge <jordan at jordaneldredge.com>
Date: Tue Dec 29 09:15:07 2015 -0800
Avoid nested ternary
While looking into adding the "no-nested-ternary" ESLint rule, I realized that
this logic could be refactored a bit.
This nested ternary was introduced in pull request #3875 in order to handle
falsy returns from `parse()`.
This refactor avoids the nested ternary and also makes the intent clearer by
associating the empty array directly with `parse()`'s return.
It also more narrowly handles the falsy case (we never intended to allow you
call `set(0)` for example.)
The only down side I can see is that if `parse()` returns falsy, we will
unnecessarily slice/clone the empty array we just created.
---
backbone.js | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/backbone.js b/backbone.js
index 371e5c8..62221ba 100644
--- a/backbone.js
+++ b/backbone.js
@@ -822,10 +822,12 @@
if (models == null) return;
options = _.defaults({}, options, setOptions);
- if (options.parse && !this._isModel(models)) models = this.parse(models, options);
+ if (options.parse && !this._isModel(models)) {
+ models = this.parse(models, options) || [];
+ }
var singular = !_.isArray(models);
- models = singular ? (models ? [models] : []) : models.slice();
+ models = singular ? [models] : models.slice();
var at = options.at;
if (at != null) at = +at;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git
More information about the Pkg-javascript-commits
mailing list