Skip to content

Commit

Permalink
fix bug due to the same filters being set up multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
nateps committed Jul 10, 2012
1 parent 5c4336c commit 26291d7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
8 changes: 7 additions & 1 deletion src/queries/QueryBuilder.js
Expand Up @@ -277,7 +277,13 @@ QueryBuilder.hash = function (json, filterFn) {
}
}

if (filterFn) return hash += SEP + 'filterFn' + SEP + noDots(filterFn.toString());
if (filterFn) {
// TODO: Do a less ghetto hash function here
hash += SEP + 'filterFn' + SEP +
filterFn.toString().replace(/[\s(){},.]/g, function(match) {
return match.charCodeAt(0);
});
}

return hash;
};
Expand Down
45 changes: 22 additions & 23 deletions src/queries/util.js
Expand Up @@ -42,37 +42,36 @@ function setupQueryModelScope (model, memoryQuery, queryId, initialResult) {
, refPath = resultRefPath(queryId, queryType)
, pointerPath = resultPointerPath(queryId, queryType)
, ns = memoryQuery.ns
, scopedModel;
, scopedModel, listener;

if (model.get(refPath)) return model.at(refPath);
if (model[refPath]) return model.at(refPath);

// Refs, assemble!
switch (queryType) {
case 'findOne':
// TODO Test findOne single query result
if (initialResult) {
model.set(pointerPath, initialResult.id);
}
if (queryType === 'findOne') {
// TODO Test findOne single query result
if (initialResult) {
model.set(pointerPath, initialResult.id);
}

scopedModel = model.ref(refPath, ns, pointerPath);
scopedModel = model.ref(refPath, ns, pointerPath);

var listener = createMutatorListener(model, pointerPath, ns, scopedModel, memoryQuery);
model.on('mutator', listener);
break;
} else {
if (initialResult) {
model.set(pointerPath, initialResult.map( function (doc) {
return doc.id;
}));
}

case 'find':
default:
if (initialResult) {
model.set(pointerPath, initialResult.map( function (doc) {
return doc.id;
}));
}
scopedModel = model.refList(refPath, ns, pointerPath);
}

scopedModel = model.refList(refPath, ns, pointerPath);
listener = createMutatorListener(model, pointerPath, ns, scopedModel, memoryQuery);
model.on('mutator', listener);

// TODO: This is a total hack. Fix the initialization of filters in client
// and prevent filters from generating multiple listeners
model[refPath] = listener;

var listener = createMutatorListener(model, pointerPath, ns, scopedModel, memoryQuery);
model.on('mutator', listener);
}
return scopedModel;
}

Expand Down

0 comments on commit 26291d7

Please sign in to comment.