mrt:lazy-subscription

v0.0.2Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

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

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

/client/subscribe.js

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

/client/some_template.js

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

Notes

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