Code Monkey home page Code Monkey logo

meteor-paginated-subscription's Introduction

Meteor Paginated Subscription

This package is an experiment that adds pagination to Meteor's standard subscriptions. It's a byproduct of the Telescope project.

Installation

Install via Meteorite:

$ mrt add paginated-subscription

Usage

This package makes available a single function Meteor.subscribeWithPagination. Like the built in Meteor.subscribe, it returns a handle, which should be used to keep track of the state of the subscription:

var handle = Meteor.subscribeWithPagination('posts', 10);

The arguments are as usual to Meteor.subscribe, with two exceptions:

  1. The last argument must be a number, indicating the number of documents per page.
  2. There's no support for a onReady callback, see TODO below.

The paginated subscription expects you to have a publication setup, as normal, which expects as a final argument the current number of documents to display (which will be incremented, in a infinite scroll fashion):

Meteor.publish('posts', function(limit) {
  return Posts.find({}, {limit: limit});
});

The important part of all this is the handle, which has the following API:

  • handle.loaded() - how many documents are currently loaded via the sub
  • handle.limit() - how many have we asked for
  • handle.ready() - are we waiting on the server right now?
  • handle.loadNextPage() - fetch the next page of results

The first three functions are reactive and thus can be used to correctly display an 'infinite-scroll' like list of results. Please see the telescope project for an example of real-world usage.

TODO

Contributions are heavily encouraged. The obvious things to fix are:

  1. Allow an onReady callback
  2. Do actual "pagination" rather than "infinite scroll" -- i.e. have an option to pass around an offset as well as limit.
  3. Tests, tests, tests

Please contact me if you want to have a go at these and I'll be happy to help in what ways I can.

meteor-paginated-subscription's People

Contributors

tmeasday avatar

Watchers

James Cloos avatar Sidharth Shanker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.