SitePen / dstore

A data infrastructure framework, providing the tools for modelling and interacting with data collections and objects.
http://dstorejs.io/
Other
281 stars 83 forks source link

track() reports on data changed outside the collection #224

Closed wkeese closed 5 years ago

wkeese commented 5 years ago

This code creates a tracked collection of store items that match priority=high:

var declare = require("dojo/_base/declare");
var Memory = require("dstore/Memory");
var Trackable = require("dstore/Trackable");
var TrackableMemory = declare([Memory, Trackable]);
var store = new TrackableMemory();
var collection = store.filter({priority:'high'});
var trackedCollection = collection.track();

trackedCollection.on('add, update, delete', function(event){
    console.log(event.type, event.target, event.previousIndex, event.index);
});

If elements with priority=high are added/updated/deleted to the store, like below, I get notifications from the trackedCollection listener as expected:

store.putSync({ id: 3, priority: "high" });

However, I'm also getting notifications for when elements that don't match the filter are added/updated/deleted to the store:

store.putSync({ id: 4, priority: "low" });

Is this expected? Seems like a bug.

edhager commented 5 years ago

A change was landed recently in commit 7c8a77fa6a9edc13852dc85458fb5320ec0beab0 that addresses this issue. Right now it lives in the master branch and will be included in the next release.

There are some caveats regarding listening for "update" events as described in PR #222 and in the Collection documentation:

Because the "update" events are not notified when an item is removed from the collection when filtering is enabled, the new filtered behavior is not on by default. We didn't want to break any existing implementations. Pass true to the new filterEvents parameter added to Collection#on.

wkeese commented 5 years ago

Ah cool, thanks for the quick response, and funny timing that this just got fixed. So I guess this is a dup of #188.