Skip to content
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

Remove controls when the map is removed #7042

Merged
merged 2 commits into from
Jul 30, 2018
Merged

Remove controls when the map is removed #7042

merged 2 commits into from
Jul 30, 2018

Conversation

mollymerp
Copy link
Contributor

fix #3264

Launch Checklist

  • briefly describe the changes in this PR
  • write tests for all new functionality
  • manually test the debug page

Copy link
Contributor

@jfirebaugh jfirebaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Add a test for the new map.remove() behavior too.

src/ui/map.js Outdated
const numControls = this._controls.length;
for (let i = numControls; i > 0; i--) {
this.removeControl(this._controls[i - 1]);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you could just call onRemove directly and not worry about indices:

for (const control of this._controls) control.onRemove(this);

@@ -785,8 +785,13 @@ test('Map', (t) => {
t.test('#remove', (t) => {
const map = createMap(t);
t.equal(map.getContainer().childNodes.length, 3);
// LogoControl is added to the map in the constructor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about something like:

t.test('#remove calls onRemove on added controls', (t) => {
    const map = createMap(t);
    const control = { onRemove: t.spy() };
    map.addControl(control);
    map.remove();
    t.ok(control.onRemove.calledOnce);
});

This avoids relying on map implementation details, and tests one desired behavior in isolation from others so it's easier to understand and debug if it fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Memory usage increases even after map.remove()
3 participants