mirror of
https://github.com/vale981/grapher
synced 2025-03-05 09:31:42 -05:00
Fixed #206 - params aware reducers
This commit is contained in:
parent
51fa2e3d43
commit
04ad543d96
4 changed files with 35 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -63,5 +63,13 @@ Authors.addReducers({
|
|||
|
||||
return object.profile.firstName + ' ' + object.profile.lastName;
|
||||
}
|
||||
},
|
||||
paramBasedReducer: {
|
||||
body: {
|
||||
_id: 1,
|
||||
},
|
||||
reduce(object, params) {
|
||||
return params.element;
|
||||
}
|
||||
}
|
||||
});
|
|
@ -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');
|
||||
})
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue