Skip to content

Commit

Permalink
fix(imitate): use null for unset this._target
Browse files Browse the repository at this point in the history
The unset this._target used to be the constant object NO but it seems
more reliable to use null here. In some rare cases (maybe with garbage
collection?) the NO object in this._target may differ from the global
NO object. The NO object is useful for streams that emit null or
undefined, but not useful for this._target so it seems better to just
use null here.
  • Loading branch information
staltz committed May 28, 2020
1 parent 46fbd3e commit baf37aa
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ export class Stream<T> implements InternalListener<T> {
protected _stopID: any;
protected _dl: InternalListener<T>; // the debug listener
protected _d: boolean; // flag indicating the existence of the debug listener
protected _target: Stream<T>; // imitation target if this Stream will imitate
protected _target: Stream<T> | null; // imitation target if this Stream will imitate
protected _err: any;

constructor(producer?: InternalProducer<T>) {
Expand All @@ -1079,7 +1079,7 @@ export class Stream<T> implements InternalListener<T> {
this._stopID = NO;
this._dl = NO as InternalListener<T>;
this._d = false;
this._target = NO as Stream<T>;
this._target = null;
this._err = NO;
}

Expand Down Expand Up @@ -1135,7 +1135,7 @@ export class Stream<T> implements InternalListener<T> {

_add(il: InternalListener<T>): void {
const ta = this._target;
if (ta !== NO) return ta._add(il);
if (ta) return ta._add(il);
const a = this._ils;
a.push(il);
if (a.length > 1) return;
Expand All @@ -1150,7 +1150,7 @@ export class Stream<T> implements InternalListener<T> {

_remove(il: InternalListener<T>): void {
const ta = this._target;
if (ta !== NO) return ta._remove(il);
if (ta) return ta._remove(il);
const a = this._ils;
const i = a.indexOf(il);
if (i > -1) {
Expand Down Expand Up @@ -1987,7 +1987,7 @@ export class MemoryStream<T> extends Stream<T> {

_add(il: InternalListener<T>): void {
const ta = this._target;
if (ta !== NO) return ta._add(il);
if (ta) return ta._add(il);
const a = this._ils;
a.push(il);
if (a.length > 1) {
Expand Down

0 comments on commit baf37aa

Please sign in to comment.