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

More plugin Shapes #3497

Merged
merged 3 commits into from
May 11, 2023
Merged

More plugin Shapes #3497

merged 3 commits into from
May 11, 2023

Conversation

ekwoka
Copy link
Contributor

@ekwoka ekwoka commented Mar 31, 2023

This change allows Alpine.plugin to accept infinitely nested arrays of plugin callbacks as well as just multiple arguments.

So while before you'd have to do

Alpine.plugin(collapse)
Alpine.plugin(morph)
Alpine.plugin(ui)

Now you could do

Alpine.plugin(collapse, morph, ui)

// or...

Alpine.plugin([collapse, morph, ui])

// or even...
Alpine.plugin(collapse, [morph, [ui]])

In production apps, I find it is helpful to have Alpine data and stores and such in their own files as plugin functions, as opposed to needing to bring them all together and call Alpine.data or Alpine.store on them collectively. A file can handle any stores or data it needs, and label itself, etc.

then when they are imported to be added, needing to ensure the list is flat and looping ourselves. It's relatively low cost to use this method to just allow these options out of the box to let people build their app modularly.

All the modules could import Alpine directly, but I think this is a good way as well.

@calebporzio
Copy link
Collaborator

I agree there should be a way to register multiple plugins using a single Alpine.plugin() call.

I don't, however, want to allow all those shapes in case we want to add second or third params to do something else down the road.

I refactored to only allow either an array of plugins or a single plugin. Thanks!

@calebporzio calebporzio merged commit 7201ff1 into alpinejs:main May 11, 2023
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.

None yet

2 participants