From c240ee633756f8fa45d63d3a3210f67dca0eac81 Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 18 Mar 2019 19:57:31 -0500 Subject: [PATCH] feat: meta.emit --- packages/mixins/property.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/mixins/property.js b/packages/mixins/property.js index c3792d1..8ab9e21 100644 --- a/packages/mixins/property.js +++ b/packages/mixins/property.js @@ -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); } }, });