-
Notifications
You must be signed in to change notification settings - Fork 33
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
Reference to element in the component #14
Comments
All middlewares added with the Edit: this is a super simple example nx.component()
.use((elem, state) => {
elem.addEventListener('click', myHandler)
})
.register('my-comp') |
Thx for the feedback btw. I plan to do a docs revamp in the future, I will make sure to clarify this. 👍 |
Thanks for example. Could I just then wrap the element using jQuery nx.component({ template: '<div id="container">hello there!</div>'})
.use((elem, state) => {
let el = $(elem);
el.show();
el('#container').addClass('change-color');
elem.addEventListener('click', myHandler)
})
.register('my-comp') will this example work? |
Sure, here is a copy-paste example. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://www.nx-framework.com/downloads/nx-beta.2.0.0.js"></script>
<script>
nx.components.app()
.use((elem, state) => {
let el = $(elem)
el.show()
el.find('#container').addClass('change-color')
})
.register('my-app')
</script>
<my-app>
<div id="container">hello there!</div>
</my-app> Just copy it into an empty HTML file and open it with your preferred browser. I never used jQuery, but I am pretty sure that you can combine it howerver you want with NX without issues. |
One small note: The nx.components.rendered({ template: ' ' })
.register('my-comp') nx.component()
.use(nx.middlewares.render({ template: ' ' }))
.register('my-comp') Alternatively you can use the I hope this makes sense, it might take some time to get used to this. To get some idea about the components you could check the source of some here. They are all a few lines long only. Edit: you can find the docs for components here |
I was just reading about NX - found it an interesting framework. However, from the docs, I could not find out if it's possible to get a reference for the DOM element the component is managing, for example if I want to do specific changes to the DOM (outside the framework) using jQuery. Could you provide an example of using NX along side of jQuery?
The text was updated successfully, but these errors were encountered: