-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do we add switchMap
?
#90
Comments
Previously: #52 Your first example kind of scares me as written - the right thing is to cancel the One wild idea for that: the mapper (in this and potentially other callback-taking methods) could take as its third argument a input.on('input')
.switchMap(async (e, idx, { signal }) => {
const response = await fetch(`/search?q={e.target.value}`, { signal });
/* ... */
})
.subscribe((results) => { /* ... */ }) and have the |
Oops. 😬 |
I'll move this over to the other pre-existing thread. |
switchMap
was mentioned at TPAC as being an API of interest. It's a method that is especially useful for composing events in the browser because of its inherent cancellation. If API bloat is a concern, I would gladly removetoArray()
,some()
,find()
et al, as those are minimally useful with observables.Use cases are things like:
Use Case: Lookahead Search
In the below scenario, the result of the
fetch
would simply be ignored.It's plausible that we could provide a signal along with the
switchMap
callback, as well. In fact, I'd almost encourage that, as it might make fetch
more useful. But I think we'd want to discuss the ergonomics there, and that could
be debated and added later. (For example, we might want to have it automatically
swallow DOMExceptions named
AbortError
?)Use Case: Changing Connections
Below, every time a URL is changed in an URL input, if it's a valid URL,
it will disconnect from the previous web socket and connect to a new one.
The text was updated successfully, but these errors were encountered: