cyclejs-community / cyclic-router

Router Driver built for Cycle.js
MIT License
109 stars 25 forks source link

feat(makeRouterDriver): Require injection of route matching algorithm #123

Closed ntilwalli closed 7 years ago

ntilwalli commented 7 years ago

In some cases I've wanted to inject my own matching algorithm (example: I've created a custom reg-ex matcher for routes) and not use switch-path. This PR allows users to inject when they define their routes. I'm posting it for discussion and possibly for merge.

TylorS commented 7 years ago

Cool, thanks for this. I'll merge this as I don't see any issues with this if you still want to after me asking a question. Are there alternatives to switch-path you see worth investigating first?

I'm not set on switch-path being what is used, just what I built this with via familiarity at the time

TylorS commented 7 years ago

Another question, what do you think about having a "bring your own route matcher" only?

makeRouterDriver(history, matchFn)
ntilwalli commented 7 years ago

I haven't investigated alternatives to switch-patch other than writing my own since my needs were pretty basic (reg-ex and array priority ordering for routes) so my function was pretty trivial to write. It does look like solid alternatives exist like https://github.com/rcs/route-parser Also, I liked injection (as opposed to investigating/proposing an alternative) since it's an easy first step which could lead to a switch without getting into the broad discussion of pros and cons of different libs.

I like the idea of "bring your own route matcher" only. If you're cool with it, we can discuss and I can change the PR accordingly.

TylorS commented 7 years ago

There is also https://github.com/cerebral/url-mapper for instance.

I think I'm in favor of BYOM (bring your own matcher). If we can get semi decent typings I'm sold. But to be honest, cyclic-router typings suck currently anyways so that shouldn't be too hard.

ntilwalli commented 7 years ago

I've posted an update, critiques welcome.

TylorS commented 7 years ago

Thanks @ntilwalli great PR LGTM

TylorS commented 7 years ago

Published as v3.0.0