mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 01:51:40 -05:00
Moved paginated sub into a package
This commit is contained in:
parent
17304f3f1a
commit
1974ac0386
5 changed files with 12 additions and 57 deletions
|
@ -12,4 +12,5 @@ router
|
|||
moment
|
||||
spiderable
|
||||
email
|
||||
database-forms
|
||||
database-forms
|
||||
paginated-subscription
|
||||
|
|
|
@ -110,7 +110,7 @@ var sortBy = function(sortProperty){
|
|||
}
|
||||
|
||||
var postListSubscription = function(find, options, per_page) {
|
||||
var handle = paginatedSubscription(per_page, 'paginatedPosts', find, options);
|
||||
var handle = Meteor.subscribeWithPagination('paginatedPosts', find, options, per_page);
|
||||
handle.fetch = function() {
|
||||
return limitDocuments(Posts.find(find, options), handle.loaded());
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
PaginatedSubscriptionHandle = function(perPage) {
|
||||
this.perPage = perPage;
|
||||
this._limit = perPage;
|
||||
this._limitListeners = new Deps.Dependency();
|
||||
this._loaded = 0;
|
||||
this._loadedListeners = new Deps.Dependency();
|
||||
}
|
||||
|
||||
PaginatedSubscriptionHandle.prototype.loaded = function() {
|
||||
Deps.depend(this._loadedListeners);
|
||||
return this._loaded;
|
||||
}
|
||||
|
||||
PaginatedSubscriptionHandle.prototype.limit = function() {
|
||||
Deps.depend(this._limitListeners);
|
||||
return this._limit;
|
||||
}
|
||||
|
||||
PaginatedSubscriptionHandle.prototype.loading = function() {
|
||||
return this.loaded() < this.limit();
|
||||
}
|
||||
|
||||
PaginatedSubscriptionHandle.prototype.loadNextPage = function() {
|
||||
this._limit += this.perPage;
|
||||
this._limitListeners.changed();
|
||||
}
|
||||
|
||||
PaginatedSubscriptionHandle.prototype.done = function() {
|
||||
// XXX: check if subs that are canceled before they are ready ever fire ready?
|
||||
// if they do we need to increase loaded by perPage, not set it to limit
|
||||
this._loaded = this._limit;
|
||||
this._loadedListeners.changed();
|
||||
}
|
||||
|
||||
|
||||
// XXX: somehow? support the last argument being a callback for ready?
|
||||
paginatedSubscription = function (perPage/*, name, arguments */) {
|
||||
var handle = new PaginatedSubscriptionHandle(perPage);
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
|
||||
Meteor.autorun(function() {
|
||||
var ourArgs = _.map(args, function(arg) {
|
||||
return _.isFunction(arg) ? arg() : arg;
|
||||
});
|
||||
|
||||
var subHandle = Meteor.subscribe.apply(this, ourArgs.concat([
|
||||
handle.limit(), function() { handle.done(); }
|
||||
]));
|
||||
handle.stop = subHandle.stop;
|
||||
});
|
||||
|
||||
return handle;
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
"branch": "beforeRouting"
|
||||
},
|
||||
"moment": {},
|
||||
"database-forms": {}
|
||||
"database-forms": {},
|
||||
"paginated-subscription": {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
"branch": "beforeRouting"
|
||||
},
|
||||
"moment": {},
|
||||
"database-forms": {}
|
||||
"database-forms": {},
|
||||
"paginated-subscription": {}
|
||||
},
|
||||
"packages": {
|
||||
"router": {
|
||||
|
@ -29,6 +30,11 @@
|
|||
"tag": "v0.0.2",
|
||||
"commit": "9e21c15aca103a18013b6d518fe5b116f16368f0"
|
||||
},
|
||||
"paginated-subscription": {
|
||||
"git": "https://github.com/tmeasday/meteor-paginated-subscription.git",
|
||||
"tag": "v0.1.0",
|
||||
"commit": "623fe77698dbfdfdfdb52855c1ba19f29aca8047"
|
||||
},
|
||||
"page-js-ie-support": {
|
||||
"git": "https://github.com/tmeasday/meteor-page-js-ie-support.git",
|
||||
"tag": "v1.3.5",
|
||||
|
|
Loading…
Add table
Reference in a new issue