-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
There was a problem hiding this 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]); | ||
} |
There was a problem hiding this comment.
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);
2b42661
to
b2a1ff6
Compare
test/unit/ui/map.test.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
… is removed simpler loop + new test update test
b2a1ff6
to
e240a48
Compare
fix #3264
Launch Checklist