Add Stream.lift (#1950)
* Add stream.lift and tests * Add docs * Add to change-log
This commit is contained in:
parent
a147023f4e
commit
76e585c523
4 changed files with 180 additions and 1 deletions
|
|
@ -7,6 +7,7 @@
|
|||
- [Stream.merge](#streammerge)
|
||||
- [Stream.scan](#streamscan)
|
||||
- [Stream.scanMerge](#streamscanmerge)
|
||||
- [Stream.lift](#streamlift)
|
||||
- [Stream.HALT](#streamhalt)
|
||||
- [Stream["fantasy-land/of"]](#streamfantasy-landof)
|
||||
- [Instance members](#instance-members)
|
||||
|
|
@ -151,6 +152,37 @@ Argument | Type | Required | De
|
|||
|
||||
---
|
||||
|
||||
##### Stream.lift
|
||||
|
||||
Creates a computed stream that reactively updates if any of its upstreams are updated. See [combining streams](#combining-streams). Unlike `combine`, the input streams are a variable number of arguments (instead of an array) and the callback receives the stream values instead of streams. There is no `changed` parameter. This is generally a more user-friendly function for applications than `combine`.
|
||||
|
||||
`stream = Stream.lift(lifter, stream1, stream2, ...)`
|
||||
|
||||
Argument | Type | Required | Description
|
||||
------------ | --------------------------- | -------- | ---
|
||||
`lifter` | `(any...) -> any` | Yes | See [lifter](#lifter) argument
|
||||
`streams...` | list of `Streams` | Yes | Streams to be lifted
|
||||
**returns** | `Stream` | | Returns a stream
|
||||
|
||||
[How to read signatures](signatures.md)
|
||||
|
||||
---
|
||||
|
||||
###### lifter
|
||||
|
||||
Specifies how the value of a computed stream is generated. See [combining streams](#combining-streams)
|
||||
|
||||
`any = lifter(streams...)`
|
||||
|
||||
Argument | Type | Required | Description
|
||||
------------ | -------------------- | -------- | ---
|
||||
`streams...` | splat of `Streams` | No | Splat of zero or more streams that correspond to the streams passed to [`stream.lift`](#stream-lift)
|
||||
**returns** | `any` | | Returns a computed value
|
||||
|
||||
[How to read signatures](signatures.md)
|
||||
|
||||
---
|
||||
|
||||
##### Stream.HALT
|
||||
|
||||
A special value that can be returned to stream callbacks to halt execution of downstreams
|
||||
|
|
@ -372,6 +404,18 @@ var greeting = stream.merge([a, b]).map(function(values) {
|
|||
console.log(greeting()) // logs "hello world"
|
||||
```
|
||||
|
||||
Or you can use the helper function `stream.lift()`
|
||||
|
||||
```javascript
|
||||
var a = stream("hello")
|
||||
var b = stream("world")
|
||||
|
||||
var greeting = stream.lift(function(_a, _b) {
|
||||
return _a + " " + _b
|
||||
}, a, b)
|
||||
|
||||
console.log(greeting()) // logs "hello world"
|
||||
```
|
||||
|
||||
There's also a lower level method called `stream.combine()` that exposes the stream themselves in the reactive computations for more advanced use cases
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue