Basic demo of groupBy
for RxJS Live.
Each branch demonstrates a different operator: mergeMap
, switchMap
, concatMap
, exhaustMap
, groupBy
, and a custom operator implementation of groupBy
.
Basic demo of groupBy for RxLive
Basic demo of groupBy
for RxJS Live.
Each branch demonstrates a different operator: mergeMap
, switchMap
, concatMap
, exhaustMap
, groupBy
, and a custom operator implementation of groupBy
.
test
Cool demo, food for thought... But I'm not sure if I'm understanding the setup you've used.
toggleStatus
function update its local state BEFORE the delay? That's fine for the setButtonEmoji
, but why have a database-tracking variable that doesn't follow the db.If it wouldn't change your demo to alter this, I think it'd be more believable to do this..
Thanks for the discussion..
Since the custom operator knows everything it need to know when groups can safely be removed, there should be no need for a fixed 15 second timeout.
Instead it could detect if the inner observable inside the switchMap
has completed. If so, it can terminate the group.
I gave it a stab in my own branch here.
export function switchMapByKey<T, K, O extends ObservableInput<any>>(
keySelector: (value: T) => K,
project: (value: T, index: number) => O
): OperatorFunction<T, ObservedValueOf<O>> {
return (source) => {
let vault: any = {};
return source.pipe(
groupBy(
(v) => {
const key = keySelector(v);
if (!vault[key]) vault[key] = new Subject<void>();
return key;
},
item => item,
group => vault[group.key]
),
mergeMap((group) =>
group.pipe(
switchMap((e, i) =>
from(project(e, i)).pipe(
tap({ complete: () => { vault[group.key].complete(); }})
)
),
finalize(() => { delete vault[group.key]; })
)
) as OperatorFunction<GroupedObservable<K, T>, ObservedValueOf<O>>
)
}
}
Edit: This was working in my browser, but TS keeps complaining about types, so it's not perfect yet.
Edit2: I gave TS some hints and now it's happy.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.