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

Automatically load included plugins #51

Closed
lekoala opened this issue May 29, 2018 · 4 comments
Closed

Automatically load included plugins #51

lekoala opened this issue May 29, 2018 · 4 comments

Comments

@lekoala
Copy link
Contributor

lekoala commented May 29, 2018

Hi again !

Although it's great to be able to load plugins selectively, it would be great to have a bundled versions of filepond that includes all plugins.

Also, it would be wonderful if plugins were able to auto register themselves if they have been loaded before filepond. I'm using standard script tags (so no vue, react or anything) and basically, since the plugin is declared as a global variable, it's just a matter of checking if the variable is defined to register the plugin on load.

@rikschennink
Copy link
Collaborator

I did initially set it up like that. But when using async script tags this gets a lot harder.

Ideally, I would like the plugins and the core to find each other without polluting the global scope, so plugins fire a pluginloaded event and filepond fires a filepondloaded event ( both on the root element of the document ), then plugins can automatically register by listening to the filepondloaded event and filepond can automatically register plugins by listening for pluginloaded events. Problem is, you don't know if all plugins have loaded because there's no information on how many need to register.

So while this works when putting the script tags after the filepond tag it only does when all code is loaded in synchronously.

I'm all ears for a possible solution, but that's the reason why plugins are registered manually because then it doesn't matter and it's up to the dev to make sure everything is loaded before registering.

@lekoala
Copy link
Contributor Author

lekoala commented May 29, 2018

In my setup, I've settled for using defer instead of async for that reason : at least I get a predictable loading order. It's even actually more efficient to do it that way (this article has some great explanations : https://flaviocopes.com/javascript-async-defer/#tldr-tell-me-whats-the-best)

When using defer, plugins will be loaded before and can be discovered easily. In the case of the jQuery plugin, you will have registered anyway a $.fn.filepond namespace, that you can use to declare the plugins as well.

And if everything is bundled together, load order is also predictable.

So, to summarize : with defer or bundles, you will have a predictable load order that removes the necessity to manually registering the plugins.

What do you think?

@rikschennink
Copy link
Collaborator

What a clear and concise article, love it.

I think using defer is a great approach, will see if I can add this in the near future. registerPlugin would still be useful for devs loading async or using the modules ( without global scope pollution ).

@rikschennink rikschennink changed the title provide bundled plugins Automatically load included plugins Jun 6, 2018
@rikschennink
Copy link
Collaborator

Added this to the roadmap so will close for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants