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

Plugin definitive guide #1624

Merged
merged 6 commits into from
Jan 9, 2022
Merged

Plugin definitive guide #1624

merged 6 commits into from
Jan 9, 2022

Conversation

TrySound
Copy link
Member

@TrySound TrySound commented Dec 6, 2021

This is just initial thoughts. Feel free to suggest any changes.

Here are described only the new visitor plugins api. Old "full", "perItem", "perItemReverse" will be removed in v3. Old JSAPI class on every node will be also removed so nodes could be plain objects.

This is just initial thoughts. Feel free to suggest any changes.
@glennosss
Copy link

Hi TrySound - I'm not sure I'd be in such a rush to remove 'full'. By removing 'full' you'll just get people who were using 'full' (like me) using the 'visitor' plugin, but never returning a visitor. In order to replace the 'ast' like you could with a plugin type of 'full', you'll get people (like me) replacing all the properties on the old ast object. Completely possible to use the 'visitor' plugin type to do these things, just messier.

Example usecase: https://github.com/glennosss/svgo-autocrop/blob/master/lib/AutocropUtils.js

@TrySound
Copy link
Member Author

TrySound commented Dec 8, 2021

Hi. I understand your usecase. Though the point of new plugin api is to cover all possible use cases and remove the necessity to choose.

Your case is easy to solve as well. Workers may accept root children or even root svg element. And you just need to assign new children to root.children. This fits into idea that ast is just mutable object.

@glennosss
Copy link

Thanks TrySound - updated to 'visitor' plugin - https://github.com/glennosss/svgo-autocrop/blob/master/index.js

@TrySound TrySound marked this pull request as ready for review January 9, 2022 11:26
@TrySound TrySound merged commit bbc6bac into main Jan 9, 2022
@TrySound TrySound deleted the plugins-docs branch January 9, 2022 11:27
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.

2 participants