feat: meta.emit

This commit is contained in:
cha0s 2019-03-18 19:57:31 -05:00
parent c1f18949e5
commit c240ee6337

View File

@ -23,6 +23,12 @@ export function PropertyMixin(key, meta = {}) {
meta.transformProperty = (key) => `${key}_PRIVATE_PROPERTY`;
}
meta.emit = meta.emit || function(...args) {
if (this.emit) {
this.emit(...args);
}
}
meta.eq = meta.eq || function (l, r) {
return l === r;
}
@ -65,8 +71,8 @@ export function PropertyMixin(key, meta = {}) {
set: function (value) {
const old = meta.get.call(this);
meta.set.call(this, value);
if (this.emit && !meta.eq.call(this, old, value)) {
this.emit(`${key}Changed`, old, value)
if (meta.track && meta.emit && !meta.eq.call(this, old, value)) {
meta.emit.call(this, `${key}Changed`, old, value);
}
},
});