RxJS Immutable Object - ChoDragon9/posts GitHub Wiki

RxJS์˜ ์˜คํผ๋ ˆ์ดํ„ฐ๋“ค์€ ์ƒˆ๋กœ์šด Observable๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ˜ธ์ถœํ•œ Observable๋ฅผ ๊ตฌ๋…ํ•œ๋‹ค. ์™ธ๋ถ€์—์„œ๋Š” ๋ณ€๊ฒฝ์ด ๋ถˆ๊ฐ€๋Š” ํ•œ ๊ฐ์ฒด Immutable Object๋ฅผ ๋งŒ๋“ค๊ธฐ ์œ„ํ•จ์ด๋‹ค.

filter

https://rxjs-dev.firebaseapp.com/api/operators/filter

function filter(predicate, thisArg) {
    return function filterOperatorFunction(source) {
        return source.lift(new FilterOperator(predicate, thisArg));
    };
}
var FilterOperator = (function () {
    function FilterOperator(predicate, thisArg) {
        this.predicate = predicate;
        this.thisArg = thisArg;
    }
    FilterOperator.prototype.call = function (subscriber, source) {
        return source.subscribe(new FilterSubscriber(subscriber, this.predicate, this.thisArg));
    };
    return FilterOperator;
}());
var FilterSubscriber = (function (_super) {
    __extends(FilterSubscriber, _super);
    function FilterSubscriber(destination, predicate, thisArg) {
        var _this = _super.call(this, destination) || this;
        _this.predicate = predicate;
        _this.thisArg = thisArg;
        _this.count = 0;
        return _this;
    }
    FilterSubscriber.prototype._next = function (value) {
        var result;
        try {
            result = this.predicate.call(this.thisArg, value, this.count++);
        }
        catch (err) {
            this.destination.error(err);
            return;
        }
        if (result) {
            this.destination.next(value);
        }
    };
    return FilterSubscriber;
}(Subscriber));

Observable.pipe

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-pipe

class Observable {
   ...
    pipe(...operations) {
        if (operations.length === 0) {
            return this;
        }
        return pipeFromArray(operations)(this);
    }
   ...
}

Observable.lift

์ƒˆ๋กœ์šด Observable๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#instance-method-lift

class Observable {
   ...
   lift(operator) {
        const observable = new Observable();
        observable.source = this;
        observable.operator = operator;
        return observable;
    }
   ...
}