Skip to content

Nicer API around composed members #82

@LeaVerou

Description

@LeaVerou

E.g. currently Props adds side effects to attributeChangedCallback() and has to wrap it manually:

let _attributeChangedCallback = this.prototype.attributeChangedCallback;
this.prototype.attributeChangedCallback = function (name, oldValue, value) {
	this.constructor[props].attributeChanged(this, name, oldValue, value);
	_attributeChangedCallback?.call(this, name, oldValue, value);
};

This is not only clumsy, it also doesn't play nicely with inheritance.

Similarly, it defines observedAttributes like this:

if (!Object.hasOwn(this, "observedAttributes")) {
	Object.defineProperty(this, "observedAttributes", {
		get: () => this[props].observedAttributes,
		configurable: true,
	});
}

which overrides any existing observedAttributes.

Ideally, we should have a better story for plugins that want to…

  • add side effects to an existing function
  • add values to an existing object or array

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions