-
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
add Map#isSourceLoaded #3691 #4033
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.
Thanks for the PR @stepankuzmin! Couple of minor comments inline.
* @returns {boolean} A Boolean indicating whether the source is loaded. | ||
*/ | ||
isSourceLoaded(id) { | ||
const source = this.style.sourceCaches[id]; |
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.
Note that it's possible for Map
to be constructed without a style, which would cause this line to blow up. Something like const source = this.style && this.style.sourceCaches[id];
would work.
error: new Error(`There is no source with ID '${id}'`) | ||
}); | ||
return; | ||
} |
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.
While it's true that the contributing guidelines say to use error events, I think throw
ing an error might be more appropriate here, because we know immediately(synchronously) that there's an error.
When, as in this case, synchronous error reporting is possible, I think it's preferable, as it's generally easier to diagnose/fix. (E.g.: because of the return;
, a user of this method might not even notice the error, since something like if (map.isSourceLoaded(id)) { ... }
would still work without blowing up.)
…or instead of firing event mapbox#3691
isSourceLoaded(id) { | ||
const source = this.style && this.style.sourceCaches[id]; | ||
if (source === undefined) { | ||
throw new Error(`There is no source with ID '${id}'`); |
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.
Per #3208, we have a convention that we emit an error
event rather than throw
an 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.
@lucaswoj ah, shoot -- this was a mistake on my part in this comment. I'd seen the guideline in CONTRIBUTING but didn't take it as strict/universal. My bad.
@stepankuzmin Oof, my apologies re: #4033 (review) -- you had it right the first time 😞 |
No problem, @anandthakker. I've fixed that :) |
Thanks @stepankuzmin ! |
Add
Map#isSourceLoaded
according to #3691