react-flexbox-layout icon indicating copy to clipboard operation
react-flexbox-layout copied to clipboard

Make the update engine listen to resize based on registrations

Open leoasis opened this issue 9 years ago • 3 comments

We could avoid explicitly listening to window's resize event and just automatically start listening/stop listening depending on the amount of registered components with the engine.

The idea would be that when there is at least 1 component, we listen to the resize event, and when we have no components (because they deregistered), we stop listening.

We can even check if we're in a DOM to support server side rendering, and all that can be handled transparently inside the engine module, without explicitly calling it, or having a side effect when requiring it.

What do you think? Any drawbacks you see?

leoasis avatar Jan 26 '16 03:01 leoasis

nope, don't see any drawbacks. However, I think that if react-flexbox-layout is required, there will most likely be at least one flexbox component, so it's pretty safe to just start listening automatically. Still, definitely open to the improvement!

bywo avatar Jan 26 '16 06:01 bywo

I was thinking on the use case where you may have a page where you're not using any layout components, and when that page is rendered (all layout components are unmounted), we stop listening for resize and later on when we get to a page where we use them, the listener is added.

Probably not that realistic though since the idea of layout components is to use them all over the place. The main goal (at least as I see it) for this improvement is to completely forget that there is a listener and hide that implementation detail in the update engine module.

leoasis avatar Jan 26 '16 16:01 leoasis

ahh I see. yea that's a good idea. I'm all for it

On Tue, Jan 26, 2016 at 8:56 AM Leonardo Garcia Crespo < [email protected]> wrote:

I was thinking on the use case where you may have a page where you're not using any layout components, and when that page is rendered (all layout components are unmounted), we stop listening for resize and later on when we get to a page where we use them, the listener is added.

Probably not that realistic though since the idea of layout components is to use them all over the place. The main goal (at least as I see it) for this improvement is to completely forget that there is a listener and hide that implementation detail in the update engine module.

— Reply to this email directly or view it on GitHub https://github.com/byronmwong/react-flexbox-layout/issues/13#issuecomment-175114563 .

bywo avatar Jan 26 '16 17:01 bywo