@watch()
shouldn't patch the prototype every time it's used.
#1990
Labels
bug
Things that aren't working right in the library.
@watch()
shouldn't patch the prototype every time it's used.
#1990
Describe the bug
@watch()
currently patches the element prototype to overrideupdate()
each time it's applied. Patching the prototype at all is less-then-ideal for performance, but creating a potentially long chain of calls will be worse. As decorators migrate towards standard decorators such patching will be impossible anyway, and there will be no other patching from experimental decorators, potentially making this patch (if it can be done) the only thing to change the class shape, slowing class initialization.To fix this, I'd recommend making
@watch()
cooperate with a base class that allows watchers. The directive stores the information about the watcher in a cache, and the base class looks up the watchers to invoke them.Here's some code from a similar utility I have:
This is a standard decorator, but it can be adapted to experimental decorators by using the class as the key into the
observersForClass
map.One benefit of this approach is that the watcher run in definition order, which is probably more intuitive. Right now watchers run in reverse definition order because the later methods make the outer wrappers for
update()
.It would be a breaking change to require a supporting implementation of
update()
, but one could be provided by a mixin, or devs could extend ShoelaceElement.To Reproduce
n/a
Demo
n/a
Screenshots
n/a
Browser / OS
all
Additional information
The text was updated successfully, but these errors were encountered: