Skip to content

athiwatc/meteor-lazy-subscription

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lazy Subscription

Overview

Lazy Subscription allows you to subscribe to collection when you need it. It is an easy way to write big application that need to load a lot of collection over an amount of pages.

Installation

mrt add lazy-subscription

Uses

First you must define the collection to be independence of server and client side.

/server/publish.js

//This is no longer share with the client.
Post = new Meteor.Collection('post');
Meteor.publish('posts', function() {
	//Just a normal publish function.
	return Post.find({});
});

/client/subscribe.js

//Post = new Meteor.Collection('post'); No longer exists. Lazy will deal with it for us.
Post = new Meteor.Lazy('post', function() {
	Meteor.subscribe('posts');
});

/client/some_template.js

Template.some_template.get_posts = function() {
	return Post().find({}); //Note that Post is now a function.
};

Notes

This should be use in reactive context or else on the first run you will get an empty collection.

About

Don't subscribe until you need to.

Resources

Stars

Watchers

Forks

Packages

No packages published