koenbok / Framer

Framer - Design Everything
https://framer.com
MIT License
5.85k stars 477 forks source link

removing event handlers will create DOMEventManagerElement's #560

Open onnlucky opened 6 years ago

onnlucky commented 6 years ago

On init and on destroy of a layer, event handlers are removed from elements that sometimes don't even have handlers. The problem is this will call the getter layer._domEventHandler and will create a needless DOMEventManagerElement just so all handlers can be removed.

For example, @define "constraintValues" calls @off "change:parent", @parentChanged when set with null, which is done when applying defaults.

Also in Layer.destroy(), @_context.emit("layer:destroy", @) will trigger code that has the same effect.

All that work is just wasteful. Especially for Layers that never actually have any dom event handlers.

jordandobson commented 6 years ago

So are you suggesting removing the layer:destroy event? We definitely need to keep this around so we know when a layer is destroyed.

I understand not firing the change:parent when set to null during initialization... If that's what you are saying.

onnlucky commented 6 years ago

Any code that calls @off for event handlers, will implicitly create a dom even wrapper because it is created in a getter. We need an alternative to the default getter that will not create a wrapper, and places that use it can skip a lot of work if there never was a wrapper.

I am not proposing to remove "layer:destroy", only to make the code that emits it follow the same code path that avoids creating needless wrappers.