-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow fetching plugins from URL #1065
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really good stuff! A handful of small changes/thoughts, and one larger one which is really a comment about register_custom_element
and does it belong in the Plugin class at all...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coolio!
|
||
Now, if you go to `http://localhost:8000` you should see the text "Hello World" on the page. | ||
|
||
Writing plugins in Python is an excellent way if you want to use PyScript's API's. However, if you want to write plugins in Javascript, you can do that too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to use
if you want to learn how to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I need to reword this, what i was trying to say was something along the lines of: "You can do stuff in python using pyscripts apis. But if you are comfortable using javascript you can do that to"
Hi @FabioRosado! Let me know if there's anything I can help with on this PR - I think it's swell and an awesome feature to add. 😃 If the only blocker is the Docs thought, we could wait for that to be a separate PR. |
Hey Jeff, just fixed the merge conflicts, yeah let's do the docs as a separate PR 😄 I'll try to knock it off over the weekend if I get the time thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to took me awhile to get back around to this - thanks for all the adjustments and clarifications! We'll tackle the additional Plugin tutorial as a thought for the future.
LGTM!
I didnt have time to write the docs yet but it's on my list 😄 thank you for the approval |
This PR adds the possibility to fetch javascript plugins from an URL and import it as a module.
As part of this, I reworked the
robustFetch
since I realised thatfetch
will throw aTypeError
when trying to fetch from bad URLs likehttp://blah.blah
and don't return a response. Robust fetch now throws a fetch error iffetch
throws theTypeError
.It also killed the old
handleFetchError
since the error message is now being thrown in therobustFetch
.FetchErrors will now inherit from UserError, which will create the banner for us, so we don't have to do things like:
Plugins
new method created
fetchUserPlugins
which loops over the plugins list and calls eitherfetchJSPlugin
orfetchPythonPlugin
. Currently we are looking at the file extension in the url and calling the right fetch method, otherwise we will throw an exception.For the JS plugins, they will only use the
afterStartup
lifecycle, which is probably fine. I've also added try/catch in the plugin manager, because my hello world plugin was failing withafterSetup is not a function
unless I created a plugin that had all the Plugin methods but nothing in there.We can't import the base Plugin class from pyscript because when we import the module we can't access the
pyscript/plugin
module.There's a lot of rough edges but maybe it's okay for the first pass.
TODO
A few things still need to do: