PolymerTS icon indicating copy to clipboard operation
PolymerTS copied to clipboard

@computed with dotted property paths: clarify docs

Open kwaclaw opened this issue 9 years ago • 2 comments

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;
    }

kwaclaw avatar Apr 04 '16 15:04 kwaclaw

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 {
    }

nippur72 avatar Apr 04 '16 18:04 nippur72

Yeah, I understand why it would not work. The suggested approach looks reasonable.

kwaclaw avatar Apr 04 '16 20:04 kwaclaw