@ormasoftchile That’s a really good question!
For almost every real world use-case, there would be need to observe property change, I think.
So, I tried to add messageChanged(newValue, oldValue)
method to MyApp
class, import observable
and copy/paste __decorate(...)
, __metadata(...)
functions and call to __decorate
, but it does not work.
This is the actual code:
<script type="module">
import { observable } from '@aurelia/runtime';
import { Aurelia, StandardConfiguration } from '@aurelia/runtime-html';
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
class MyApp {
message = "Hello Aurelia 2!";
messageChanged(newValue, oldVelue) {
console.log(`${oldVelue} -> ${newValue}`);
}
reverseMessage() {
this.message = this.message.split('').reverse().join('');
}
};
__decorate([
observable,
__metadata("design:type", String)
], MyApp.prototype, "message", void 0);
new Aurelia()
.register(StandardConfiguration)
.enhance({
host: document.querySelector('#my-app'),
component: MyApp
});
</script>
If I remember correctly, Aurelia v1 has static helper method somewhere (I think it is called Decorate
), as a helper when using plain es5. I am not aware if this is possible in Aurelia v2.
There is a link to API documentation, but it does not help at all:
http://aurelia.io/docs/api/metadata/function/decorators