私はAngularの相対初心者です。ng-bootstrapプロジェクトから読んでいるソースを理解するのには苦労しています。 The source code can be found here。Observable関数で.call()をなぜ呼び出すのですか?
私はngOnInitのコードで非常に混乱しています:
ngOnInit(): void {
const inputValues$ = _do.call(this._valueChanges, value => {
this._userInput = value;
if (this.editable) {
this._onChange(value);
}
});
const results$ = letProto.call(inputValues$, this.ngbTypeahead);
const processedResults$ = _do.call(results$,() => {
if (!this.editable) {
this._onChange(undefined);
}
});
const userInput$ = switchMap.call(this._resubscribeTypeahead,() => processedResults$);
this._subscription = this._subscribeToUserInput(userInput$);
}
これらの観察可能な機能に.call(...)
を呼び出すのポイントは何ですか?これが達成しようとしているのはどのような振る舞いですか?これは正常なパターンですか?
Angular教育の一環としてObservables(意図しない言い回し)について多くの読書/視聴を行ってきましたが、このようなことは一度もありませんでした。任意の説明は、私が
const inputValues$ = _do.call(this._valueChanges, value => {
this._userInput = value;
if (this.editable) {
this._onChange(value);
}
});
が私の意見では、それはいつものパターン(私はそれが同じパターンだと思いますが、別の形で書かれている)ではありません
const inputValues$=this._valueChanges.do(value=>{
this._userInput = value;
if (this.editable) {
this._onChange(value);
}
})
と同等であると仮定し
、 'do'は通常観察可能で呼び出されていることですそれだけではありません。この答えは私にとって事をより明確にしてくれませんでした – CodyBugstein
Observableで「Do」が呼び出されました:Observableはイベントのストリームです。私たちがそれに「do」を呼ぶと、それはそのイベントを購読して、イベント発生時まで –
私はあなたのための例を持っています:https://plnkr.co/edit/dJNRNI?p=preview。それを実行すると、コンソールでより明確に見ることができます –