let drawer = {};
let stacks = {};
async function actionDealCard(hidden) {
let previousMutation = drawer.mutation;
drawer.mutation = true;
await new Promise(resolve => {
setTimeout(resolve, previousMutation?500:100);
console.log('animation happening');
});
stacks.mutation = hidden;
}
async function mainFunction() {
let deals = [1,2,3];
for (let key in deals) {
await actionDealCard(key);
}
console.log(stacks, drawer);
}
mainFunction();
Above is the simplified version of my code. I implemented this using imperative coding style. Now I want to turn this into reactive streams. How do I do that?
I've tried something like this:
// I need an event stream that describes when to mutate drawer
// to pass to DrawerProperty function
// This might be a bus to simplify the solution but buses are bad.
let esDrawerMutate = ???
let drawer = DrawerProperty(esDrawerMutate);
async function actionDealCard(key) {
// I have no clue what's going on here
}
let deals = Bacon.fromArray([1,2,3]);
let esMain = deals.flatMap(key => {
return Bacon.fromPromise(actionDealCard(key));
});
esMain.log();
function DrawerProperty(esMutate) {
return Bacon.update({},
[esMutate, _ => _.mutation = true]);
}
function StacksProperty(esMutate) {
return Bacon.update({},
[esMutate, _ => _.mutation = true]);
}
When my above code run this is the output:
animation happening
animation happening
animation happening
{
"mutation": "2"
} {
"mutation": true
}
I guess my goal here is to produce this same output in functional style.