propertiesObservable()¶
Observable creation operator
Creates an observable that emits the value of a properties on an component
whenever properties change. It uses the same underlying implementation as
propertyObservable() operator, in conjunction with combineLatest()
operator, to observe multiple properties at once.
- propertiesObservable(cmp, ...properties)¶
Creates an observable emitting the values of multiple properties on a Stencil component whenever they change.
function propertiesObservable<T extends ComponentInterface, K extends keyof T>(cmp: T, ...properties: K[]): Observable<Pick<T, K>>; function propertiesObservable<P extends object>(cmp: ComponentInterface, ...properties: (keyof P)[]): Observable<P>;
- Arguments:
cmp (
ComponentInterface) – The Stencil component instance for which to observe the properties....properties (
PropertyKey) – The names of the properties to observe.
- Returns:
Observable that emits an object containing the latest values of the specified properties whenever any of the properties change.
- Return type:
Record<PropertyKey, unknown>
Hint
Operator can infer the type of properties from the component only if
the observed properties are declared as public and have a type
annotation. Otherwise, you will need to provide the types explicitly
or deal with any type.
Example¶
1import {
2 Component,
3 ComponentInterface,
4 h,
5} from '@stencil/core';
6import { propertiesObservable } from '@runopenode/rxjs-stencil';
7import { Observable } from 'rxjs';
8
9@Component({
10 tag: 'my-cmp',
11 shadow: true,
12})
13class MyCmp implements ComponentInterface {
14
15 public foo: string;
16
17 public bar: number;
18
19 public constructor() {
20 propertiesObservable(this, 'foo', 'bar')
21 .subscribe(({foo, bar}): void => {
22 // Handle changes to foo and bar
23 });
24 }
25
26 public render(): any {
27 // Render component template
28 }
29}