Passing default parameter to publication?


#1

I’m using 1.3, React, and react-komposer.

In my container I am passing a session variable to my subscribe (which is passing it to my publish function).

Unfortunately the session variable (which holds the limit) is not initialized when it is passed to the subscribe function…

I tried to provide a default value for the parameter (tried both setting the default in the subscribe call and the publish function arguments, neither is working)

Does 1.3 have this feature? I thought it was ES2015 but is it es7?


#2

Usually, you do the following:

// server
Meteor.publish('posts.list', function ({limit = 10}) {
   return Posts.find({}, {limit});
});

// client

Meteor.subscribe("posts.list", {limit: 20});

Now, there is one gotcha as far as i remember: Do not pass null as limit, but i am not sure if this still leads to problem.


#3

I’m doing this and getting an error:

server:

Meteor.publish('messages', (currentLimit = 10) => {
	check(currentLimit, Number);
	return Messages.find({},{ limit: currentLimit });
});

client:

let messagesSub = Meteor.subscribe('messages', Session.get( "messageLimit"));

the error:

Exception from sub messages id ZBqrs4yEnF8zZtwLC Error: Match error: Expected number, got null

I am initiating the session variable in a componentWillMount and the subscribe is happening in a react-komposer container that is the parent (I guess) of the component with the componentWillMount. I would think that if the session variable isn’t set yet, than it should trigger the publication to just use 10… but I guess not?