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

Refactor RTL plugin loading code #3418

Merged
merged 13 commits into from
Nov 28, 2023
Merged

Refactor RTL plugin loading code #3418

merged 13 commits into from
Nov 28, 2023

Conversation

HarelM
Copy link
Collaborator

@HarelM HarelM commented Nov 28, 2023

Launch Checklist

This is a refactoring of the RTL plugin loading code.
It splits the code into what is done in the worker vs what is done in the main thread (which was a complicated single class).
Moves all the logic into the class, using extending evented in the main thread no notify when the plugin is loaded or the state changes.

This also removes all the callback hell that was in this class which is not a lot more readable.

It changes the setRTLTextPlugin public API and removed the callback from it.

  • 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.
  • Write tests for all new functionality.
  • Document any changes to public APIs.
  • Add an entry to CHANGELOG.md under the ## main section.

@codecov-commenter
Copy link

codecov-commenter commented Nov 28, 2023

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (10af384) 75.50% compared to head (a73802e) 75.52%.
Report is 12 commits behind head on main.

Files Patch % Lines
src/source/rtl_text_plugin_worker.ts 59.09% 9 Missing ⚠️
src/source/worker.ts 35.71% 9 Missing ⚠️
src/data/bucket/symbol_bucket.ts 66.66% 1 Missing ⚠️
src/style/evaluation_parameters.ts 50.00% 1 Missing ⚠️
src/symbol/transform_text.ts 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3418      +/-   ##
==========================================
+ Coverage   75.50%   75.52%   +0.02%     
==========================================
  Files         241      242       +1     
  Lines       19230    19210      -20     
  Branches     4271     4259      -12     
==========================================
- Hits        14520    14509      -11     
+ Misses       4710     4701       -9     

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

@HarelM
Copy link
Collaborator Author

HarelM commented Nov 28, 2023

Man, these render tests are a pain... :-S

dispatcher: Dispatcher = new Dispatcher(getGlobalWorkerPool(), 'rtl-text-plugin-dispacher');
queue: PluginState[] = [];

async _sendPluginStateToWorker() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be private?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if I should start adding private... while I generally agree that this is the right approach, it should probably be a wider usage of these modifiers, so I'm not sure when will be a good time to introduce this...

Copy link
Collaborator

@neodescis neodescis Nov 28, 2023

Choose a reason for hiding this comment

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

Well, the way I look at it is anything that isn't private is technically adding to the API, even if it has an underscore.

Copy link
Collaborator

@neodescis neodescis Nov 28, 2023

Choose a reason for hiding this comment

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

If it makes sense, especially since we're gearing up for 4.x, I'd be happy to go through map.ts and style.ts to mark stuff as private. Maybe some other areas too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree, but there are plugins that uses these underscore methods and the code itself which uses those, so this is more of a convention than an actual way to block usage... IDK...
Also see here:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Was writing while you were, so my message is answering you first and not second.
I would advise to get some feedback from the community around this before doing so - changing stuff to private, using our slack channel.
While I generally agree this is the right solution, I'm not sure what it would solve on one hand, but I know it will cause some pain on the other - so the value here is low I believe.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK, if you don't think it's worth the pain, I'll stop harping, haha

}
}

async _downloadRTLTextPlugin() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here... private?

@@ -320,6 +288,18 @@ export class Style extends Evented {
});
}

_rtlTextPluginStateChange = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Private?

@neodescis
Copy link
Collaborator

This is soooo much better. Thank you for doing this!

@HarelM
Copy link
Collaborator Author

HarelM commented Nov 28, 2023

Yup, it's a lot clearer now which part runs where and what it actually does. Took me a few hours to reverse engineer this... :-/

@HarelM
Copy link
Collaborator Author

HarelM commented Nov 28, 2023

@neodescis can we merge this and decide later on the modifier stuff?

@neodescis
Copy link
Collaborator

@neodescis can we merge this and decide later on the modifier stuff?

Certainly!

@HarelM HarelM merged commit d68b919 into main Nov 28, 2023
14 checks passed
@HarelM HarelM deleted the refactor-rtl-plugin branch November 28, 2023 21:56
@HarelM HarelM mentioned this pull request Nov 28, 2023
7 tasks
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.

3 participants