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

add Map#isSourceLoaded #3691 #4033

Merged
merged 3 commits into from
Jan 23, 2017
Merged

add Map#isSourceLoaded #3691 #4033

merged 3 commits into from
Jan 23, 2017

Conversation

stepankuzmin
Copy link
Contributor

Add Map#isSourceLoaded according to #3691

Copy link
Contributor

@anandthakker anandthakker left a 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];
Copy link
Contributor

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;
}
Copy link
Contributor

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 throwing 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.)

isSourceLoaded(id) {
const source = this.style && this.style.sourceCaches[id];
if (source === undefined) {
throw new Error(`There is no source with ID '${id}'`);
Copy link
Contributor

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.

Copy link
Contributor

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.

@anandthakker
Copy link
Contributor

@stepankuzmin Oof, my apologies re: #4033 (review) -- you had it right the first time 😞

@stepankuzmin
Copy link
Contributor Author

No problem, @anandthakker. I've fixed that :)

@anandthakker
Copy link
Contributor

Thanks @stepankuzmin !

@anandthakker anandthakker merged commit 2793b42 into mapbox:master Jan 23, 2017
@mollymerp mollymerp mentioned this pull request Feb 10, 2017
10 tasks
@stepankuzmin stepankuzmin deleted the 3691 branch October 2, 2017 16:28
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.

4 participants