Netflix / x-element

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

Analysis-time errors should be halting #31

Closed theengineear closed 3 years ago

theengineear commented 5 years ago

Currently, analysis work actually uses an instance (to resolve methods, etc). This allows us to dispatch errors at runtime instead of just throwing errors. Because we're not throwing halting errors, we're able to consider these errors non-fatal and move on.

In light of the comment below about the truly static observeAttributes hook and in light of discussions about making both computed methods and observers static #30, I propose we do cause a halting error.

It will:

  1. Remove forks in logic that deal with graceful failure
  2. Allow us to be truly static with our analysis
  3. Can't be missed by developers since it will fail to render anything

As long as analysis is truly static, you know that if an instance boots in development, it will boot in production, so it's not really possible to cause an error in production if you got the thing working in development.

theengineear commented 5 years ago

Here's an interesting thought related to analysis-time work. There does exist one-and-only-one hook in the HTMLElement class that you can depend on to be called before any this of an element sees the light of day.

🥁 - rull

static get observedAttributes!

I think this is actually pretty neat and leads me maybe change my mind about dispatching an error... I.e., I think maybe we should throw a halting error instead.

The observedAttributes hook is cool because it:

  1. Enforces that we don't have this yet, so we can't cheat even if we want to!
  2. Doesn't require any special hooks from base classes
  3. Can't be broken by subclasses since properties don't work at all if you don't call this on super since that's where we make sure reflected properties are observed.

I'm going to update the description to reflect this change in opinion, I believe a history of edits is kept now, so feel free to peruse that if you need the context.

theengineear commented 5 years ago

@klebba , you won me over on this one. Thanks for entertaining my bad idea 👍

klebba commented 5 years ago

Hah, it was not a bad idea! Glad you were able to work through both options