docs(nx): adds docs for readAll and readFirst

This commit is contained in:
vsavkin 2017-10-04 11:29:30 -04:00
parent 47ab8a5d72
commit 73c8c6c7fd
2 changed files with 27 additions and 1 deletions

View File

@ -2,7 +2,9 @@ import {ModuleWithProviders, NgModule} from '@angular/core';
import {DataPersistence} from './data-persistence';
/**
* @whatItDoes Provides services simplifying enterprise Angular development.
* @whatItDoes Provides services for enterprise Angular applications.
*
* See {@link DataPersistence} for more information.
*/
@NgModule({})
export class NxModule {

View File

@ -3,10 +3,34 @@ import {first} from 'rxjs/operator/first';
import {toArray} from 'rxjs/operator/toArray';
import {toPromise} from 'rxjs/operator/toPromise';
/**
* @whatItDoes reads all the values from an observable and returns a promise
* with an array of all values. This should be used in combination with async/await.
*
* ## Example
*
* ```typescript
* const obs = of(1, 2, 3, 4);
* const res = await readAll(obs)
* expect(res).toEqual([1, 2, 3, 4]);
* ```
*/
export function readAll<T>(o: Observable<T>): Promise<T[]> {
return toPromise.call(toArray.call(o));
}
/**
* @whatItDoes reads the first value from an observable and returns a promise
* with it. This should be used in combination with async/await.
*
* ## Example
*
* ```typescript
* const obs = of(1, 2, 3, 4);
* const res = await readFirst(obs)
* expect(res).toEqual(1);
* ```
*/
export function readFirst<T>(o: Observable<T>): Promise<T> {
return toPromise.call(first.call(o));
}