Permalink
Browse files

[style] declare variables at the top level of scope they are used

  • Loading branch information...
nateps committed Mar 1, 2014
1 parent 622bf66 commit dfb77c50728f4aeafd954a53681eac1db4bd3ff7
Showing with 21 additions and 14 deletions.
  1. +0 −1 .jshintrc
  2. +5 −3 lib/Model/Query.js
  3. +9 −6 lib/Model/fn.js
  4. +4 −2 lib/Model/ref.js
  5. +3 −2 lib/Model/refList.js
View
@@ -8,7 +8,6 @@
"quotmark": "single",
"undef": true,
"trailing": true,
- "funcscope": true,
"shadow": true,
"expr": true,
"boss": true
View
@@ -354,8 +354,9 @@ Query.prototype.unsubscribe = function(cb) {
var count = --query.subscribeCount;
if (count) return cb(null, count);
+ var ids;
if (query.shareQuery) {
- var ids = resultsIds(query.shareQuery.results);
+ ids = resultsIds(query.shareQuery.results);
query.shareQuery.destroy();
query.shareQuery = null;
}
@@ -409,9 +410,10 @@ Query.prototype._onChange = function(ids, previousIds, cb) {
// have a value from a fetch or previous shareQuery instance
this.model._setDiff(this.idSegments, ids);
+ var group, finished;
if (cb) {
- var group = util.asyncGroup(cb);
- var finished = group();
+ group = util.asyncGroup(cb);
+ finished = group();
}
for (var i = 0; i < diff.length; i++) {
var item = diff[i];
View
@@ -30,22 +30,25 @@ Model.prototype.fn = function(name, fns) {
};
function parseStartArguments(model, args, hasPath) {
+ var fns, name;
if (typeof args[0] === 'function') {
- var fns = args[0];
+ fns = args[0];
} else {
- var name = args[0];
+ name = args[0];
}
+ var path, inputPaths;
if (hasPath) {
- var path = model.path(args[1]);
- var inputPaths = Array.prototype.slice.call(args, 2);
+ path = model.path(args[1]);
+ inputPaths = Array.prototype.slice.call(args, 2);
} else {
- var inputPaths = Array.prototype.slice.call(args, 1);
+ inputPaths = Array.prototype.slice.call(args, 1);
}
var i = inputPaths.length - 1;
+ var options;
if (model.isPath(inputPaths[i])) {
inputPaths[i] = model.path(inputPaths[i]);
} else {
- var options = inputPaths.pop();
+ options = inputPaths.pop();
}
while (i--) {
inputPaths[i] = model.path(inputPaths[i]);
View
@@ -113,8 +113,9 @@ function addListener(model, type, fn) {
// is pointing. All original mutations happen on the fully dereferenced
// location, so this detection only needs to happen in one direction
var toMap = model._refs.toMap;
+ var subpath;
for (var i = 0, len = segments.length; i < len; i++) {
- var subpath = (subpath) ? subpath + '.' + segments[i] : segments[i];
+ subpath = (subpath) ? subpath + '.' + segments[i] : segments[i];
// If a ref is found pointing to a matching subpath, re-emit on the
// place where the reference is coming from as if the mutation also
// occured at that path
@@ -223,9 +224,10 @@ Model.prototype._dereference = function(segments, forArrayMutator, ignore) {
if (segments.length === 0) return segments;
var refs = this.root._refs.fromMap;
var refLists = this.root._refLists.fromMap;
+ var doAgain;
do {
var subpath = '';
- var doAgain = false;
+ doAgain = false;
for (var i = 0, len = segments.length; i < len; i++) {
subpath = (subpath) ? subpath + '.' + segments[i] : segments[i];
View
@@ -392,13 +392,14 @@ Model.prototype.refList = function() {
options = arguments[3];
}
var fromPath = this.path(from);
+ var toPath;
if (Array.isArray(to)) {
- var toPath = [];
+ toPath = [];
for (var i = 0; i < to.length; i++) {
toPath.push(this.path(to[i]));
}
} else {
- var toPath = this.path(to);
+ toPath = this.path(to);
}
var idsPath = this.path(ids);
var refList = this.root._refLists.add(fromPath, toPath, idsPath, options);

0 comments on commit dfb77c5

Please sign in to comment.