Closed carlosalvidrez closed 6 years ago
Do you have any other reactive variables that you use in the autorun?
Autorun will be executed anytime one of the reactive variables change their value. If you're only using this.pagination.ready()
it is probably called once when it is false
and another time when it is true
(you could ignore the first false
by using a template variable (this.isInit = true/false))
Thanks. Like this?
if( ! this.pagination.ready()) { console.log( "passage.created.js - autorun - this.pagination.ready() NOT:" , this.pagination.ready() ); this.isInit = false; }
Yes, you can write something like this to avoid the first autorun call:
Template.MyList.onCreated(function() {
this.pagination = new Meteor.Pagination(Collection);
const pagination = this.pagination;
let isInit = true;
this.autorun(function () {
if (isInit) {
isInit = false;
} else {
// execute code related to this.pagination.ready()
}
});
});
Got it, thanks! Sorry, I thought this.isInit was invoking some existing meteor property : )
I am placing a "this.pagination.ready()" within my template autorun, and I notice that it causes the autorun to execute twice. Is there a way to handle this so the autorun only gets called once? I realize I may be missing something : )
PS. Thank you for your patience and super helpful answers.