Giter Site home page Giter Site logo

Can I pass a rootNode to `nanohref`? about choo HOT 5 OPEN

m90 avatar m90 commented on June 6, 2024
Can I pass a rootNode to `nanohref`?

from choo.

Comments (5)

m90 avatar m90 commented on June 6, 2024

Hmm, maybe I am missing something here as I tried the following:

I hacked into the choo version in my node_modules adding the root node argument to the nanohref call manually, yet choo somehow still tried to handle clicks outside of the host element.

from choo.

goto-bus-stop avatar goto-bus-stop commented on June 6, 2024

choo hasn't really supported being used in like a "sub application" style but it could be really good for that, so I think any feature that will help it excel in that use case would be really welcome :)

The behaviour in your second post kinda looks like a bug in nanohref to me, this is the code that uses the rootNode value:

https://github.com/choojs/nanohref/blob/80c11c4fdb1c731aad1b94f4c93b0c386b97c69c/index.js#L21-L27

So when you click something, it walks up the tree until it finds either an <a href> or arrives at the rootNode. but if you click a link outside the rootNode, it will still happily find the <a href>.

from choo.

m90 avatar m90 commented on June 6, 2024

Assuming the bug in nanohref is fixed, it should not be too hard to get this into choo itself, but I am really unsure where the option belongs.

A few things that could be done that I'm not a real fan of any yet:

  • Add a new key to the options passed to choo([opts]). I can't even come up with a name for this.
  • Allow a DOM Element to be passed instead of true|false to opts.href which scopes nanohref down to children of that element.
  • Add a second optional argument to app.mount that scopes the router to the given selector. I'm not sure if this actually works because of app.start.

I think option 2 would probably be the least invasive, but it's also not really what I'd call an intuitive API. Ugh.

from choo.

m90 avatar m90 commented on June 6, 2024

Is there any input on this one as well as choojs/nanohref#13 - I'd still love to implement this in one way or the other as it's a hard requirement of what I'm working on right now.

from choo.

blahah avatar blahah commented on June 6, 2024

You can compose the dependencies quite simply to achieve this. See for example: https://github.com/graforlock/choo-detached

from choo.

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.