Skip to content

Commit

Permalink
fix: observables were not emitting properly when the number of subscr…
Browse files Browse the repository at this point in the history
…ibers changed mid-emit
  • Loading branch information
ersimont committed Jul 15, 2019
1 parent 7fd2733 commit 4ad91fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions projects/ng-app-state/src/lib/store-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,19 @@ describe("StoreObject", () => {
counterStore.$.subscribe(spy);
expectSingleCallAndReset(spy, 3);
});

it("works when the number of subscribers changes mid-emit (production bug)", () => {
const spy = jasmine.createSpy();

store("counter")
.$.pipe(take(2))
.subscribe();
store("counter").$.subscribe(spy);
expectSingleCallAndReset(spy, 0);

store("counter").set(1);
expectSingleCallAndReset(spy, 1);
});
});

describe(".batch()", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ObservableNode extends Observable<any> {
}

private emit() {
for (const subscriber of this.subscribers) {
for (const subscriber of this.subscribers.slice()) {
subscriber.next(this.value);
}
}
Expand Down

0 comments on commit 4ad91fa

Please sign in to comment.