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

docs(from): Convert docs for from #4031

Merged
merged 2 commits into from
Aug 21, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/internal/observable/from.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,74 @@ export function from<T>(input: ObservableInput<T>, scheduler?: SchedulerLike): O

throw new TypeError((input !== null && typeof input || input) + ' is not observable');
}

/**
Copy link
Member

Choose a reason for hiding this comment

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

Hi Rob, basically this is an awesome pr. Thanks for all the work you put into it. But this part has to be above the function declaration to be valid JSDoc. Maybe take a look at another operator like fromEvent then you will see what I mean.

* Creates an Observable from an Array, an array-like object, a Promise, an iterable object, or an Observable-like object.
*
* <span class="informal">Converts almost anything to an Observable.</span>
*
* ![](from.png)
*
* `from` converts various other objects and data types into Observables. It also converts a Promise, an array-like, or an
* <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#iterable" target="_blank">iterable</a>
* object into an Observable that emits the items in that promise, array, or iterable. A String, in this context, is treated
* as an array of characters. Observable-like objects (contains a function named with the ES2015 Symbol for Observable) can also be
* converted through this operator.
*
* ## Examples
* ### Converts an array to an Observable
* ```javascript
* import { from } from 'rxjs/observable/from';
*
* const array = [10, 20, 30];
* const result = from(array);
* result.subscribe(x => console.log(x));
* // Logs:
* // 10 20 30
* ```
* <a href="https://stackblitz.com/edit/js-tfvhag" target+"_blank">Stackblitz example</a>
Copy link
Member

Choose a reason for hiding this comment

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

I really appreciate adding stackblitz, but first I think it doesn't really adds value for the small api examples. I think it would be more helpful for the tutorial, we want to add soon. Additionally this messes up the outline in the docs and it isn't conform with accessibility standards. Really thanks for this, but I think this makes sense to add in a seperate pull request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds great to me. I will remove these examples and use later in tutorials.

* ---
* ### Convert an infinite iterable (from a generator) to an Observable
* ```javascript
* import { take } from 'rxjs/operators';
* import { from } from 'rxjs/observable/from';
*
* function* generateDoubles(seed) {
* let i = seed;
* while (true) {
* yield i;
* i = 2 * i; // double it
* }
* }
*
* const iterator = generateDoubles(3);
* const result = from(iterator).pipe(take(10));
* result.subscribe(x => console.log(x));
*
* // Logs:
* // 3 6 12 24 48 96 192 384 768 1536
* ```
*
* <a href="https://stackblitz.com/edit/js-e7r2ud" target="_blank">StackBlitz example</a>
* ---
*
* ### with async scheduler
* ```javascript
* import { from } from 'rxjs/observable/from';
* import { async } from 'rxjs/scheduler/async';
*
* console.log('start');
*
* const array = [10, 20, 30];
* const result = from(array, async);
*
* result.subscribe(x => console.log(x));
*
* console.log('end');
*
* // Logs:
* // start end 10 20 30
* ```
*
* <a href="https://stackblitz.com/edit/js-kghdtb" target="_blank">StackBlitz example</a>
*/
Copy link
Member

Choose a reason for hiding this comment

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

could you add param describtion for the method signature and return value