renderObservable()¶
Observable creation operator
Create a new Observable that emits when the component render() function is
called. Value will be emitted after the next microtask (next tick).
If component is already rendered, the observable will emit immediately.
It uses hot observable pattern, which means that the observable is shared between all subscribers and emits the same value to all of them.
- renderObservable(cmp)¶
Creates an observable emitting when the component render() function is called.
function renderObservable(cmp: ComponentInterface): Observable<void>;
- Arguments:
cmp (
ComponentInterface) – The Stencil component instance to observe.
- Returns:
Observable that emits when the component render() function is called.
- Return type:
Observable<void>
Example¶
Initialize custom logic when component is rendered¶
1import {
2 Component,
3 ComponentInterface,
4 h,
5} from '@stencil/core';
6import { take } from 'rxjs/operators';
7import { renderObservable } from '@runopenode/rxjs-stencil';
8
9@Component({
10 tag: 'my-cmp',
11 shadow: true,
12})
13class MyCmp implements ComponentInterface {
14
15 public constructor() {
16 renderObservable(this)
17 .pipe(
18 take(1)
19 )
20 .subscribe((): void => {
21 // Initialize custom logic when component is rendered.
22 });
23 }
24
25 public render(): any {
26 // Render component template
27 }
28}