PolymerTS
PolymerTS copied to clipboard
@computed with dotted property paths: clarify docs
Seems when the computed value is based on a sub-property, the @computed annotation style does not work. Maybe clarify in the documentation. Example:
@property({ type: Object, notify: true })
model: AppModel;
// this does not compile
@computed({ type: Boolean, notify: true })
isAuthenticated(model.userProfile: any): boolean {
return this.model.userProfile != null;
}
//this works
@property({ type: Boolean, notify: true, computed: "getAuthenticated(model.userProfile)" })
isAuthenticated: boolean;
getAuthenticated(userProfile: any): boolean {
return this.model.userProfile != null;
}
that's because
isAuthenticated(model.userProfile: any): boolean { }
is not valid JavaScript/TypeScript.
But perhaps @computed can be modified so to accept a name or path, e.g.:
@computed({ type: Boolean, notify: true, path: "model.userProfile" })
isAuthenticated(userProfile: any): boolean {
}
Yeah, I understand why it would not work. The suggested approach looks reasonable.