Skip to content

Instantly share code, notes, and snippets.

@themeteorchef
Created January 21, 2016 02:51
Show Gist options
  • Select an option

  • Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.

Select an option

Save themeteorchef/af54bae2979c06e47267 to your computer and use it in GitHub Desktop.

Revisions

  1. themeteorchef created this gist Jan 21, 2016.
    12 changes: 12 additions & 0 deletions paginated-publication.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    Meteor.publish( 'pagination', function( collection, split, page ) {
    check( collection, String );
    check( split, Number );
    check( page, Match.OneOf( String, Number ) );

    var documents = global[ collection ].find( {}, { fields: { _id: 1 } } ).fetch(),
    documentChunks = _.chunk( documents, split ),
    filter = page ? parseInt( page, 10 ) : 0,
    ids = _.map( documentChunks[ filter ], '_id' );

    return global[ collection ].find( { _id: { $in: ids } } );
    });
    2 changes: 2 additions & 0 deletions subscription.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    // API: pagination subscription, collection to paginate's global var, number of items per page, current page.
    Meteor.subscribe( 'pagination', 'CollectionGlobalVar', 10, this.params.page );