-
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
check if before layer exists #5679
check if before layer exists #5679
Conversation
src/style/style.js
Outdated
@@ -622,6 +622,10 @@ class Style extends Evented { | |||
this._order.splice(index, 1); | |||
|
|||
const newIndex = before ? this._order.indexOf(before) : this._order.length; | |||
if (before && newIndex === -1) { | |||
this.fire('error', { message: new Error(`Layer with id "${before}" does not exist on this map.`)}); |
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.
The key here should be error
since you're passing an error object, not a message.
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.
Oh, I see it was mixed up in the original code.
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.
I think you're right, the key here should be error
as well as here https://github.com/mapbox/mapbox-gl-js/pull/5679/files#diff-0fcf9ef37a1614185cad0dcbd5ec5529L571
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.
Shall I change it to a {error: ....}
?
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.
yes please @jingsam and it would be great if you could change the it to {error: new Error...
on line 571 as well. thank you!
Otherwise looks good! |
@jingsam did you want to fix up the JSDoc just a few lines above your change while you're at it? https://github.com/mapbox/mapbox-gl-js/blob/master/src/style/style.js#L601 |
fixed tests. but this seems odd:
I prefer |
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.
thanks!!
I think we should check if
before
layer exists when move a layerLaunch Checklist