mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 04:26:41 -04:00
add second autorun to reset limit when changing data context
This commit is contained in:
parent
0658f172ea
commit
22229dc8cb
1 changed files with 9 additions and 3 deletions
|
@ -7,7 +7,6 @@ for the embedded postsList template. It receives its parameters from a "caller"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
Template.postsListController.onCreated(function () {
|
Template.postsListController.onCreated(function () {
|
||||||
|
|
||||||
// 1. Initialization (*not* reactive!)
|
// 1. Initialization (*not* reactive!)
|
||||||
|
@ -19,7 +18,14 @@ Template.postsListController.onCreated(function () {
|
||||||
|
|
||||||
// 2. Autorun
|
// 2. Autorun
|
||||||
|
|
||||||
// will re-run when terms are changed, either by the router or by the template itself
|
// Autorun 1: when terms change, reset the limit
|
||||||
|
instance.autorun(function () {
|
||||||
|
// add a dependency on data context to trigger the autorun
|
||||||
|
var terms = Template.currentData().terms; // ⚡ reactive ⚡
|
||||||
|
instance.postsLimit.set(Settings.get('postsPerPage', 10));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Autorun 2: will re-run when limit or terms are changed
|
||||||
instance.autorun(function () {
|
instance.autorun(function () {
|
||||||
|
|
||||||
// get terms from data context
|
// get terms from data context
|
||||||
|
@ -38,10 +44,10 @@ Template.postsListController.onCreated(function () {
|
||||||
var subscriptionsReady = instance.subscriptionsReady(); // ⚡ reactive ⚡
|
var subscriptionsReady = instance.subscriptionsReady(); // ⚡ reactive ⚡
|
||||||
|
|
||||||
// console.log('// ------ autorun running ------ //');
|
// console.log('// ------ autorun running ------ //');
|
||||||
// Tracker.onInvalidate(console.trace.bind(console));
|
|
||||||
// console.log("terms: ", terms);
|
// console.log("terms: ", terms);
|
||||||
// console.log("limit: ", postsLimit);
|
// console.log("limit: ", postsLimit);
|
||||||
// console.log("ready: ", subscriptionsReady);
|
// console.log("ready: ", subscriptionsReady);
|
||||||
|
// Tracker.onInvalidate(console.trace.bind(console));
|
||||||
|
|
||||||
// if subscriptions are ready, set terms to subscriptionsTerms
|
// if subscriptions are ready, set terms to subscriptionsTerms
|
||||||
if (subscriptionsReady) {
|
if (subscriptionsReady) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue