Just found out how to do this, sharing to the community. Let me know if my approach has problem/limitation.
The use case is, I like to keep my app repo lean, so I have habit to push down as many business logic as I could to seperate repos. My app repo adds them using git repo tag.
Those packages are pure logic, have no dependencies on Aurelia. I can reuse the code in other projects (some are not web apps).
The problem is, when you use getter property xmax
in Aurelia html template, it ends up as a dirty check
.
class Box {
// x, y, width, hight
get xmax() {
return this.x + this.width;
}
}
One possible solution is add aurelia-binding
to your lib’s dependencies, and use @computedFrom('x', 'width')
on xmax
.
But that defeats our will to keep that lib out of Aurelia.
Here is how you can manually teach Aurelia the dependencies of xmax
, without using computedFrom
.
class Box {
// x, y, width, hight
get xmax() {
return this.x + this.width;
}
}
// this got same effect as @computedFrom('x', 'width')
Object.getOwnPropertyDescriptor(
Box.prototype, 'xmax'
).get.dependencies = ['x', 'width'];