Fixed #206 - params aware reducers

This commit is contained in:
Theodor Diaconu 2017-12-21 19:59:29 +02:00
parent 51fa2e3d43
commit 04ad543d96
4 changed files with 35 additions and 4 deletions

View file

@ -11,7 +11,10 @@ function hypernova(collectionNode, userId) {
});
}
export default function hypernovaInit(collectionNode, userId, config = {bypassFirewalls: false, params: {}}) {
export default function hypernovaInit(collectionNode, userId, config = {}) {
const bypassFirewalls = config.bypassFirewalls || false;
const params = config.params || {};
let {filters, options} = applyProps(collectionNode);
const collection = collectionNode.collection;

View file

@ -12,10 +12,10 @@ export default class ReducerNode {
* @param {*} args
*/
compute(object, ...args) {
object[this.name] = this.reduce.call(null, object, ...args);
object[this.name] = this.reduce.call(this, object, ...args);
}
reduce(object, ...args) {
return this.reduceFunction.call(null, object, ...args);
return this.reduceFunction.call(this, object, ...args);
}
}

View file

@ -63,5 +63,13 @@ Authors.addReducers({
return object.profile.firstName + ' ' + object.profile.lastName;
}
},
paramBasedReducer: {
body: {
_id: 1,
},
reduce(object, params) {
return params.element;
}
}
});

View file

@ -154,4 +154,24 @@ describe('Reducers', function () {
})
})
});
});
it('Should work with params reducers', function () {
const query = createQuery({
authors: {
$options: {limit: 1},
paramBasedReducer: 1,
}
});
query.setParams({
element: 'TEST_STRING'
});
const data = query.fetch();
assert.isTrue(data.length > 0);
data.forEach(author => {
assert.equal(author.paramBasedReducer, 'TEST_STRING');
})
});
});