-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Support Observable #165
Support Observable #165
Conversation
@@ -96,6 +97,25 @@ test('plan assertions with support for promises', function (t) { | |||
}); | |||
}); | |||
|
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.
Might we worth extracting all the Observable related test into a separate test file, since there are so many now.
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.
Ok, and the Promise related tests too? I'm thinking the end result would be:
- test.js
- test.Promise.js
- test.Observable.js
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.
Yeah, but that should be done in a separate PR.
- test.js
- promise.js
- observable.js
Generally looks good :) Will need docs and tests are currently failing. |
Happy to write some documentation. I'll keep looking at the failing tests, I'm not sure what the problem is yet... |
I think 'es6-symbol' is causing the tests to fail. What is the preferred solution for Symbols in 0.10 and 0.12? |
Hmm... also zen-observable requires a Promise polyfill... |
We will have to run zen-observables through the Babel |
@BarryThePenguin #200 - will fix the Node 0.10 error - it exists on master (I don't know how the latest master build passed) |
Great, I'll squash and rebase again once that gets in |
} | ||
|
||
var Observable = require('zen-observable'); | ||
|
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'm not sure if this is a Great Idea™
Any opinions?...
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.
Nah - just set it. That doesn't do anything to prevent pollution of globals.
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.
It's in test/test.js for Observables only as we want a lightweight implementation of the observable spec to test with. zen-observable
"Requires ES6 Promises or a Promise polyfill" and this looked like a simple way to do that without also having a Symbol polyfil at the same time.
Maybe @Blesh or @zenparsing have a suggestion?
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'm unsure of what the goal is here for "Supporting Observables". What do you need them to do? Do you need to support subscription to them? Do you need to support returning them?
If it's the former, you should be able to test for obj[Symbol.observable]
and call it (like a function) to get back an observable
object with a subscribe()
function on it that follows the zen-observable
spec. For that, there's really no need to import a library.
Okay, I think I'm caught up with what the desire is here. Observables can "end" in one of three ways:
You only really need to care about 1 and 2, because 3 would be caused by the test itself. To handle 1 and 2 for zen-observable, RxJS 5+, Kefir, Most and Bacon, you'd just need: let obj = getSomethingThatMightBeObservable();
if (obj[Symbol.observable]) {
obj[Symbol.observable]().subscribe({
complete() { /* done successfully */ },
error(err) { reportError(err); /* done because error */ }
});
} But the problem there is while you've determined that it's "done", you haven't analyzed the output. If the idea is to analyze the output, the best short-term solution is to subscribe to return myObservable.forEach(x => doSomeAssertion(x === 'whatever')); There would be no mileage from Kefir, Most or Bacon from that unless the spec changes to include that |
... actually in that case it wouldn't matter anyhow, because the libraries that aren't RxJS 5 or zen-observable would need to be subscribed to in a different way. I think that using |
👍 |
Off topic to this PR, but kinda weird that you have to call |
Good luck with that one. It's not a bad idea, but I think it will be hard to get traction on changes to Promise to support Observable. However, with RxJS, you can just use |
Also, I think it would be |
@BarryThePenguin Can you rebase from master and fix the merge conflict? This looks good to me. @vdemedes @jamestalmage Anything final you'd like to point out? |
Everything looks good to me, very straightforward, thanks @BarryThePenguin! |
👍 |
Feel free to cancel build 168 That was a mistake |
Done. |
Landed! Thank you @BarryThePenguin :) |
🎉 |
I've added some docs for it e57eff0, but I don't really know how Observables work, so any improvements welcome! For example, can you |
@sindresorhus You can't directly |
That's too bad... I was hoping In that case, |
Fixes #84
Still working through it. Happy to hear any feedback. I've just duplicated the tests for Promises. I started out writing tests using RxJs which all passed successfully. Switched to
zen-observable
half way through so some tests are currently skipped as a result.