2021-09-07 04:51:42 +08:00
|
|
|
import { Tracker } from 'meteor/tracker';
|
|
|
|
|
|
|
|
export const subscriptionReactivity = new Tracker.Dependency();
|
|
|
|
// Create the subscription and store its data to use in the client (E.G. subscriptionId)
|
|
|
|
class SubscriptionRegistry {
|
|
|
|
constructor() {
|
|
|
|
this.registry = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
createSubscription(subscription, options, ...params) {
|
|
|
|
const opt = { ...options };
|
|
|
|
opt.onStop = () => {
|
|
|
|
subscriptionReactivity.changed();
|
2023-01-17 22:30:25 +08:00
|
|
|
if (options?.onStop) options.onStop();
|
2021-09-07 04:51:42 +08:00
|
|
|
this.registry[subscription] = null;
|
|
|
|
};
|
|
|
|
this.registry[subscription] = Meteor.subscribe(subscription, ...params, opt);
|
|
|
|
return this.registry[subscription];
|
|
|
|
}
|
|
|
|
|
|
|
|
getSubscription(name) {
|
|
|
|
return this.registry[name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new SubscriptionRegistry();
|