//
Publications VS static data fetching in Meteor.js
Search
Notion
Publications VS static data fetching in Meteor.js
Written on
Empty
Updated on
Empty
Using publications + subscriptions
// server Meteor.publish("plans", () => Plans.find()); // client const { loading, plans } = useTracker(() => { const subscription = Meteor.subscribe("plans"); return { loading: !subscription.ready(), plans: Plans.find({}, { sort: { price: 1 } }).fetch(), }; });
JavaScript
👍 Pros
A
B
C
👎 Cons
A
B
C
Using methods
// server + client (for optimistic UI) import { ValidatedMethod } from "meteor/mdg:validated-method"; import { CallPromiseMixin } from "meteor/didericis:callpromise-mixin"; export const getPlans = new ValidatedMethod({ name: "plans.get", mixins: [CallPromiseMixin], validate: null, run({ query = {}, options = {} } = {}) { return Plans.find(query, options).fetch(); }, }); // client const [loading, setLoading] = useState(true); const [plans, setPlans] = useState([]); useEffect(() => { getPlans .callPromise({ options: { sort: { price: 1 } } }) .then((result) => setPlans(result)) .catch((error) => console.warn(error)) .finally(setLoading(false)); }, []);
JavaScript
💡
Using mdg:validated-method and meteor/didericis:callpromise-mixin is not strictly necessary, but I like it for promisifying the method call.
👍 Pros
A
B
C
👎 Cons
More verbose
B
C
// server + client (for optimistic UI) //TODO // client //TODO
JavaScript
💡
Using mdg:validated-method and meteor/didericis:callpromise-mixin is not strictly necessary, but I like it for promisifying the method call.
👍 Pros
A
B
C
👎 Cons
External dependency
Doesn't seem in active development
Using React Query plus methods
// server + client (for optimistic UI) //TODO // client // TODO
JavaScript
👍 Pros
A
B
C
👎 Cons
More verbose
B
C