A package which does the following:
//vanilla
Meteor.publish('nameOfSub',fn2);
//conditional
Meteor.conditionalPublish('nameOfSub',fn1,fn2);
fn2
is the standard publication function, and is only called if fn1
returns true
.
fn1
is the predicate function which is given one argument: subsArray
. The subsArray
passed to fn1
is an array of currently active subscriptions for that connection with the same name; 'nameOfSub'
in the example above.
Usages
-
Checking arguments. This would allow us to separate publication logic from
check
orMatch
and other checking logic. -
Checking for enough change. When the arguments to a publication fall on an approx. continuous spectrum (e.g. geolocation coordinate pairs), usually we do not want to republish a data set if the input parameters change by a very small dX. So, we can check in the predicate function if the current input parameters differ enough from the previous ones.
-
Checking for enough change in non-reactive queries. For non-reactive publications, (e.g. aggregate queries), it is common to have a notion of change/distance, which should be used to determine if we should rerun the aggregate query (e.g. if the timestamp differs by less than 1 hour, don’t rerun the query, since our data’s ~period of change may be 5 hours)
Of course, you can do all of this using the vanilla Meteor.publish
, but I think it is more pretty/readable to separate all predicate logic from the publication logic.
I was thinking about writing this package. If anyone is interested in this package or wants to work on it too, let me know. If you have a better design approach, please let me know.
Thanks!