scheduleRender()¶
Pipeable operator
Schedule a render of the component. This is useful when you want to force a render of the component as result of changing the values of the component which are not tracked by Stencil (observables, for example).
By default, the render is scheduled on the next tick (after
Promise.resolve()), but you can disable this behavior by passing false
as second argument.
- scheduleRender(cmp, nextTick=true)¶
Schedules a render of the component.
function scheduleRender<T = unknown>(cmp: ComponentInterface, nextTick: boolean = true): MonoTypeOperatorFunction<T>
- Arguments:
cmp (
ComponentInterface) – The Stencil component instance for which to schedule a render.nextTick (
boolean) – Optional. Iftrue, the render will be scheduled on the next tick (afterPromise.resolve()). Iffalse, the render will be scheduled immediately.
Example¶
Schedule rendering of component when observable emits¶
1import { Component, h } from '@stencil/core';
2import { Observable, of } from 'rxjs';
3import { scheduleRender } from '@runopenode/stencil-rxjs';
4
5@Component({
6 tag: 'my-component',
7 shadow: true,
8})
9export class MyComponent {
10
11 private myObservable$: Observable<number> = of(1, 2, 3);
12
13 private _value: number = 0;
14
15 public constructor() {
16 this.myObservable$
17 .pipe(
18 tap(value => this._value = value),
19 scheduleRender(this)
20 )
21 .subscribe();
22 }
23
24 render() {
25 return (
26 <div>{{ this._value }}</div>
27 );
28 }
29}