Skip to content

Commit

Permalink
fix(core): remove double change event on create
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Aug 9, 2023
1 parent 97497c3 commit 546ec3c
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions core/CustomElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,32 +358,11 @@ export default class CustomElement extends ICustomElement {

const {
changedCallback: customSimpleCallback,
propChangedCallback: customNamedCallback,
fireChangeOnCreate,
} = options;

const customCallbacks = [];
if (customSimpleCallback) {
customCallbacks.push([name, customSimpleCallback]);
}
if (customNamedCallback) {
customCallbacks.push([name, function remappedCallback(...args) {
customNamedCallback.call(this, name, ...args);
}]);
}
if (customCallbacks.length) {
this.onPropChanged(customCallbacks);
if (fireChangeOnCreate) {
this._addCallback('_onConstructedCallbacks', function onCreateChangeEmitter() {
const value = this[name];
if (customSimpleCallback) {
customSimpleCallback.call(this, undefined, value, null);
}
if (customNamedCallback) {
customNamedCallback.call(this, name, undefined, value, null);
}
});
}
this.onPropChanged([[name, customSimpleCallback]]);
}

// TODO: Inspect possible closure bloat
Expand All @@ -393,6 +372,14 @@ export default class CustomElement extends ICustomElement {

const config = defineObservableProperty(this.prototype, name, options);

if (fireChangeOnCreate) {
this._addCallback('_onConstructedCallbacks', function onCreateChangeEmitter() {
const value = this[name];
config.propChangedCallback?.call(this, name, value, value, null);
config.changedCallback?.call(this, value, value, null);
});
}

this.propList.set(name, config);

const { attr, reflect, watchers, INIT_SYMBOL } = config;
Expand Down

0 comments on commit 546ec3c

Please sign in to comment.