Skip to content

Commit

Permalink
add fromPromise eventTransformer to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
raimohanska committed Jun 5, 2015
1 parent 17cf2f9 commit 359f21f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ $("#my-div").asEventStream("click", function(event, args) { return args[0] })
```

<a name="bacon-frompromise"></a>
[`Bacon.fromPromise(promise [, abort])`](#bacon-frompromise "Bacon.fromPromise(promise : Promise[A] [, abort : boolean]) : EventStream[A]") creates an EventStream from a Promise object such as JQuery Ajax.
This stream will contain a single value or an error, followed immediately by stream end. You can use the optional abort flag (i.e. ´fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream.
[`Bacon.fromPromise(promise [, abort] [, eventTransformer])`](#bacon-frompromise "Bacon.fromPromise(promise : Promise[A] [, abort : boolean][, eventTransformer]) : EventStream[A]") creates an EventStream from a Promise object such as JQuery Ajax.
This stream will contain a single value or an error, followed immediately by stream end.
You can use the optional abort flag (i.e. ´fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream.
You can also pass an optional function that transforms the promise value into Events. The default is to transform the value into `[new Bacon.Next(value), new Bacon.End()]`.
Check out this [example](https://github.com/raimohanska/baconjs-examples/blob/master/resources/public/index.html).

<a name="bacon-fromevent"></a>
Expand Down
6 changes: 4 additions & 2 deletions readme-src.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,11 @@ $("#my-div").asEventStream("click", function(event, args) { return args[0] })
```
"""

doc.fn "Bacon.fromPromise(promise : Promise[A] [, abort : boolean]) : EventStream[A]", """
doc.fn "Bacon.fromPromise(promise : Promise[A] [, abort : boolean][, eventTransformer]) : EventStream[A]", """
creates an EventStream from a Promise object such as JQuery Ajax.
This stream will contain a single value or an error, followed immediately by stream end. You can use the optional abort flag (i.e. ´fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream.
This stream will contain a single value or an error, followed immediately by stream end.
You can use the optional abort flag (i.e. ´fromPromise(p, true)´ to have the `abort` method of the given promise be called when all subscribers have been removed from the created stream.
You can also pass an optional function that transforms the promise value into Events. The default is to transform the value into `[new Bacon.Next(value), new Bacon.End()]`.
Check out this [example](https://github.com/raimohanska/baconjs-examples/blob/master/resources/public/index.html).
"""

Expand Down
4 changes: 2 additions & 2 deletions spec/specs/frompromise.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe "Bacon.fromPromise", ->
dispose()
success("a")
expect(events).to.deep.equal([])

it "should support custom event transformer", ->
transformer = (value) -> [value.toUpperCase(), new Bacon.End]
events = []
Expand All @@ -57,7 +57,7 @@ describe "Bacon.fromPromise", ->
dispose()
delete promise.abort
expect(isAborted).to.deep.equal(true)

it "should not abort ajax promise on unsub, if abort flag is not set", ->
isAborted = false
promise.abort = ->
Expand Down

0 comments on commit 359f21f

Please sign in to comment.