Code Monkey home page Code Monkey logo

Comments (5)

malcolmsparks avatar malcolmsparks commented on September 28, 2024

Hi Ragnar - this is a great feature request.

I hadn't considered this use-case but it's clearly a good thing if bidi continues to find a handler which does match. Obviously there is a determinstic order here, so I think it makes sense that bidi returns the first route that matches, but if there's missing parameters, it shouldn't blow up like it does, but continue seeking a match. Let me think over this for a bit longer and see if a good design occurs to me. I'll leave the issue open.

And please accept my apologies for taking so long to respond.

Regards,

Malcolm

from bidi.

wilkerlucio avatar wilkerlucio commented on September 28, 2024

Hi,

I just got into the same situation, these are my routes in question:

(def routes ["/" {""   :index
                  "v/" {[:source-id] {""              :composition
                                      ["/" :track-id] :composition}}

                  "s/" {[:search] :search-results}}])

The track-id is an optional parameter, Bidi is able to match-route fine for both cases, but leaving the code as is the path-for only works without the :track-id (it's always ignored). By inverting the order I can generate with :track-id but trying otherwise will blow up (like discussed before).

Would be great to have this feature.

from bidi.

isaksky avatar isaksky commented on September 28, 2024

This code looks like it is intended to solve this problem:
https://github.com/juxt/bidi/blame/335cb3165f873e8590199fcc20acb288104fe7ce/src/bidi/bidi.cljc#L451-L453

451 ;; If you have multiple routes which match the same handler, but need to
452 ;; label them so that you can form the correct URI, wrap the handler in
453 ;; a TaggedMatch.

Just adding a wrapper, e.g., (tag :mytag 'handler) in both the routes and path-for just makes it return nil, however. Can you clarify @malcolmsparks ? Is that code related to this problem? If not, are you open for a pull request?

from bidi.

malcolmsparks avatar malcolmsparks commented on September 28, 2024

Actually is should be (tag handler :mytag) - the argument order of the TaggedMatch record was confusing (the tag function was switching the args around). I've cleaned that up in the last commit.

I think this issue, in general, is addressed by the use of tags. If you want the same handler at more than one route, you can use tags to distinguish between them. I'm concerned that an approach which involved path-for continuing it's journey until it had uncovered every possible match would impact performance for everyone.

from bidi.

isaksky avatar isaksky commented on September 28, 2024

Sounds good, thank you!

from bidi.

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.