Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix bug due to the same filters being set up multiple times

  • Loading branch information...
commit 26291d756e56185783decb46c2eec609fc68757e 1 parent 5c4336c
@nateps nateps authored
Showing with 29 additions and 24 deletions.
  1. +7 −1 src/queries/QueryBuilder.js
  2. +22 −23 src/queries/util.js
View
8 src/queries/QueryBuilder.js
@@ -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;
};
View
45 src/queries/util.js
@@ -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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.