mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
use Subs Manager for some template-level subscriptions to fix post page content flash issue
This commit is contained in:
parent
8fa0507a65
commit
9eef5fdf07
9 changed files with 31 additions and 28 deletions
|
@ -5,9 +5,9 @@ Comments.controllers = {};
|
|||
Comments.controllers.page = RouteController.extend({
|
||||
waitOn: function() {
|
||||
return [
|
||||
coreSubscriptions.subscribe('singleCommentAndChildren', this.params._id),
|
||||
coreSubscriptions.subscribe('commentUsers', this.params._id),
|
||||
coreSubscriptions.subscribe('commentPost', this.params._id)
|
||||
Telescope.subsManager.subscribe('singleCommentAndChildren', this.params._id),
|
||||
Telescope.subsManager.subscribe('commentUsers', this.params._id),
|
||||
Telescope.subsManager.subscribe('commentPost', this.params._id)
|
||||
];
|
||||
},
|
||||
data: function() {
|
||||
|
|
|
@ -31,4 +31,11 @@ if(Meteor.isServer) {
|
|||
});
|
||||
}
|
||||
|
||||
Telescope.controllers = {};
|
||||
Telescope.controllers = {};
|
||||
|
||||
Telescope.subsManager = new SubsManager({
|
||||
// cache recent 50 subscriptions
|
||||
cacheLimit: 50,
|
||||
// expire any subscription after 30 minutes
|
||||
expireIn: 30
|
||||
});
|
||||
|
|
|
@ -165,12 +165,6 @@ Router._filters = {
|
|||
};
|
||||
|
||||
var filters = Router._filters;
|
||||
coreSubscriptions = new SubsManager({
|
||||
// cache recent 50 subscriptions
|
||||
cacheLimit: 50,
|
||||
// expire any subscription after 30 minutes
|
||||
expireIn: 30
|
||||
});
|
||||
|
||||
Meteor.startup( function (){
|
||||
|
||||
|
|
|
@ -109,7 +109,4 @@ Package.onUse(function(api) {
|
|||
"i18n/zh-CN.i18n.json"
|
||||
], ["client", "server"]);
|
||||
|
||||
api.export([
|
||||
'coreSubscriptions'
|
||||
]);
|
||||
});
|
||||
|
|
|
@ -6,7 +6,7 @@ Template.user_invites.created = function () {
|
|||
instance.invites = new ReactiveVar({});
|
||||
|
||||
Meteor.autorun(function () {
|
||||
coreSubscriptions.subscribe('invites', user._id);
|
||||
Telescope.subsManager.subscribe('invites', user._id);
|
||||
var invites = Invites.find({invitingUserId: user._id});
|
||||
instance.invites.set(invites);
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ Package.onUse(function (api) {
|
|||
'matb33:collection-hooks@0.7.11',
|
||||
'chuangbo:marked@0.3.5',
|
||||
'meteorhacks:fast-render@2.3.2',
|
||||
'meteorhacks:subs-manager@1.3.0',
|
||||
'meteorhacks:subs-manager@1.4.0',
|
||||
'percolatestudio:synced-cron@1.1.0',
|
||||
'useraccounts:unstyled@1.8.1',
|
||||
'manuelschoebel:ms-seo@0.4.1',
|
||||
|
|
|
@ -16,6 +16,10 @@ Template.posts_list_controller.onCreated(function () {
|
|||
instance.terms = new ReactiveVar(instance.data.terms);
|
||||
instance.postsLimit = new ReactiveVar(Settings.get('postsPerPage', 10));
|
||||
|
||||
// if caching is set to true, use Subs Manager. Else use template.subscribe. Default to false
|
||||
var enableCache = (typeof instance.data.terms.enableCache === "undefined") ? false : instance.data.terms.enableCache;
|
||||
var subscriber = enableCache ? Telescope.subsManager : instance;
|
||||
|
||||
// 2. Autorun
|
||||
|
||||
// Autorun 1: when terms change, reset the limit
|
||||
|
@ -38,10 +42,10 @@ Template.posts_list_controller.onCreated(function () {
|
|||
var subscriptionTerms = _.extend(_.clone(terms), {limit: postsLimit}); // extend terms with limit
|
||||
|
||||
// use this new object to subscribe
|
||||
var postsSubscription = instance.subscribe('postsList', subscriptionTerms);
|
||||
var usersSubscription = instance.subscribe('postsListUsers', subscriptionTerms);
|
||||
var postsSubscription = subscriber.subscribe('postsList', subscriptionTerms);
|
||||
var usersSubscription = subscriber.subscribe('postsListUsers', subscriptionTerms);
|
||||
|
||||
var subscriptionsReady = instance.subscriptionsReady(); // ⚡ reactive ⚡
|
||||
var subscriptionsReady = postsSubscription.ready() && usersSubscription.ready(); // ⚡ reactive ⚡
|
||||
|
||||
// console.log('// ------ autorun running ------ //');
|
||||
// console.log("terms: ", terms);
|
||||
|
|
|
@ -24,7 +24,8 @@ Posts.controllers.list = RouteController.extend({
|
|||
|
||||
var terms = {
|
||||
view: this.view,
|
||||
limit: this.params.limit || Settings.get('postsPerPage', 10)
|
||||
limit: this.params.limit || Settings.get('postsPerPage', 10),
|
||||
enableCache: true
|
||||
};
|
||||
|
||||
// console.log('----------------- router running');
|
||||
|
@ -115,10 +116,10 @@ Posts.controllers.page = RouteController.extend({
|
|||
|
||||
template: 'post_page',
|
||||
|
||||
waitOn: function () {
|
||||
this.postSubscription = coreSubscriptions.subscribe('singlePost', this.params._id);
|
||||
this.postUsersSubscription = coreSubscriptions.subscribe('postUsers', this.params._id);
|
||||
this.commentSubscription = coreSubscriptions.subscribe('commentsList', {view: 'postComments', postId: this.params._id});
|
||||
subscriptions: function () {
|
||||
this.postSubscription = Telescope.subsManager.subscribe('singlePost', this.params._id);
|
||||
this.postUsersSubscription = Telescope.subsManager.subscribe('postUsers', this.params._id);
|
||||
this.commentSubscription = Telescope.subsManager.subscribe('commentsList', {view: 'postComments', postId: this.params._id});
|
||||
},
|
||||
|
||||
post: function() {
|
||||
|
@ -210,8 +211,8 @@ Meteor.startup(function () {
|
|||
template: 'post_edit',
|
||||
waitOn: function () {
|
||||
return [
|
||||
coreSubscriptions.subscribe('singlePost', this.params._id),
|
||||
coreSubscriptions.subscribe('allUsersAdmin')
|
||||
Telescope.subsManager.subscribe('singlePost', this.params._id),
|
||||
Telescope.subsManager.subscribe('allUsersAdmin')
|
||||
];
|
||||
},
|
||||
data: function() {
|
||||
|
@ -244,7 +245,7 @@ Meteor.startup(function () {
|
|||
name: 'post_submit',
|
||||
template: 'post_submit',
|
||||
waitOn: function () {
|
||||
return coreSubscriptions.subscribe('allUsersAdmin');
|
||||
return Telescope.subsManager.subscribe('allUsersAdmin');
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ Users.controllers.page = RouteController.extend({
|
|||
|
||||
waitOn: function() {
|
||||
return [
|
||||
coreSubscriptions.subscribe('singleUser', this.params._idOrSlug)
|
||||
Telescope.subsManager.subscribe('singleUser', this.params._idOrSlug)
|
||||
];
|
||||
},
|
||||
|
||||
|
@ -47,7 +47,7 @@ Users.controllers.page = RouteController.extend({
|
|||
Users.controllers.edit = RouteController.extend({
|
||||
waitOn: function() {
|
||||
return [
|
||||
coreSubscriptions.subscribe('singleUser', this.params.slug)
|
||||
Telescope.subsManager.subscribe('singleUser', this.params.slug)
|
||||
];
|
||||
},
|
||||
data: function() {
|
||||
|
|
Loading…
Add table
Reference in a new issue