-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Add support for adding external scripts to document. #300
base: main
Are you sure you want to change the base?
Conversation
This PR adds support for adding external scripts to the document. Not sure if the way that I implemented 'attributes' to the AddScript function is the most convinent. Let me know what solution could fit better. Created tests for AddScript function.
Some observations:
Here's an implementation that takes these into account: |
AddScript guarntees that the script was loaded or returns a error.
I commited a implementation that takes this into account. But I don't have sufficient knowledge of vecty to create a test for timeout exceeded scenario. Not sure how I could mock script has loaded event. I manually tested it with these: |
I had a second idea, what if we leave it up to the end user to decide what happens "onload". Because now In a timeout scenario
// AddScript adds an external script to the document, does not guarantee that the script has been loaded.
// If you want to guarantee that the script has been loaded use `onload`
func AddScript(url string, attributes map[string]interface{}, onload func(jsObject, []jsObject) interface{}) { |
AddScript removes "onload" event listener when the function has executed.
In Go it's not quite common to use "onX" callbacks. This kind of function makes control of user applications harder. The way people usually go about dealing with long lasting functions is just have them block and let the user decide if they want to run them asynchronously like so: go func() {
AddScript("url.com", nil)
onload()
}() This practice is best summarized as: Let users decide if they want concurrent programs or not. Don't use goroutines in user facing code if it can be easily circumvented. That said, I'm not sure what @slimsag has to say about if vecty is the correct place for |
True, it seems like this function is hard to implement in a way that it takes into account all of the factors mentioned. Which is unfortunate because function like I'd love to find a way to implement this function inside |
This PR adds support for adding external scripts to the document.
Not sure if the way that I implemented 'attributes' to the
AddScript
function is the most convenient. Let me know what solutioncould fit better.
Created tests for
AddScript
function