@glimmer/tracking
Version:
Glimmer property tracking library
59 lines (58 loc) • 1.67 kB
TypeScript
/**
* @decorator
*
* Marks a property as tracked.
*
* By default, a component's properties are expected to be static,
* meaning you are not able to update them and have the template update accordingly.
* Marking a property as tracked means that when that property changes,
* a rerender of the component is scheduled so the template is kept up to date.
*
* @example
*
* ```typescript
* import Component from '@glimmer/component';
* import { tracked } from '@glimmer/tracking';
*
* export default class MyComponent extends Component {
* @tracked
* remainingApples = 10
* }
* ```
*
* When something changes the component's `remainingApples` property, the rerender
* will be scheduled.
*
* @example Computed Properties
*
* In the case that you have a getter that depends on other properties, tracked
* properties accessed within the getter will automatically be tracked for you.
* That means when any of those dependent tracked properties is changed, a
* rerender of the component will be scheduled.
*
* In the following example we have two properties,
* `eatenApples`, and `remainingApples`.
*
*
* ```typescript
* import Component from '@glimmer/component';
* import { tracked } from '@glimmer/tracking';
*
* const totalApples = 100;
*
* export default class MyComponent extends Component {
* @tracked
* eatenApples = 0
*
* get remainingApples() {
* return totalApples - this.eatenApples;
* }
*
* increment() {
* this.eatenApples = this.eatenApples + 1;
* }
* }
* ```
*/
export declare let tracked: PropertyDecorator;
export declare function setPropertyDidChange(cb: () => void): void;