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

Fix MapOptions#style is optional in the Map constructor #4003

Closed
wants to merge 2 commits into from

Conversation

vicb
Copy link
Sponsor Contributor

@vicb vicb commented Apr 15, 2024

See if (options.style) this.setStyle(...); in the constructor

My use case is to use a base layer switcher so I do not want to set a style explicitly when instantiating the map.

Launch Checklist

  • Confirm your changes do not include backports from Mapbox projects (unless with compliant license) - if you are not sure about this, please ask!
  • Briefly describe the changes in this PR.
  • Link to related issues.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Post benchmark scores.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 93.84615% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 86.44%. Comparing base (d76c044) to head (cd6d72e).

Files Patch % Lines
src/ui/map.ts 93.75% 1 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4003      +/-   ##
==========================================
- Coverage   86.64%   86.44%   -0.21%     
==========================================
  Files         242      242              
  Lines       32493    32502       +9     
  Branches     1990     2118     +128     
==========================================
- Hits        28154    28096      -58     
- Misses       3391     3482      +91     
+ Partials      948      924      -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -387,7 +387,8 @@ const defaultOptions = {
crossSourceCollisions: true,
validateStyle: true,
/**Because GL MAX_TEXTURE_SIZE is usually at least 4096px. */
maxCanvasSize: [4096, 4096]
maxCanvasSize: [4096, 4096],
style: '',
Copy link
Member

Choose a reason for hiding this comment

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

If style can be undefined why setting it to an empty sting?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

If style can be undefined

This is an ambiguous statement. options.style can not be set to undefined but the style key can be omitted from options.

Then the reason is

// This type is used inside map since all properties are assigned a default value.
export type CompleteMapOptions = Complete<MapOptions>;

i.e. the value after the default are applied should satisfy StyleSpecification | string

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I'm following...

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

CompleteMapOptions#style is a required key of type string | StyleSpecification.

If the style prop is not set in the options passed to the ctor, it has to be added with a tour satisfying string | StyleSpecification.

Does this make sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you adding style: '' though if you're making it optional above?

Copy link
Member

Choose a reason for hiding this comment

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

The current behavior is that the default style value is undefined, setting it to '' will change the current behavior and has a higher probability of breaking exiting client code than keeping it as before.
Am I missing something?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

setting it to '' will change the current behavior and has a higher probability of breaking exiting client code than keeping it as before.

It all depends what you consider the source of truth. I am definitely a TS developer and consider types the source of truth and I like to use TS strict mode. I you think the average user look at the source code rather than than the TS types, you might be right.

Copy link
Member

Choose a reason for hiding this comment

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

It's not that I think developers look at the code, but if you have something that is working right now, this might break it, changing only the types will make it more correct and might cause a break in the build, but not in run time.
It's a slim chance, but if the purpose of this change is to improve the public facing API types, let's focus on changing the types only at this point and avoid unexpected changes to the "logic".

Not sure I'm successful in passing my point here...

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

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

Can we discuss on slack (victor at suumit.com). I'm busy tonight but should be available tomorrow. Thx.

Copy link
Member

Choose a reason for hiding this comment

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

Are you in the maplibre slack? I can't find you using a simple "victor" search... 😕

See `if (options.style) this.setStyle(...);` in the constructor
@vicb vicb force-pushed the MapOptions/style branch 2 times, most recently from 3ce06f0 to 640a762 Compare April 16, 2024 06:40
@HarelM
Copy link
Member

HarelM commented May 30, 2024

I believe this was addressed by #4151, right?

@HarelM HarelM closed this May 30, 2024
@vicb
Copy link
Sponsor Contributor Author

vicb commented May 30, 2024

You're absolutely right, sorry I forgot to close this one.
Thanks!

@vicb vicb deleted the MapOptions/style branch May 30, 2024 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants