Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here

subs-manager

Subscriptions Manager for Meteor

Subscribe to updates I use subs-manager


Statistics on subs-manager

Number of watchers on Github 359
Number of open issues 47
Average time to close an issue about 2 months
Main language JavaScript
Average time to merge a PR about 2 hours
Open pull requests 8+
Closed pull requests 0+
Last commit over 3 years ago
Repo Created about 5 years ago
Repo Last Updated over 1 year ago
Size 64 KB
Organization / Authorkadirahq
Contributors7
Page Updated
Do you use subs-manager? Leave a review!
View open issues (47)
View subs-manager activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating subs-manager for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

SubsManager Build Status

Subscriptions Manager for Meteor

This is a general-purpose subscriptions manager for Meteor. You can use Subscription Manager to cache subscriptions in the client side. This will help you to reduce the CPU usage of your app and improve the client side experience.

Why?

Normally you invoke subscriptions inside the template level or in the router level(in the case of Iron Router). So, when you are switching routes or changing templates/components, subscriptions will run again.

Normally, users go back and forth in your app in a single session. So, in each those route/page changes, app will re-subscribe data from the server. That's a waste and slow down your app in the client side.

Solution

Subscriptions Manager caches your subscriptions in the client side. So, when the user switching between routes, he will no longer have to wait. Also, Meteor won't need to re-send data that's already in the client.

In technical terms, Subscriptions Manager runs it's own Tracker.autorun computation internally. It does not interfere with Router or Templates. It works independently.

Subscriptions Manager does not cache your individual data. It tells Meteor to cache the whole subscription. So, your data will get updated in the background as usual.

Usage

Installation:

meteor add meteorhacks:subs-manager

Then create a new SubsManager instance:

PostSubs = new SubsManager();

Then instead of subscribing to Meteor.subscribe(), use PostSubs.subscribe(). Check this example:

Template.blogPost.onCreated(function() {
    var self = this;
    self.ready = new ReactiveVar();
    self.autorun(function() {
        var postId = FlowRouter.getQueryParam('postId');
        var handle = PostSubs.subscribe('singlePost', postId);
        self.ready.set(handle.ready());
    });
});

Here's how this works:

  • Let's say you visit page /posts?postId=abc.
  • Then Meteor will subscribe to the singlePost publication with abc as the postId.
  • Then let's imagine you visit to /posts?postId=bbc.
  • Just like above, it'll subscribe to the singlePost publication with bbc as the postId.
  • Now, let's say we go back to /posts?postId=abc. Then, subsManager won't fetch data again from the server. Subscription is already exists inside the client.

Check following links for more information:

Resetting

Sometime, we need to re-run our subscriptions due to various reasons.

Eg:- After a user has update the plan.

In those situations, you can try to reset Subscription Manager.

var subs = new SubsManager();

// later in some other place
subs.reset();

Clear Subscriptions

In some cases, we need to clear the all the subscriptions we cache. So, this is how we can do it.

var subs = new SubsManager();

// later in some other place
subs.clear();

Cache Control

Since now you are caching subscriptions, the Meteor server will also cache all your client data. But don't worry - that's not a huge issue.

But, you can control the caching behavior. Here's how to do it.

var subs = new SubsManager({
    // maximum number of cache subscriptions
    cacheLimit: 10,
    // any subscription will be expire after 5 minute, if it's not subscribed again
    expireIn: 5
});

Patterns for using SubsManager

Using a global Subscription Manager

You can create a global subscription manager as shown in the above example. By doing that, all your subscriptions are cached as a whole.

Using separate Subscription Managers

If you need more control over caching, you can create separate Subscription Managers for each set of subscriptions and manage them differently.

If you are using SubsManager inside a ReactComponents, this is the suggested way.

Using global ready checking

You can also check the ready status of all the subscriptions at once like this:

var subs = new SubsManager();
subs.subscribe('postList');
subs.subscribe('singlePost', 'id1');

Tracker.autorun(function() {
  if(subs.ready()) {
    // all the subscriptions are ready to use.
  }
});

Cache subscriptions you only need

With Subscription Manager you don't need to use it everywhere. Simply use it wherever you need without changing other subscriptions.

Limitations

Subscription Manager aims to be a drop-in replacement for Meteor.subscribe (or this.subscribe() in Iron Router). At the moment, the following functionality doesn't work.

  • onError and onReady callbacks (issue)
subs-manager open issues Ask a question     (View All Issues)
  • almost 3 years Outdated for angular2-meteor
  • almost 3 years Cannot create a Subs-Manager within a Reactive computation
  • almost 3 years Has this become abandonware?
  • almost 3 years submanger lost connection
  • about 3 years If there are no subscriptions, then ready() is always false
  • about 3 years subs-manager continuous improvements
  • about 3 years SubsManager between two subscriptions
  • about 3 years subs.update()
  • about 3 years when the user logout the app, he still able to find collections on console
  • over 3 years error invoking SubsManager.subscribe: undefined
  • over 3 years Checking if a certain subscription is ready
  • over 3 years FlowRouter.go stops working after implementing SubsManager
  • over 3 years Bug in the code?
  • over 3 years Where should I declare the subscription/s?
  • over 3 years Subscription not expiring
  • almost 4 years Why is .ready() set to false when _cacheList.length === 0 ?
  • almost 4 years rendered callback does not fire when using subs manager
  • almost 4 years How to use with remote subscriptions (from cluster)
  • almost 4 years Manager interfering with ReactMeteorData
  • almost 4 years How to clear all template-level subscriptions from 'onLogin' callback
  • about 4 years Proposal - add subs.static property
  • about 4 years Set the website of this GitHub repo to the Atmopshere package
  • about 4 years infinite loop after 10 subscribe (cacheLimit)
  • about 4 years Pattern for updating a subscription limit argument
  • about 4 years Subs manager will send null as a subscription parameter
  • about 4 years Old documents are not resent?
  • over 4 years working with i18n-db
  • over 4 years I've just discovered this package and I am confused
  • over 4 years Subscription manager breaks the usage of iron router hooks.
  • over 4 years expire after stop()
subs-manager open pull requests (View All Pulls)
  • Unsubscribe a certain subscription
  • Manage a DDP connection to different server
  • Fixed onError issue
  • No expire, no cache limit.
  • fix/clear method
  • add {canonical:true} option to EJSON.stringify
  • Are you able to call subs.subscribe("mySub").stop() ? #28
  • account for the possibility of sub.ready() changing from true to false
subs-manager questions on Stackoverflow (View All Questions)
  • KADIRA Subs manager and observe MeteorJS
subs-manager list of languages used
Other projects in JavaScript