How to create non reactive publications in meteor?
I have few documents in one collection and I want to send the data to client on first load and I don’t want to receive new updates in client, how to do this?
I tried simply {reactive: false}
Meteor.publish('industries', function () {
return Industry.find({},{reactive: false})
});
but looks like {reactive: false} is client side options.
I can give this options to the cursor wherever I’m using the cursor, but still I doubt that server sends data reactively.
I don’t want to waste the server memory (merge box storage where it keeps track of that data).
I know I can use meteor methods, but I’m using this subscription lot of places in my app like 10-20 times so rewriting is bit of work.
Is there any simple way to do this like adding {reactive: false} options
there may be lot of use cases where user don’t need reactivity in publications I think.
Here is a way to make a non-reactive subscription.
Use fast-render and remove Meteor.subscribe() altogether.
You will get data injected into HTML on the client, but technically never subscribe to it on the server.
IMHO the better way to do this is to skip subscriptions all together. Just create a Meteor method that returns the same data that the publication would (just make sure to call fetch so you don’t return the cursor). You’ll need to use the same permissions checks if it has sensitive data.
Blonk does this with the jobs ‘feed’ so that when you’re swiping the card doesn’t change while you’re swiping (makes it jitter).
If you need to persist the data on a hot reload you can use Session or a reactive dict to store it in.
It depends on what you’re calling reactivity here. In my example you’ll receive the initial document set and no subsequent updated or removed messages, so the data will remain static on the client end.
Your blog post is about getting data from a 3rd party API, which isn’t reactive, I assume.
But can you make a publication non-reactive coming from native Meteor Mongo instance with .added?
Not in this case as we’re grabbing data from the collection within the publication (which is on the server). What makes the example “non reactive” is that we’re only sending added messages once after initially subscribing.
Does this method of publishing incurs server overhead for maintaining the publication? (like for reactive pubs)
Say, if 10K clients will subscribe, will the server require more RAM and CPU?
FWIW (ideally) if you’re starting from scratch today I would recommend getting into Apollo and use the GraphQL mutations… it’s kind of like a combo of simple-schema and meteor methods (the schema determines what the client is allowed to get back). However I realize that’s a lot of overhead for some but yeah Meteor methods have served me very well over the years!