This repository has been archived by the owner on Oct 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(operators): add documentation for toPromise
- Loading branch information
Wortmann, Jan-Niklas
authored and
Wortmann, Jan-Niklas
committed
Jan 4, 2018
1 parent
5059b48
commit 412c024
Showing
1 changed file
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,46 @@ | ||
import { OperatorDoc } from '../operator.model'; | ||
|
||
export const toPromise: OperatorDoc = { | ||
'name': 'toPromise', | ||
'operatorType': 'utility' | ||
export const toPromiseOperator: OperatorDoc = { | ||
name: 'toPromise', | ||
operatorType: 'utility', | ||
signature: 'public toPromise(PromiseCtor: *): Promise<T>', | ||
parameters: [ | ||
{ | ||
name: 'PromiseCtor', | ||
type: '*', | ||
attribute: 'optional', | ||
description: `promise The constructor of the promise. If not provided, | ||
it will look for a constructor first in Rx.config.Promise then fall back to the native Promise constructor if available.` | ||
} | ||
], | ||
shortDescription: { | ||
description: `An ES2015 compliant promise which contains the last value from the Observable sequence. | ||
If the Observable sequence is in error, then the Promise will be in the rejected stage. | ||
If the sequence is empty, the Promise will not resolve.`, | ||
extras: [ | ||
{ | ||
type: 'Tip', | ||
text: | ||
'This operator makes reactive programming easy to use for developers who are not used to it.' | ||
} | ||
] | ||
}, | ||
examples: [ | ||
{ | ||
name: 'Just return the emitted value of the observable as a promise', | ||
code: ` | ||
const source = Rx.Observable | ||
.of(42) | ||
.toPromise(); | ||
source.then((value) => console.log('Value: %s', value)); | ||
// => Value: 42 | ||
`, | ||
externalLink: { | ||
platform: 'JSBin', | ||
url: 'http://jsbin.com/fanivejahe/embed?js,console,output' | ||
} | ||
} | ||
], | ||
relatedOperators: ['map', 'subscribe'] | ||
}; |