meteor-tabular
meteor-tabular copied to clipboard
Strange behaviour caused by adding Util.objectsAreEqual
I have a table whose selector is retrieved from template helper:
{{> tabular table=TabularTables.MyTable selector=selector id="myTable"}}
Template.myTemplate.onCreated(function(){
this.taskSelector = new TaskSelector();
});
Template.myTemplate.helpers({
selector: function() {
return Template.instance().taskSelector.getQuery();
}
});
The TaskSelector function above is a helper I use to quickly create a taskSelector - an object with methods to manipulate selector for the tabular table:
TaskSelector = function(query) {
this.selector = new ReactiveVar(query || {});
this.getQuery = function() {
return this.selector.get();
};
/* And other methods to manipulate this.selector */
};
So what we're doing here is very usual: Inside the selector template helper of myTemplate, we return the query value retrieved from the taskSelector object.
This works as expected for version 1.2.0 of the package, but doesn't work with 1.3.0+. When upgraded to 1.3.0+ the table no longer updates when my selector changes.
I was able to locate the part of the code causing this: It's the addition of Util.objectsAreEqual here. If we remove Util.objectsAreEqual, the table is updating normally again.
The problem seems to be, when my selector is updated, the oldVal and newVal inside Util.objectsAreEqual are always the same, preventing an actual ReactiveVar set. However, I'm not sure what is causing this.
I will take a look at that area of the code, but this will be easier to debug if you can create a simple reproduction app and link to the code.
Still have the same problem.
What i see while debug this part is that template.tabular.pubSelector is having the same value of pubSelector before the call to template.tabular.pubSelector.set(pubSelector) and i can't find in the code other place where template.tabular.pubSelector is setted.
var pubSelector = Util.getPubSelector(
template.tabular.selector,
(data.search && data.search.value) || null,
template.tabular.searchFields,
template.tabular.searchCaseInsensitive,
template.tabular.splitSearchByWhitespace,
data.columns || null
);
template.tabular.pubSelector.set(pubSelector);