Comments (3)
Hi @newlix -- I unfortunately don't have time to dig into the specifics of that library right now, but I assume you're referencing this example:
// Dropzone class:
var myDropzone = new Dropzone("div#myId", { url: "/file/post"});
i.e., you're wondering what you would pass in as div#myId
in the case of an element rendered by Vecty. Given that is the case, the way you would do that would be to assign an Id
to your element in Vecty. e.g.:
func (m *MyComponent) Render() *vecty.HTML {
return elem.Div(
prop.ID("myId"),
)
}
Unfortunately, there isn't yet a way for you to be informed via Vecty that "your element has been created" for you to actually instantiate Dropzone
in the example code above. This is due to issue #75
A workaround until that issue is fixed would be something like e.g. querying the DOM constantly until that element appeared, then instantiating Dropzone
.
from vecty.
Hi, thanks for your suggestion.
I did solve the problem. I was wondering why I couldn't get the dom element after vecty.RenderBody was called. After reading the RenderBody source code, I found that body would only be rendered after the doc is ready.
// RenderBody renders the given component as the document body. The given
// Component's Render method must return a "body" element.
func RenderBody(body Component) {
nextRender := doRender(body)
if nextRender.tag != "body" {
panic(fmt.Sprintf("vecty: RenderBody expected Component.Render to return a body tag, found %q", nextRender.tag))
}
doRestore(nil, body, nil, nextRender)
// TODO: doRestore skip == true here probably implies a user code bug
doc := js.Global.Get("document")
if doc.Get("readyState").String() == "loading" {
doc.Call("addEventListener", "DOMContentLoaded", func() { // avoid duplicate body
doc.Set("body", nextRender.Node)
})
return
}
doc.Set("body", nextRender.Node)
}
I found a easier way to make sure that the client.js generated by gopherjs will not run until after the page has loaded by using the HTML <script> defer Attribute (http://www.w3schools.com/TAgs/att_script_defer.asp).
//index.html
...
<script src="client.js" defer></script>
I think it would be useful that the default page automatically generated by gopherjs serve could generate the script tag with the derfer
attribute too.
from vecty.
Given that #75 has been fixed, you can now make your component implement the vecty.Mounter
interface. That is:
func (m *MyComponent) Render() *vecty.HTML {
return elem.Div(
prop.ID("myId"),
)
}
// Mount implements the vecty.Mounter interface.
func (m *MyComponent) Mount() {
// DOM element "myId" has now been created and you can start manipulating it with DOM API.
}
Likewise, also see the vecty.Unmounter
interface.
If there is a more specific question, or if you have any thoughts, feel free to let me know or create a new issue :)
from vecty.
Related Issues (20)
- Add a basic example on usage HOT 5
- allow global panic handler HOT 2
- removeChild crashes if parent node is nil HOT 1
- [feature request] static HTML/CSS components HOT 6
- Examples go.mod file conflict HOT 1
- Add snake videogame example. HOT 4
- question: What is this prop vs. state idea HOT 3
- Instrumenting panic messages HOT 8
- question: initializing rendered HTML nodes via javascript HOT 4
- Porting gopherjs js calls to use with vecty HOT 2
- Document the availability of vecty project template generator HOT 1
- Return type of If function
- prop.Value("") does not produce the correct html on first render
- Vecty needs an official website HOT 10
- The slack invite link in readme is broken
- vecty docs HOT 1
- How to update a rendered element? HOT 10
- Failed Running The Example HOT 8
- Todo MVC example has misleading usage of p.Items HOT 2
- Rerendering List Replaces First ListItem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vecty.