-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[WIP] Add recipe for hot observables #956
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# How to test hot observables | ||
|
||
Ava supports autosubscribing to cold observables, which will not work for hot observables. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ava => AVA |
||
For hot observables, we will need to first subscribe, and then trigger the values to be sent in the stream. | ||
We can automatically unsubscribe by using `#take()`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify here what |
||
|
||
## Installing rxjs v5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
`npm install --save rxjs` | ||
|
||
## Create a source file named interactions.js | ||
|
||
``` | ||
function create({Rx}) { | ||
const writeSubject = new Rx.Subject() | ||
|
||
function write(data) { | ||
writeSubject.next(data) | ||
} | ||
|
||
return { | ||
actions: {write}, | ||
events: {write: writeSubject.toObservable()} | ||
} | ||
} | ||
|
||
export default { | ||
create | ||
} | ||
``` | ||
|
||
## Now test it | ||
|
||
``` | ||
import tests from 'Ava' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ava => ava There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tests => test |
||
import Rx from 'rxjs' | ||
import interactionsFactory from './interactions' | ||
|
||
tests( | ||
`Given that we subscribe to the write event, | ||
when the user calls the action write with 'hello' | ||
then our subscriber recieves the message 'hello'`, | ||
function onTest(test) { | ||
const expected = 'hello' | ||
const interactions = interactionsFactory.create({Rx}) | ||
interactions.events.write.take(1).subscribe(function(actual) { | ||
test.is(actual, expected) | ||
test.done() | ||
}) | ||
interactions.actions.write(expected) | ||
} | ||
) | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use semi-colons, tab indentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name it: