-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(Observable.from): use scheduler if supplied #1788
Conversation
|
Yeesh. Good catch, @chrisprice . Do you think you can add a test that verifies the change? (i.e. one that was broken before the change, but works now?) |
|
This is the rabbit hole I was talking about 😬 The following test will pass - it('should handle any iterable thing with a scheduler', (done: MochaDone) => {
const iterable = <any>{};
const iteratorResults = [
{ value: 'one', done: false },
{ value: 'two', done: false },
{ done: true }
];
const expected = ['one', 'two'];
expect($$iterator).to.equal(Symbol.iterator);
iterable[Symbol.iterator] = () => {
return {
next: () => {
return iteratorResults.shift();
}
};
};
Observable.from(iterable, x => x, null, Rx.Scheduler.async).subscribe((x: string) => {
expect(x).to.equal(expected.shift());
}, (x) => {
done(new Error('should not be called'));
}, () => {
expect(expected.length).to.equal(0)
done();
});
expect(expected.length).to.equal(2);
});But will fail if the following line is substituted - Observable.from(iterable, Rx.Scheduler.async).subscribe((x: string) => {The conditionals around the arguments seems very inconsistent across both the I don't mind chasing a few of these down but are you able to give some some guidance around the API you're aiming for? |
|
If something takes a scheduler, it should be an optional last argument. If the arguments before the scheduler are optional, then I'd expect any order would work:
Should all work. |
|
I've modified the
Before I spend any time fixing all the ❌s, is it worth reconsidering whether the projection and context arguments are useful? I would expect arrow-functions and Updated, I'd made a mistake transcribing the table |
ee994b0
to
a2c87a6
Compare
|
Apologies for the multiple edits on the table, these are the results which I believe are now accurately transcribed above (with $ npm run build_test | grep Observable.from
1) Observable.from should accept observable and projection:
2) Observable.from should accept observable, projection and scheduler:
3) Observable.from should accept observable, projection and context:
4) Observable.from should accept observable, projection, context and scheduler:
5) Observable.from should accept array and projection:
6) Observable.from should accept array, projection and scheduler:
7) Observable.from should accept array, projection and context:
8) Observable.from should accept array, projection, context and scheduler:
9) Observable.from should accept promise and projection:
10) Observable.from should accept promise, projection and scheduler:
11) Observable.from should accept promise, projection and context:
12) Observable.from should accept promise, projection, context and scheduler:
13) Observable.from should accept iterator and scheduler:
14) Observable.from should accept iterator and projection:
15) Observable.from should accept iterator, projection and scheduler:
16) Observable.from should accept iterator, projection and context:
17) Observable.from should accept iterator, projection, context and scheduler:
18) Observable.from should accept array-like, projection and scheduler:
19) Observable.from should accept string and scheduler:
20) Observable.from should accept string, projection and scheduler:
21) Observable.from should accept arguments and scheduler:
22) Observable.from should accept arguments, projection and scheduler: |
|
@chrisprice I think you raise a valid question. I know that the idea of a projection function as an argument to |
9d1d4e3
to
f77e9ca
Compare
| @@ -210,18 +24,6 @@ describe('Observable.from', () => { | |||
| expect(r).to.throw(); | |||
| }); | |||
|
|
|||
| it('should handle object has observable symbol', (done: MochaDone) => { | |||
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.
Where did this test go? (Also, I think this test was invalid)
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.
Folded into the matrix test below. I can restore it but I think it would just be a dupe.
f77e9ca
to
553c5bb
Compare
|
I think I've addressed all the comments with the latest update -
|
|
@Blesh how's this look besides needing rebase? |
|
LGTM |
|
@chrisprice just needs a rebase then it's merge time 🎉 |
BREAKING CHANGE - Observable.from no longer supports the optional map function and associated context argument. This change has been reflected in the related constructors and their properties have been standardised.
553c5bb
to
3f052a6
Compare
|
Rebased on to 3c35b94 👍 |
|
Thanks !! |
|
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description:
Arguments supplied to
Observable.fromare not being propagated correctly. I've chased this a couple of levels down the rabbit hole and whilst this patch fixes some issues, I'm starting to think that Iterators and Schedulers just don't work together. I supply this patch only because the code is so obviously wrong.N.B. I tried adding tests but I don't understand enough about your testing primitives and their behavior to get the results I would expect. However, I believe the code is currently so obviously wrong that the tests are unnecessary to prove correctness, only to prevent regression.