cryss
cryss

Reputation: 4509

Aurelia and computed properties

I've just started looking at AureliaJS so I created a sample app described here: http://aurelia.io/get-started.html. I noticed a strange behavior there.

In the example we have:

get fullName(){
    return `${this.firstName} ${this.lastName}`;
}

But when I put there a logging:

get fullName(){
    console.log('test');
    return `${this.firstName} ${this.lastName}`;
}

The app will start logging infinitely the 'test' value. Have you experienced the same results?

Upvotes: 1

Views: 112

Answers (1)

cryss
cryss

Reputation: 4509

I've just experienced a dirty-checking here. When we use computed properties, we have to explicitly define the dependencies. Like that:

@computedFrom('firstName', 'lastName')
get fullName(){
    return `${this.firstName} ${this.lastName}`;
}

When you don't specify the computedFrom decorator here, aurelia will use a dirty-checking.

Upvotes: 1

Related Questions