Reduce boilerplate: allow to define actions with options object #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: this is a suggestion for discussion. :)
While trying to switch uMap to using Leaflet.Toolbar, I found myself with quite a lot of repetitive code, like defining a new class for every action, then giving this new class as parameter to the toolbar.
I think a nice API should be very very simple on the first approach, and then allow more complex needs by more complex calls. And certainly it's often that our actions are only a className, a tooltip and a callback.
So this PR aim to allow creating actions this way:
instead of:
This includes:
Of course, one can still make its own ToolbarAction class and do whatever he wants. My goal here is only to make the library first step much simpler.
Thanks in advance for your feedback! :)