-
-
Notifications
You must be signed in to change notification settings - Fork 928
Description
Description
This issue is to discuss potential additions and enhancements for mithril/stream.
This is a collection of helpers I've found useful working with Streams: https://github.com/spacejack/mithril-stream-extra
It's a bit TypeScript-heavy because I wanted to add a ReadonlyStream type, but otherwise I think it's also got useful helpers for plain JS.
(Revisiting it however, I found the ReadonlyStream type is now broken with the current Typescript compiler... I'm having trouble coming up with a Stream-compatible read-only type so that ReadonlyStream types are usable with all Stream functions. This might need to be done as a complete custom stream .d.ts or brought into core to work.)
In addition to the above, these functions are for getting promises from streams:
/**
* Promise that resolves on stream's initial value
* Credit to @isiahmeadows for eliminating the extra map
*/
export function one<T>(s: ReadonlyStream<T>): Promise<T> {
return new Promise<T>(resolve => {
let done = false
let s1: Stream<T>
s1 = s.map(v => {
if (done) {
return
}
done = true
if (s1 != null) {
s1.end(true)
}
resolve(v)
})
if (done) {
s1.end(true)
}
})
}
/**
* Promise that resolves on stream's next value
*/
export function nextOne<T>(s: ReadonlyStream<T>): Promise<T> {
return one(dropInitial(s))
}
Why
Having used streams in various ways, this is a set of helpers I've found most useful. I'd also like to hear from others about what additional stream functions or patterns they're using. And any suggestions/critiques or antipattern warnings about the above are welcome as well.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status