From 412c0248c619e91c7b71e791436f7df8b04ec718 Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Wed, 3 Jan 2018 20:42:28 +0100 Subject: [PATCH 1/6] docs(operators): add documentation for toPromise --- src/operator-docs/utility/toPromise.ts | 46 ++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index f08859af..5023d662 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -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', + 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'] }; From f8668717c60d95c5693120c9fe44a8a7c9c24ad4 Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Thu, 4 Jan 2018 21:50:32 +0100 Subject: [PATCH 2/6] docs(operators): fix documentation due to copy paste errors --- src/operator-docs/utility/toPromise.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index 5023d662..58af1088 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -1,6 +1,6 @@ import { OperatorDoc } from '../operator.model'; -export const toPromiseOperator: OperatorDoc = { +export const toPromise: OperatorDoc = { name: 'toPromise', operatorType: 'utility', signature: 'public toPromise(PromiseCtor: *): Promise', @@ -42,5 +42,5 @@ export const toPromiseOperator: OperatorDoc = { } } ], - relatedOperators: ['map', 'subscribe'] + relatedOperators: ['fromPromise'] }; From 7098aaaa25fceb4bbd75c5fa12d637237a89c66d Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Thu, 4 Jan 2018 22:34:34 +0100 Subject: [PATCH 3/6] docs(operators): add short description --- src/operator-docs/utility/toPromise.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index 58af1088..5b6d1ed1 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -14,6 +14,10 @@ export const toPromise: OperatorDoc = { } ], shortDescription: { + description: + 'Converts an Observable sequence to a ES2015 compliant promise.' + }, + walkthrough: { 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.`, From eda96b689fbf1a6673729c60b3596cd0e6f9e2ab Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Tue, 16 Jan 2018 21:10:28 +0100 Subject: [PATCH 4/6] docs(operators): fix typo in toPromise doc --- src/operator-docs/utility/toPromise.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index 5b6d1ed1..700211a8 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -3,13 +3,13 @@ import { OperatorDoc } from '../operator.model'; export const toPromise: OperatorDoc = { name: 'toPromise', operatorType: 'utility', - signature: 'public toPromise(PromiseCtor: *): Promise', + signature: 'public toPromise(PromiseCtor: *): Promise', parameters: [ { name: 'PromiseCtor', type: '*', attribute: 'optional', - description: `promise The constructor of the promise. If not provided, + description: `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.` } ], From fa33d59a41ca6722adc551e79beffea47afc6554 Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Tue, 6 Feb 2018 20:15:14 +0100 Subject: [PATCH 5/6] docs(documentation): add es 6 import to toPromise documentation --- src/operator-docs/utility/toPromise.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index 700211a8..68bac448 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -33,8 +33,9 @@ export const toPromise: OperatorDoc = { { name: 'Just return the emitted value of the observable as a promise', code: ` - const source = Rx.Observable - .of(42) + import {of} from 'rxjs/observable/of'; + + const source = of(42) .toPromise(); source.then((value) => console.log('Value: %s', value)); From e1ad924feb9f2e0a1eb5a19842f53643a67f9f72 Mon Sep 17 00:00:00 2001 From: "Wortmann, Jan-Niklas" Date: Tue, 13 Feb 2018 17:47:20 +0100 Subject: [PATCH 6/6] docs(operators): add tip for async await --- src/operator-docs/utility/toPromise.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/operator-docs/utility/toPromise.ts b/src/operator-docs/utility/toPromise.ts index 68bac448..39809317 100644 --- a/src/operator-docs/utility/toPromise.ts +++ b/src/operator-docs/utility/toPromise.ts @@ -26,6 +26,10 @@ export const toPromise: OperatorDoc = { type: 'Tip', text: 'This operator makes reactive programming easy to use for developers who are not used to it.' + }, + { + type: 'Tip', + text: 'After calling toPromise you can make use of async/await!' } ] },