Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(docs-infra): convert hard-coded
comparing-observables
examples …
…into a proper mini-app Previously, the examples in the `comparing-observables` guide were hard-coded. This made it impossible to test them and verify they are correct. This commit fixes this by converting them into a proper mini-app. In a subsequent commit, tests will be added to verify that the source code works as expected (and guard against regressions). Fixes #31024
- Loading branch information
1 parent
ead169a
commit 70e85d1
Showing
4 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
40 changes: 40 additions & 0 deletions
40
aio/content/examples/comparing-observables/src/observables.ts
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { map } from 'rxjs/operators'; | ||
import { Observable } from 'rxjs'; | ||
|
||
// #docregion observable | ||
|
||
// declare a publishing operation | ||
const observable = new Observable<number>(observer => { | ||
// Subscriber fn... | ||
}); | ||
|
||
// initiate execution | ||
observable.subscribe(() => { | ||
// observer handles notifications | ||
}); | ||
|
||
// #enddocregion observable | ||
|
||
// #docregion unsubscribe | ||
|
||
const subscription = observable.subscribe(() => { | ||
// observer handles notifications | ||
}); | ||
|
||
subscription.unsubscribe(); | ||
|
||
// #enddocregion unsubscribe | ||
|
||
// #docregion error | ||
|
||
observable.subscribe(() => { | ||
throw Error('my error'); | ||
}); | ||
|
||
// #enddocregion error | ||
|
||
// #docregion chain | ||
|
||
observable.pipe(map(v => 2 * v)); | ||
|
||
// #enddocregion chain |
25 changes: 25 additions & 0 deletions
25
aio/content/examples/comparing-observables/src/promises.ts
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// #docregion promise | ||
// initiate execution | ||
const promise = new Promise<number>((resolve, reject) => { | ||
// Executer fn... | ||
}); | ||
|
||
promise.then(value => { | ||
// handle result here | ||
}); | ||
|
||
// #enddocregion promise | ||
|
||
// #docregion chain | ||
|
||
promise.then(v => 2 * v); | ||
|
||
// #enddocregion chain | ||
|
||
// #docregion error | ||
|
||
promise.then(() => { | ||
throw Error('my error'); | ||
}); | ||
|
||
// #enddocregion error |
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