MithrilJS / MithrilJS/mithril.js
Stream Extras
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 14.5k
- Forks
- 922
- PR merge metrics
- No merged PRs in 30d
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the proposed helpers in the linked mithril-stream-extra repository and the TypeScript ReadonlyStream concerns described here. The issue does not define a selected scope or acceptance criteria; progress would require deciding which stream additions, typings, or promise helpers belong in core.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100