AUR0774
Last updated
Was this helpful?
Was this helpful?
class MyClass {
@watch('someExpression') // Incorrect: Applied to a property
myProperty: string = 'value';
} class MyClass {
_value: string;
@watch('someExpression') // Incorrect: Applied to a getter
get myValue() { return this._value; }
}import { watch, resolve } from '@aurelia/runtime-html';
import { ILogger } from '@aurelia/kernel';
export class MyViewModel {
private readonly logger = resolve(ILogger);
firstName: string = 'John';
lastName: string = 'Doe';
userId: number = 1;
// Correct: @watch applied to a method
@watch('firstName')
firstNameChanged(newValue: string, oldValue: string) {
this.logger.info(`First name changed: ${oldValue} -> ${newValue}`);
}
// Correct: @watch applied to the class
@watch({ expression: 'lastName', changeHandler: 'lastNameChangedHandler' })
static { /* Class decorator usage */ }
lastNameChangedHandler(newValue: string, oldValue: string) {
this.logger.info(`Last name changed: ${oldValue} -> ${newValue}`);
}
// Incorrect: @watch applied to a property/field - Causes AUR0774
// @watch('userId')
// watchedUserId: number = this.userId;
private _internalValue: string = 'initial';
// Incorrect: @watch applied to a getter - Causes AUR0774
// @watch('somethingElse')
// get computedValue(): string {
// return this._internalValue.toUpperCase();
// }
// Incorrect: @watch applied to a setter - Causes AUR0774
// @watch('yetAnotherThing')
// set computedValue(value: string) {
// this._internalValue = value;
// }
}
// Correct class decorator usage syntax
@watch({ expression: 'userId', changeHandler: 'userIdChangedHandler' })
export class UserComponent {
private readonly logger = resolve(ILogger);
userId: number = 10;
userIdChangedHandler(newValue: number, oldValue: number){
this.logger.info(`User ID changed: ${oldValue} -> ${newValue}`);
}
}