javascript - Property dependencies on object attributes -
i'd use property dependencies avoid dirty checking on computed properties. since properties on computed property depends no primitives attributes of object don't know how make work.
code:
import {computedfrom} 'aurelia-framework'; export class person { persondata = { firstname: 'john', lastname: 'doe', // more attributes... } // ... // doesn't work: @computedfrom('persondata.firstname', 'persondata.lastname') // neither does: // @computedfrom('persondata["firstname"], 'persondata["lastname"]') // nor: // @computedfrom('persondata') fullname() { return `${this.persondata.firstname} ${this.persondata.lastname}`; } // ... }
the @computedfrom
attribute add support expressions- keep eye on https://github.com/aurelia/binding/pull/276
a word of caution- overusing @computedfrom
(eg @computedfrom(p1.p2.p3, p4.p5, p6, p7, p8)
) end being less performant dirty-checking. there's tradeoff between one-time setup of observers vs continuous function evaluation dirty-checking- mileage may vary.
another option use with
binding in view , bind object props directly:
<span with="persondata">${firstname} ${lastname}</span>
last not least, there's aurelia-computed
plugin can parse getter function bodies , produce observer doesn't use dirty-checking: https://github.com/jdanyow/aurelia-computed
Comments
Post a Comment