Skip to content

Commit

Permalink
fix: __changedProperties not working with multiple instances
Browse files Browse the repository at this point in the history
__changedProperties is now part of instance

Signed-off-by: Wouter Vroege <[email protected]>
  • Loading branch information
woutervroege committed Apr 8, 2020
1 parent f0f3117 commit dda605b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/addons/properties-changed-callback-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ export const PropertiesChangedCallback = (SuperClass) => class extends SuperClas

propertyChangedCallback(propName, oldValue, newValue) {
super.propertyChangedCallback && super.propertyChangedCallback(propName, oldValue, newValue);
if(!this.constructor.__changedProperties) this.constructor.__changedProperties = new Map();
if(!this.__changedProperties) this.__changedProperties = new Map();
this.constructor.__addChangedProperty.call(this, propName, oldValue);
}

static __addChangedProperty(propName, oldValue) {
window.cancelAnimationFrame(this.__propertiesChangedCallbackDebouncer);
const changedProps = this.constructor.__changedProperties;
const changedProps = this.__changedProperties;
if(!changedProps.has(propName)) changedProps.set(propName, oldValue);
this.__propertiesChangedCallbackDebouncer = window.requestAnimationFrame(this.constructor.__invokeCallback.bind(this));
}

static __invokeCallback() {
const oldValues = {};
const newValues = {};
this.constructor.__changedProperties.forEach((oldValue, propName) => oldValues[propName] = oldValue);
this.constructor.__changedProperties.forEach((oldValue, propName) => newValues[propName] = this[propName]);
this.__changedProperties.forEach((oldValue, propName) => oldValues[propName] = oldValue);
this.__changedProperties.forEach((oldValue, propName) => newValues[propName] = this[propName]);
const propNames = Object.keys(oldValues);

this.constructor.__changedProperties.clear();
this.__changedProperties.clear();
this.propertiesChangedCallback && this.propertiesChangedCallback(propNames, oldValues, newValues);
}

Expand Down

0 comments on commit dda605b

Please sign in to comment.