[英]Bacon update properties depend on each other cyclic introducing bus
我有兩個可能相互依賴的屬性,所以我介紹了一個總線:
let esDealOne1 = Bacon.later(0, true);
let esDealOne2 = Bacon.later(1000, true);
let bHanging = new Bacon.Bus();
let esSetCards = bHanging.filter(_ => _.cards);
let pHanging = HangingStateProperty(esSetCards);
let pDrawer = DrawerProperty(bHanging, esDealOne1);
let pStacks = [
StackProperty(0, esDealOne2, pHanging),
];
function HangingStateProperty(esSetCards) {
let setCards = (_, cards) => {
return { ..._, ...cards };
};
return Bacon.update({},
[esSetCards, setCards]);
}
function DrawerProperty(bHanging, esDealOne1) {
let dealOne1 = (_) => {
let card = _.usefulProperty;
bHanging.push({ cards: [card] });
return _; };
return Bacon.update({},
[esDealOne1, dealOne1]);
}
function StackProperty(n, esAllDealOne2, pHanging) {
let esDealOne2 = esAllDealOne2.filter(_ => _.i === n);
let dealOne2 = (_, {i}, hangingState) => {
let cards = hangingState.cards;
_.property = cards;
return _;
};
return Bacon.update({},
[esDealOne2, pHanging, dealOne2]);
}
我怎樣才能擺脫這輛公共汽車?
很難移除總線,相反這會簡化總線的使用:
export function SyncBus() {
let bus = this.bus = new Bacon.Bus();
this.assign = pBase => {
pBase.onValue(_ => bus.push(_));
};
}
用法:
let bDrawer = new SyncBus();
// don't forget `toProperty` otherwise gets old values
let pDragCardsDrawEarly = bDrawer
.bus
.map(_ => _.extra)
.filter(_ => _.dragcards)
.map(_ => ({ dragcards: _.dragcards }))
.toProperty();
let pDrawer = OwnerProperty({});
bDrawer.assign(pDrawer);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.