Skip to content

Lifecycle

All beans can provide two lifecycle methods

NameDescription
__init__The initialization method executed when creating a bean instance, and supports asynchrony
__dispose__The dispose method executed during bean instance destruction
  • Zova provides two code snippets, you can quickly add corresponding lifecycle methods by entering init or dispose

For Example: $useComputed

typescript
export class Counter {
  count: number = 0;
  count2: string;

  protected async __init__() {
    this.count2 = this.$useComputed(() => {
      return `=== ${this.count} ===`;
    });
  }
}

For Example: $watch

typescript
export class Counter {
  count: number = 0;

  protected async __init__() {
    this.$watch(
      () => this.count,
      () => {
        console.log('changed: ', this.count);
      },
    );
  }
}

Released under the MIT License.