Meteor-Community-Packages / Meteor-Community-Packages/meteor-tabular

Strange behaviour caused by adding Util.objectsAreEqual

Open
#210 2 comments 0 reactions 0 assignees View on GitHub
needs reproduction potential bug
Dominant language
JavaScript
Stars
360
Forks
132
PR merge metrics
No merged PRs in 30d

Description

I have a table whose selector is retrieved from template helper:

```
{{> tabular table=TabularTables.MyTable selector=selector id="myTable"}}
```

``` javascript
Template.myTemplate.onCreated(function(){
this.taskSelector = new TaskSelector();
});
```

``` javascript
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](https://github.com/aldeed/meteor-tabular/commit/2867ed41b04833a77c8016896d14fc7c028e602f#diff-ece7b3a707d8f580fb6b6fee6d3ef889R18). 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.

Contributor guide

Open the contributing guide

Research direction

Reproduce the example using a template helper, TaskSelector, ReactiveVar, and a tabular selector on the 1.2.0 and 1.3.0+ versions. Start at the added Util.objectsAreEqual call linked in the issue and trace how oldVal and newVal are compared when the selector changes. Done means selector updates reliably refresh the table without removing the equality check.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.