-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split GridLayer into Grid (DOM-less) & GridLayer #2376
Conversation
Could this be refactored as encapsulation, so a GridLayer has a Grid as a member, instead of inheriting from it? |
@tmcw I'll try that, although most of my attempts at using composition in place of inheritance usually result in a much more verbose code, which I try to avoid in Leaflet. |
@mourner did doing DOM related stuff in I like the look of this, even with the extra super calls, maybe just adding a few comments to the super calls for clarification would help the readability. |
@patrickarlt as you can see here, there's a lot more DOM-related logic involved than just creating and removing tiles, like animation, upscaling etc. |
I gave the encapsulation approach a try this weekend and ran into a problem. If you try to make The only way I can see around this is to pass the I think this might result in more verbose code as @mourner suggested. |
GridLayer was rewritten substantially so we should do it from scratch anyway after the pyramid tiles stuff, so closing here. |
Sounds good the pyramid tiles stuff looks sweet. Any comment on if |
@patrickarlt not sure yet, we'll see how it looks when it's done in the #2382 branch. |
@mourner sounds good I'll keep an eye on that branch |
A bit of an update on this. I started by refactors which I wanted to use |
I've got this integrated into |
Following @patrickarlt suggestions in #2344, I made a quick experiment in the
grid
branch, splitting the currentGridLayer
implementation (534 lines) into two classes —Grid
(pure DOM-less grid logic with wrapping/bounding/etc, 299 lines) &GridLayer
(handles DOM tiles, positioning, anim etc., 277 lines).I'm not yet satisfied with how it looks because of too much super calls (
L.Grid.prototype.method.call(this, a, b)
) and a bit bulkier code overall (31 more sloc), but the direction might be promising, as it logically splits the hugeGridLayer
implementation in half, and the current 534 lines for one class is too much and looks pretty messy.I'm sure @jfirebaugh won't like it though, he hates inheritance. :) I don't currently see a clean way to deal with
GridLayer
complexity without introducing another class in inheritance chain though. cc @tmcw