Git Product home page Git Product logo

Comments (5)

solkimicreb avatar solkimicreb commented on May 19, 2024 1

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.

solkimicreb avatar solkimicreb commented on May 19, 2024 1

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.

solkimicreb avatar solkimicreb commented on May 19, 2024

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.

solkimicreb avatar solkimicreb commented on May 19, 2024

Thx for the feedback btw. I plan to do a docs revamp in the future, I will make sure to clarify this. πŸ‘

from framework.

antonioaguilar avatar antonioaguilar commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.