Code Monkey home page Code Monkey logo

Comments (9)

reywood avatar reywood commented on May 18, 2024 2

The find function can return any falsy value (e.g., null, undefined, false, etc) to short circuit. This effectively returns an empty set. You should never call this.ready() or this.stop() in find functions.

For example:

Meteor.publishComposite("mypub", {
    find: function() {
        if (!this.user) {
            return;
        }

        return MyCollection.find({ ... });
    }
});

from meteor-publish-composite.

bitomule avatar bitomule commented on May 18, 2024

And what happens if you didn't return nothing? Can that cause problems?

from meteor-publish-composite.

reywood avatar reywood commented on May 18, 2024

Doing return; is equivalent to return undefined; which is perfectly fine.

from meteor-publish-composite.

bitomule avatar bitomule commented on May 18, 2024

Yeah, but what happens if a find doesn't return anything, like:

Find:{
   If(bla){
       return find...
   }
}

from meteor-publish-composite.

reywood avatar reywood commented on May 18, 2024

Collection.find() always returns a cursor, so that's fine. It doesn't matter if there are records in it or if it's empty.

from meteor-publish-composite.

bitomule avatar bitomule commented on May 18, 2024

Sorry, maybe I didn't explain it well but my question was what happens if bla (in this case) is false so collection.find is never fired. No return is called.

from meteor-publish-composite.

reywood avatar reywood commented on May 18, 2024

Ah, I see. That is also equivalent to return undefined; so no problem.

from meteor-publish-composite.

bitomule avatar bitomule commented on May 18, 2024

ok thanks :)

from meteor-publish-composite.

s-devaney avatar s-devaney commented on May 18, 2024

In the native Meteor publish method, returning an empty cursor (i.e. []) works (although this.stop() is best practice) but doing this in publishComposite results in an error, it might be good to replicate this behavior? Although a return statement works. as described above.

from meteor-publish-composite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.