Reactive-Extensions / RxJS

The Reactive Extensions for JavaScript
http://reactivex.io
Other
19.49k stars 2.1k forks source link

takeUntil toArray doubles results after several invokations? #995

Open macmillan78 opened 8 years ago

macmillan78 commented 8 years ago

I implemented a flux like thing. I invoke an action, which causes one or more stores to update and so on. I implemented a debug helper which tries to collect the action and the updated stores and saves them with the state changes to a log.

    var storeSource = Store.source.takeUntil(Action.source).toArray();

    Action.source.subscribe((action) => {
        this._counter++;
        storeSource.subscribe((stores) => {
            console.log(stores);

            // save to store
        });
    });

After the second action invokation, 'stores' has every store twice, while other subscribers on the original observable Store.source only get invoked once ...

martinhrvn commented 6 years ago

I can confirm this.. here is a simpler example:

const count = Rx.Observable.interval(100).take(10);
const countArray = count.toArray()
countArray.subscribe(i => console.log(i))
countArray.subscribe(i => console.log(i))
countArray.subscribe(i => console.log(i))
countArray.subscribe(i => console.log(i))

The output of this is a bit strange:

[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9]
[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9]
[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9]
[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9]