Skip to content
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

feat(Observable): initially create Observable.generate factory #1537

Closed

Conversation

Igorbek
Copy link
Contributor

@Igorbek Igorbek commented Mar 26, 2016

Description:

The PR adds static Observable.generate/GenerateObservable.create method with implementation aligned with RxJS4.

The signature supports passing parameters and a single options:

  static create<T, S>(
    initialState: S,
    condition: ConditionFunc<S>,
    iterate: IterateFunc<S>,
    resultSelector: ResultFunc<S, T>,
    scheduler?: Scheduler): Observable<T>
  static create<S>(
    initialState: S,
    condition: ConditionFunc<S>,
    iterate: IterateFunc<S>,
    scheduler?: Scheduler): Observable<S>
  static create<T, S>(
    options: GenerateOptions<T, S>): Observable<T>

Related issue:
#1482

This is my first PR here, hi everybody :)

@@ -20,6 +20,7 @@ import './add/observable/fromArray';
import './add/observable/fromEvent';
import './add/observable/fromEventPattern';
import './add/observable/fromPromise';
import './add/observable/generate';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is going under Rx, it may need to be also under kitchenSink as well. (kitchSink contains all of Rx export)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know what should be included into kitchenSink. I'll include.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kwonoj kitchen sink imports all of Rx by default, so if it is part of rx, kitchen sink will see it too.

https://github.com/ReactiveX/rxjs/blob/master/src/Rx.KitchenSink.ts#L2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I missed that. Sorry for bringing confusion.

@benlesh
Copy link
Member

benlesh commented Mar 28, 2016

@Igorbek this PR needs to be flattened and rebased.

@Igorbek
Copy link
Contributor Author

Igorbek commented Mar 29, 2016

Sure.

@Igorbek Igorbek force-pushed the feature/observable-generate branch from cfeafea to 32b7cf8 Compare March 29, 2016 17:48
const expected = '(12345|)';

expectObservable(source).toBe(expected);
});*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to enable this test need to fix #1543 first

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked in #1544 prior to this and believe this is now unblocked - would you mind to update this one?

@Igorbek
Copy link
Contributor Author

Igorbek commented Mar 29, 2016

@Blesh, it's been flattened and rebased.

@benlesh
Copy link
Member

benlesh commented Mar 29, 2016

@Igorbek we might need to hold this PR until @kwonoj's #1545 lands, or otherwise coordinate with @kwonoj. I don't think there will be huge changes to the testing code, but there would be some changes for sure.

@kwonoj, what do you think?

@kwonoj
Copy link
Member

kwonoj commented Mar 29, 2016

I'm about to check in #1545 now (locally running tests for verification once again) so it'll be soon - would like to ask same way to hold this bit. Apologize to @Igorbek might need one additional rebase.

@Igorbek
Copy link
Contributor Author

Igorbek commented Mar 29, 2016

Sure, no problem.

@Igorbek Igorbek force-pushed the feature/observable-generate branch 2 times, most recently from cce6b1f to 894c721 Compare April 1, 2016 15:47
@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 1, 2016

Ok, now it's been fixed, flattened and rebased again.

@staltz
Copy link
Member

staltz commented Apr 1, 2016

Sorry for reviewing this late in the process, and thank you for the effort so far.

I'd like to remind about the criteria for merging an operator (this was shown as a PR comment template when a PR is opened), so there are still a few things missing until this operator is "complete", namely:

  • If possible, write a asDiagram test case too, for PNG diagram generation purposes
  • The operator must be documented in JSDoc style in the implementation file, including also the PNG marble diagram image
  • The operator should be listed in doc/operators.md in a category of operators
  • It should also be inserted in the operator decision tree file doc/decision-tree-widget/tree.yml

If you need a reference in how to do those, I recommend looking at

@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 2, 2016

Ok, I've just returned from Build and so now will probably have more time this week to complete this journey.

@@ -120,6 +120,7 @@ There are operators for different purposes, and they may be categorized as: crea
- [`fromEvent`](../class/es6/Observable.js~Observable.html#static-method-fromEvent)
- [`fromEventPattern`](../class/es6/Observable.js~Observable.html#static-method-fromEventPattern)
- [`fromPromise`](../class/es6/Observable.js~Observable.html#static-method-fromPromise)
- `generate`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staltz should I make it a link by following the pattern around?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a link is nice 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 7, 2016

Ok, looks like I'm done. That's what was changed:

  • added an overload that accepts an 'options' object without resultSelector but still properly typed with state as a result type
  • all calls to user functions (iterate, condition and resultSelector) are now in try-catch errors are emitted to subscriber's error channel
  • reduced unnecessary calls to condition function
  • added more tests to cover scenarios with/without scheduler specified
  • added JSDoc to all exported functions and option fields
  • the operator added to the list in doc and to decision tree

@staltz please review and see my question about doc link

const source = Observable.generate(1, x => x == 1, x => x + 1);
const expected = '(1|)';

expectObservable(source).toBe(expected, { '1': 1 });
});
it('should produce all values synchronously', () => {

asDiagram('generate(1, x => x < 3, x => x + 1)')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we have only one of these asDiagram tests, per file. This third one is the most interesting for a diagram. Can you make the 1st and 2nd test revert back to normal it() test?

@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 11, 2016

@staltz Please go ahead with your separate PR for the docs. I've slightly changed the docs, so I hope it'll help you. The informal part and long technical description are still missing. I appreciate your assistance.

@staltz
Copy link
Member

staltz commented Apr 12, 2016

Nice, thanks

@benlesh
Copy link
Member

benlesh commented Apr 12, 2016

@staltz ... this looks okay from my review, but I'm leaving it up to you since it seems like you're waiting for something docs related.

@benlesh
Copy link
Member

benlesh commented Apr 12, 2016

Okay.. this LGTM. Last thing would be to flatten this into one commit. @Igorbek can you flatten this? The commit message should be something like feat(Observable.generate): add generate static creation method with some description of the work done. This is so it shows up cleanly in the CHANGELOG.md at publish time.

I'm publishing in a few minutes, so this will probably land in next week's release.

- add overloads that accepts distinct options and a single options object
- add tests with marble diagrams
- add JSDoc
@Igorbek Igorbek force-pushed the feature/observable-generate branch from 2fe2115 to e4c9f56 Compare April 12, 2016 23:01
@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 12, 2016

Done.

@staltz
Copy link
Member

staltz commented Apr 13, 2016

LGTM, thanks Igor

@benlesh
Copy link
Member

benlesh commented Apr 14, 2016

Merged with c03434c... thanks @Igorbek

@benlesh benlesh closed this Apr 14, 2016
@Igorbek
Copy link
Contributor Author

Igorbek commented Apr 14, 2016

@Blesh just curious, why don't you use normal merge and use this strange cherry picking?

@staltz
Copy link
Member

staltz commented Apr 18, 2016

@lock
Copy link

lock bot commented Jun 7, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants