Comments (5)
thanks so much for chatting about this!
from routes.
Hello! Thank you for taking a look at this library!
is the current behavior expected? if not, i think the issue is here:
The current behavior is indeed expect (I admit I haven't done the best job at documenting this 😅). When writing the route matching my thinking was that having the same node act as both an exact match, and a capture (like in your example) would be a little confusing, and make it harder to predict how route matching is supposed to work. The current implementation seems easier to reason about for me personally. Performance wasn't the reason for making this choice, but reducing some backtracking does help I guess :)
I have thought about being stricter at times by not allowing patterns where an exact match and a capture happens on the same node at-all. That reduces some flexibility, but it makes things a little easier to understand as users if there's an actual error/feedback at the time of creating the router, instead of silently missing a route like you see here.
from routes.
Excellent writeup about elm/url
! While not quite the same, the first version of routes (https://github.com/anuragsoni/routes/blob/0.1.0/src/routes.ml) was closer in spirit to elm/url
's parser than where I've ended up today!
from routes.
Thanks for the quick response! Your answer makes sense to me. I agree it’s easier to reason about.
I have thought about being stricter at times by not allowing patterns where an exact match and a capture happens on the same node at-all.
How would this be achieved? Would add return an option/result?
Edit: Oh i guess ocaml has runtime errors! so would you just throw? elm doesn’t so i had not even considered that as an option.
from routes.
How would this be achieved? Would add return an option/result?
Since we can perform this check at the time we create a router instance, and when adding a new route to an existing router, we can have these functions return a result type that make it clear that this operation can result in errors. Adding an exception raising variant of these functions could also be nice in-case people would like to fail with an exception early on in the app lifecycle.
from routes.
Related Issues (20)
- API for catch all route HOT 8
- Support additonal methods `Other(string) HOT 3
- Forward additional custom data to handlers HOT 9
- fix travis build with 4.08 HOT 2
- Ability to get human readable name for route HOT 2
- Expose an add method which allows a user to add a new route to the router trie HOT 2
- Add human readable route patterns
- Use a less restrictive ocaml/dune constraint
- Keep the old readme example in examples/ HOT 2
- Optional patterns at the end of path HOT 3
- Pattern with 2+ options where path is discarded HOT 5
- Group targets with different signature under same type HOT 8
- Fix mdx tests on windows HOT 1
- Update or remove the bucklescript packaging setup
- Versions 0.9.0 and 0.9.1 don't appear in opam packages HOT 3
- Compiler error when combining custom pattern with "variable pattern" (e.g. str) HOT 2
- Add an Opium example once more? HOT 4
- Trailing slashes example in the README HOT 1
- Good way to match on methods and paths?
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 routes.