Netflix / x-element

A dead simple starting point for custom elements.
Apache License 2.0
28 stars 12 forks source link

Ensure computation on initialization. #144

Closed theengineear closed 1 year ago

theengineear commented 1 year ago

This handles a nuanced edge case where internal, computed properties can be incorrect if they were interrogated between host construction and initialization.

For example:

// This will trigger construction (assuming the element is defined).
const element = document.createElement('my-element');

// Do things after construction, before initialization.

// This will trigger initialization (again, assuming definition).
document.body.append(element);

// Do things after initialization while connected.

This change set should guarantee that after initialization, during connection — things will be correct. We cannot make such guarantees when not connected due to lack of eventing around attribute callbacks.

Closes #143.

theengineear commented 1 year ago

FYI @klebba — Going to get this change in since I'm confident on it and I'd like to include it in a project I'm working on. I left detailed code comments for you — we can always revert / change if you're opposed 👌