Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noReady functionality for publish #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

aaronthorp
Copy link

Added noReady: true option to options variable allowing optional ready state to allow for in-publish aggregation similar to tmeasday:publish-counts.

Example use: eCommerce store listing products, aggregation to get distinct brand field for filtering using the existing search keywords or product category/other filters selected.

Also modified export to default export to allow for use of

import ReactiveAggregate from 'meteor/jcbernack:reactive-aggregate'

instead of

import { ReactiveAggregate } from 'meteor/jcbernack:reactive-aggregate'

as there are no other variables for importing from this package.

Meteor.publish('search', function(query, limit, skip) {
        let filter = _buildSearchQuery(query.keyword)
       
        var data = Products.find(filter, {limit, skip})
        
        Meteor.defer(() => {
            ReactiveAggregate(this, Products, [
                { $match: filter },
                { $group: { _id: '$brand', count: { $sum: 1 } } }
            ], { clientCollection: 'filterBrand', noReady: true })

            ReactiveAggregate(this, Products, [
                { $match: filter },
                { $group: { _id: '$category_id', count: { $sum: 1 } } }
            ], { clientCollection: 'filterCategories', noReady: true })
        })

        Counts.publish(this, "searchCount", Products.find(filter), {noReady: true})
        
        return data
    } else {
        this.stop()
    }
})

aggregate.js Outdated
...options
});

export const ReactiveAggregate = function (subscription, collection, pipeline = [], options = {}) {
export default ReactiveAggregate = function (subscription, collection, pipeline = [], options = {}) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, please use export default function ReactiveAggregate(...).

@JcBernack
Copy link
Owner

Thanks. Please fix the one export issue and I will merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants