mirror of
https://github.com/vale981/Vulcan
synced 2025-03-09 20:16:39 -04:00
25 lines
861 B
JavaScript
25 lines
861 B
JavaScript
![]() |
import Mingo from 'mingo';
|
||
|
|
||
|
Mongo.Collection.prototype.findInStore = function (store, selector = {}, options = {}) {
|
||
|
const typeName = this.options && this.options.typeName;
|
||
|
const docs = _.where(store.getState().apollo.data, {__typename: typeName})
|
||
|
|
||
|
const mingoQuery = Mingo.Query(selector);
|
||
|
|
||
|
const cursor = mingoQuery.find(docs);
|
||
|
const sortedDocs = cursor.sort(options.sort).all();
|
||
|
|
||
|
// console.log('// findRedux')
|
||
|
// console.log("typeName: ", typeName)
|
||
|
// console.log("selector: ", selector)
|
||
|
// console.log("options: ", options)
|
||
|
// console.log("all docs: ", docs)
|
||
|
// console.log("selected docs: ", cursor.all())
|
||
|
// console.log("sorted docs: ", cursor.sort(options.sort).all())
|
||
|
|
||
|
return {fetch: () => sortedDocs};
|
||
|
}
|
||
|
|
||
|
Mongo.Collection.prototype.findOneInStore = function (store, _id) {
|
||
|
return this.findInStore(store, {_id}).fetch();
|
||
|
}
|