GithubHelp home page GithubHelp logo

Comments (36)

fundon avatar fundon commented on May 8, 2024

Maybe need a recursion function likes printTree.

from echo.

vishr avatar vishr commented on May 8, 2024

This test doesn't do much, I am working on to add conflicting routes and priority order to get picked up - it's not done yet. I am not even sure if that would be possible without giving up on the performance of the router. #16

from echo.

fundon avatar fundon commented on May 8, 2024

I'm looking forward. πŸ‘

from echo.

fundon avatar fundon commented on May 8, 2024

Do you have plain to fix this?

from echo.

vishr avatar vishr commented on May 8, 2024

Deferred it until few more releases - it's getting complicated.

from echo.

fundon avatar fundon commented on May 8, 2024

Okay, I also try to fix this in my Node version.
There are some cases http://guides.rubyonrails.org/routing.html.
I think we should support them.

from echo.

vishr avatar vishr commented on May 8, 2024

Sure, thanks.

from echo.

fundon avatar fundon commented on May 8, 2024

I think we can convert any :param to :$1 first, below like this:

/photos/:id => /photos/:$1
// alias = ['id']
/photos/:pid/users/:id => /photos/:$1/users/:$2
// alias = ['pid', 'id']

Convert the original path to format path and store the param keys.

from echo.

vishr avatar vishr commented on May 8, 2024

@fundon This is an interesting point, I never noticed it. I will implement it at next opportunity.

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr I implement a version, and haven't been optimized, so currently it's very slower.

See

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr I refactor the add(), insert() and find() methods.
See

Convert paths to special format.

/:username/:repo/issues/:id => /:$0/:$1/issues/:$2

e.g:

  • /users/:id => /users/:$0
  • /users/:userId/photos/:id => /users/:$0/photos/:$1
  • /users/:uid/books/:bid => /users/:$0/books/:$

Note Make sure the param node append to the end of the edges.

Improve performance.

I found the has key is unused in find method.

find(method, path)

steps:

  1. search snode
  2. search pnode
  3. search cnode

Maybe I can submit a PR. hah

Example:

'/geocoder'
'/geocoder/new'
'/geocoder/edit'
'/geocoder/edit/email'
'/geocoder/edit/:item'
'/geocoder/any*'
'/geocoder/:action'
└── /geocoder has=1 h=function edges=1
    └── / has=0 h=null edges=4
        β”œβ”€β”€ edit has=1 h=function edges=1
        β”‚   └── / has=0 h=null edges=2
        β”‚       β”œβ”€β”€ email has=1 h=function edges=0
        β”‚       └── :$0 has=0 h=function edges=0
        β”œβ”€β”€ new has=1 h=function edges=0
        β”œβ”€β”€ any has=3 h=null edges=1
        β”‚   └── * has=0 h=function edges=0
        └── :$0 has=0 h=function edges=0

from echo.

vishr avatar vishr commented on May 8, 2024

@fundon Great!
Has property gives us node information without looking up into findEdge function. Are you talking about improvement in the mentioned cases or in general - the current implementation of the router?

Also can you elaborate on what all features you have implemented so far in your router?

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr

Implemented features:

  • Convert param key to special key, likes: /:username/:repo/issues/:id => /:$0/:$1/issues/:$2
  • named param multi aliases, likes: /users/:id , /users/:userId/photos/:id => /users/:$0, /users/:$0/photos/:$1

Full cases https://github.com/trekjs/router/blob/master/test/router.test.js

from echo.

vishr avatar vishr commented on May 8, 2024

@fundon Excellent, I never realized it was just a step away. I would like to incorporate these changes into the router - I already did some. How do you compare your router to other nodejs routers? Have you done any comparison?

from echo.

fundon avatar fundon commented on May 8, 2024

Use GitHub API routes, compare with below:

  • path-to-regexp
  • route-recognizer
  • route-trie
  • routington

https://github.com/trekjs/router/blob/master/benchmarks/index.js

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr See this https://travis-ci.org/trekjs/router#L710

from echo.

vishr avatar vishr commented on May 8, 2024

Cool, you should publish your results in nodejs forum, https://www.reddit.com/r/node etc.

from echo.

fundon avatar fundon commented on May 8, 2024

Yes, I should. haha
Looking forward to your implementation in Go.

from echo.

fundon avatar fundon commented on May 8, 2024

BTW, I do not use has key in find method, maybe it is not needed。

from echo.

vishr avatar vishr commented on May 8, 2024

Yup, I am gonna take some time and refactor the router based on our discussion - that will cover the cleanup and other goodies ;)

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr I fixed a bug.

You can see this change via: https://github.com/trekjs/router/compare/d702c01826771302156a5e949bdc66a75992d431...master?diff=unified&name=master

from echo.

vishr avatar vishr commented on May 8, 2024

#16

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr

The bug is below:

Bug:

/users/:id
/users/:id/edit

r.find('/users') // will match `/users/:id`.

The right behavior is not found.
It's fixed in my latest Node.js version.

from echo.

vishr avatar vishr commented on May 8, 2024

I will look into it. Can you try the below routes?

/users/new
/users/:id

Find /users/nnn

from echo.

fundon avatar fundon commented on May 8, 2024

I did not try that.

from echo.

vishr avatar vishr commented on May 8, 2024

Wouldn't it go to new? as n comes first in the search?

from echo.

fundon avatar fundon commented on May 8, 2024

Should match /users/:id.

from echo.

vishr avatar vishr commented on May 8, 2024

@fundon I tried below code, it returns empty.

var Router = require('trek-router');

r = new Router()

// static route
r.add('GET', '/users/new', {});
// param route
r.add('GET', '/users/:id', {});
// catch-all route
r.add('GET', '/books/*', {});

result = r.find('GET', '/users/nnn')
console.log(result)

from echo.

fundon avatar fundon commented on May 8, 2024

Yes, it's a bug. I'm thinking. How to fix this?

from echo.

vishr avatar vishr commented on May 8, 2024

I need some time to fix it.

from echo.

fundon avatar fundon commented on May 8, 2024

Me too. Good catch! Hah

from echo.

fundon avatar fundon commented on May 8, 2024

Wow, nice! πŸ‘

There is not goto statement in JavaScript. 😭 hah

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr I tried the latest Echo, I found a small bug.

/users
/users/new
/users/:id/echo
/users/*

Find /users/echo/hello => empty // right, return /users/*
Find /users/echo => empty // right, return /users/*

from echo.

vishr avatar vishr commented on May 8, 2024

@fundon How have you implemented param name alias?
Thanks

from echo.

fundon avatar fundon commented on May 8, 2024

@vishr Yes, I implemented it.

https://github.com/trekjs/router/blob/master/src/router.js#L87-L121

Examples:

/users/:id/echo => /users/:/echo ['id']
/users/:user_id/photos/:id => /users/:/photos/: ['user_id', 'id']

from echo.

vishr avatar vishr commented on May 8, 2024

Thanks @fundon

from echo.

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.