Comments (5)
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.
from framework.
One small note:
The nx.component({ template: '' })
snippet won't work. If you would like to pass a template, you must use a component which uses the render
middleware internally or you must add the middleware to the bare component by hand. The following two are equivalent.
nx.components.rendered({ template: ' ' })
.register('my-comp')
nx.component()
.use(nx.middlewares.render({ template: ' ' }))
.register('my-comp')
Alternatively you can use the app
, page
, display
or control
components instead of rendered
as they all use the render
middleware internally (among with many others.)
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
from framework.
All middlewares added with the component.use
method have 3 parameters. The first parameter is the actual DOM element. (The component instance is a Web Component, which is a vanilla DOM element). You are free to use any of the native DOM apis on the element. NX is designed to work with post hooks only, so no native hack or other framework should break it (:
Edit: this is a super simple example
nx.component()
.use((elem, state) => {
elem.addEventListener('click', myHandler)
})
.register('my-comp')
from framework.
Thx for the feedback btw. I plan to do a docs revamp in the future, I will make sure to clarify this.
from framework.
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?
from framework.
Related Issues (20)
- Planned features HOT 2
- Handling model data inside a component HOT 10
- npm install issues
- Bower support + Firefox NX source download bug HOT 12
- Upcoming core rework HOT 3
- Is this project alive? HOT 3
- Why doesn't `exec` return values? HOT 5
- Web components org recommendation list HOT 1
- DOM node attribute changes not caught by handler HOT 3
- [Question] Can this framework be used with a template engine? HOT 3
- [MAJOR BUG] website won't openππ HOT 4
- Surviving contact with jquery and its libraries
- Usage inside meteor (amd/import usage instead of webpack) HOT 1
- Uncaught ReferenceError: module is not defined HOT 2
- history error HOT 3
- 402: Payment required HOT 1
- What is the status of this project? HOT 1
- Add supports for clipboard events. HOT 9
- Hide elements until they are resolved. HOT 8
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 framework.