Skip to content

Latest commit

 

History

History
72 lines (52 loc) · 1.39 KB

File metadata and controls

72 lines (52 loc) · 1.39 KB

Hides the identity of an observer.

Returns

(Observer): An observer that hides the identity of the specified observer.

{% if book.isPdf %}

function SampleObserver () {
    Rx.Observer.call(this);
    this.isStopped = false;
}

SampleObserver.prototype = Object.create(Rx.Observer.prototype);
SampleObserver.prototype.constructor = SampleObserver;

Object.defineProperties(SampleObserver.prototype, {
    onNext: {
        value: x => {
            if (!this.isStopped) {
                console.log(`Next: ${x}`);
            }
        }
    },
    onError: {
        value: err => {
            if (!this.isStopped) {
                this.isStopped = true;
                console.log(`Error: ${err}`);
            }
        }
    },
    onCompleted: {
        value: () => {
            if (!this.isStopped) {
                this.isStopped = true;
                console.log('Completed');
            }
        }
    } 
});

var sampleObserver = new SampleObserver();

var source = sampleObserver.asObserver();

console.log(source === sampleObserver);
// => false

{% else %}

Example

{% endif %}

{% if book.isPdf %}

{% else %}

Location

  • rx.js

{% endif %}