Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Better switchMap #1

@devanshj

Description

@devanshj

Right now switchMap is really hacky it "contextualizes" (kinda like a mutation) the behavior passed to it...

let x$ = Rex.interval(1000)
let [click$, sendClick] = Rex.createEvent()

p(click$, Rex.switchMap(() => x$), Rex.subscribe(console.log))

p(x$, Rex.subscribe(console.log))
// this won't log every second because it has been contextualized
// by the above switchMap

We can make the a "cloner" that would clone the behavior so that the original remains as it is...

let x$ = Rex.interval(1000)
let [click$, sendClick] = Rex.createEvent()

p(click$, Rex.switchMap(() => Rex.$(x$)), Rex.subscribe(console.log))

p(x$, Rex.subscribe(console.log))
// now this logs every second

I think this is kinda doable, although I haven't tried at all.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions