Netflix / x-element

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

Make functional “initial”/“default” per instance. #81

Closed theengineear closed 3 years ago

theengineear commented 3 years ago

Previously, we allowed these to be shared across all instances, it’s now only shared over time across the same instance.

Importantly, the same default value is used per-instance over and over again. Otherwise, you might unnecessarily cause additional computes when an upstream dependency gets a new default reference.

IMPORTANTLY, this means that if you wrote code like default: () => () => (\* whatever *\), you need to change it to default: () => (\* whatever *\). Previously, that's how you would make something per instance vs per constructor. I.e., whereas the functional syntax served as a reminder that you were setting something mutable, you now just cannot set a mutable default on the constructor at all.

theengineear commented 3 years ago

@codeStryke and @klebba — I updated this to match our current expectations. The test suite was update (and extended) to match.

Gonna merge since I doubt there will be any objection here. I made a note about the lines of code that might potentially be effected. They're easy to search for in a codebase.