-
Notifications
You must be signed in to change notification settings - Fork 37
Routing #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Routing #2
Conversation
bower.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Version fields in bower.json are redundant at the moment as it only uses git tags to resolve released versions anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bower warns if version in bower.json and tag are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you delete it, then it won't warn at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed version
|
Sorry if it seems I'm being picky about the naming of things :) I just wasn't sure what they meant without having to dig through the code a bit. |
src/Routing/Getter.purs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract function dropHash = replace rgx ""?
|
I'll make specific comments on the individual lines, but what I'll say here is more general. This is going to seem a bit ranty, for which I apologize, but I've been planning to write something like this up for a while. Edit: this has turned into a DSL tutorial, sorry. Take it for what it is - I think this would be a nice way to think about the problem. This library seems like a really good candidate for a "layers of abstraction" approach. I'll explain what I mean by that. The pieces are all there, but I think there may be a better way to arrange them.
In detail:
class (Alternative f) <= Match f where
lit :: String -> f Unit
var :: f String
param :: String -> f String
anyParam :: f (Tuple String String)We can already start writing matching functions without choosing a representation. Laws tell us what these routes mean: data FooBar = Foo String | Bar Number Boolean
route :: forall f. (Match f) => f FooBar
route = Foo <$> (lit "foo" *> var)
<|> Bar <$> (lit "bar" *> (num <$> var)) <*> (bool <$> param "baz")Aside: if you want to be able to generate routes from values as well as parse them, then one nice thing about this approach is that it works in different categories. I think you can just switch
newtype MatchImpl a = MatchImpl (Route -> Either MatchError a)We want to be able to write Then we can write
route = ("foo" </> var) <|> ("bar" </> var <?> "baz")This is probably the least important layer from the point of view of the theory, but quite important when it comes to using the library. The important thing is that we're building a language on top of an existing theory, which provides laws to guide us. Other comments:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to use decodeURIComponent or something similar here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
|
|
Yes, you're probably right, especially if we stay with the parse-from-template approach. I'm just thinking out loud more than anything with this one.
In a particular template, yes, but what if you want to handle two different types of routes? A which you would then be able to postprocess to a more meaningful error message like: |
|
@jdegoes But, personally, I don't see the point:
|
|
@paf31 |
|
Yeah, as I say, just understand my notes as an alternative approach, and to a certain extent, me trying to understand the problem. If everything works as needed, maybe don't worry about it. I put the more important items ( |
|
@paf31 Thank you very much for review! It's very helpful. |
It's a free lesson in how to organize a library from the creator of PureScript. 😃 I think @paf31's suggestions would improve the organization of the library even if they wouldn't add functionality. If you agree, then go ahead and make them, if you don't agree, well we can discuss further on Skype or just merge the PR as-is. |
|
Great! I'll try to try @paf31 approach in different branch and make pr in day or two |
No description provided.