RxJS Immutable Object - ChoDragon9/posts GitHub Wiki
RxJS์ ์คํผ๋ ์ดํฐ๋ค์ ์๋ก์ด Observable
๋ฅผ ์์ฑํ๊ณ ํธ์ถํ Observable
๋ฅผ ๊ตฌ๋
ํ๋ค. ์ธ๋ถ์์๋ ๋ณ๊ฒฝ์ด ๋ถ๊ฐ๋ ํ ๊ฐ์ฒด Immutable Object
๋ฅผ ๋ง๋ค๊ธฐ ์ํจ์ด๋ค.
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;
}
...
}