horizon icon indicating copy to clipboard operation
horizon copied to clipboard

Resubscribing to a watch() Observable causes duplicated data

Open tomdegoede opened this issue 8 years ago • 2 comments

Server version: 1.1.3 Client version: 1.1.3

Unsubscribing and then resubscribing the same watch() Observable will cause records to be added to the collection even when they are already present.

var t = horizon('tasks');
t.store({title: 'test'}).subscribe(function (stored) {
    var id = stored.id;

    var watch = t.findAll(id).watch();

    var sub = watch.subscribe(function (r) {
        console.log(r);
    });

    setTimeout(function () {
        sub.unsubscribe();

        sub = watch.subscribe(function (r) {
            console.log(r);
        });
    }, 1000);
});

tomdegoede avatar Aug 10 '16 22:08 tomdegoede

Hi @tomdegoede could you try out the 2.0.0 beta? We changed how the watches work, they should be reference counting their subscribers now

deontologician avatar Aug 15 '16 21:08 deontologician

I'm adding this to the next release. We at the very least should have a test for this behavior

deontologician avatar Aug 19 '16 03:08 deontologician