Gözden geçirilebilir bir "yürütücü" işlevinden (isteğe bağlı olarak) döndürülmüş olan "atma" veya "abonelikten çıkma" işlevinin amacının ne olduğu konusunda kafam karıştı, gibi pek:"Aboneliği iptal et" fonksiyonu geri arama/kanca Gözlemlenebilir "yürütücü" işlevi
const Rx = require('rxjs');
const obs = Rx.Observable.create(obs => {
// we are in the Observable "executor" function
obs.next(4);
// we return this function, which gets called if we unsubscribe
return function() {
console.log('disposed');
}
});
const s1 = obs.subscribe(
function (v) {
console.log(v);
},
function (e) {
console.log(e);
},
function() {
console.log('complete');
}
);
const s2 = obs.subscribe(
function (v) {
console.log(v);
},
function (e) {
console.log(e);
},
function() {
console.log('complete');
}
);
s1.unsubscribe();
s2.unsubscribe();
beni kafasını karıştıran böyle bir işlev aslında kodunuzdaki referanslara tutunmaya ve bu nedenle çöp toplama önlemek için daha muhtemel olacağıdır.
Bu senaryoda bir işlevi döndürmenin amacının ne olduğunu, işlevin çağrıldığını ve imzanın ne olduğunu söyleyebilir misiniz? Bu konuda bilgi bulmakta zorlanıyorum.
let index = 0;
let obsEnqueue = this.obsEnqueue = new Rx.Subject();
this.queueStream = Rx.Observable.create(obs => {
const push = Rx.Subscriber.create(v => {
if ((index % obsEnqueue.observers.length) === obsEnqueue.observers.indexOf(push)) {
obs.next(v);
}
});
return obsEnqueue.subscribe(push);
});
Bu yerine sadece düz bir fonksiyonun bir abonelik dönmek görünüyor:
Ben de örneğin infaz işlevinden bu bir abonelik döndürmek çok daha karmaşık örneklere bakın. Bununla ne olduğunu açıklayan var mı?
net bir soru yapmak için
, bunu arasındaki fark nedir:const sub = new Rx.Subject();
const obs = Rx.Observable.create($obs => {
$obs.next(4);
return sub.subscribe($obs);
});
ve sonucu vermeyen çağrı abone: için
const sub = new Rx.Subject();
const obs = Rx.Observable.create($obs => {
$obs.next(4);
sub.subscribe($obs);
});
Aslında "executor" işlevi denir emin değilim, ama bu Promises dünya – Olegzandr