-
Notifications
You must be signed in to change notification settings - Fork 155
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
Suggestions for Url-Api #433
Comments
The entire new My motivation for that refactor was simple - I had one big router and a struct/function with links in one of my app and it became very error-prone, so I tried to find some better patterns. Current So.. current |
I will draft a PR for this later this week. |
If @power-fungus has no objection (or doesn't respond in a few days), could I create the PR instead? I have a few further suggestions They mostly amount to integration with existing The first is to convert The second is to remove all the iteration methods on The third and kind of questionable is to expose the The second and third are afterthoughts, but the first, I think should be implemented, especially as it's a relatively minor change for the API users that adds consistency with the |
@AlterionX Try it and please update also examples to match your changes:
Clean |
Oh boy, that's a bunch. Also, got it. |
Please go ahead with a PR. Unfortunately, the seed-project I was working on has been suspended and brought my interaction with seed to a halt. I have a few comments which may or may not be considered during implementation. The current implementation already allows The notion of the base-path is already present in the current api and my proposal is to embrace the concept for mutable url structs. Maybe the When I worked on this issue, I aimed for a more complete api for routing. In my project, I had to deploy my app at During my work on the url-code, the The features about public-path and web_sys-url independence are not too trivial to implement and I did not find a good solution yet. I did not include |
The path from your
It's shame, I hope it will be resumed 😢 I like you ideas and also it would be nice to see more high-quality Seed apps. |
What is that? It looks interesting |
@power-fungus See #369 (comment) - there is an explanation and examples that exercise it. |
Just note: There is a related issue - #383 |
Just two short points (overall, I'm happy with the Url API and routing facilities of Seed):
Note on 2: it is good that the function doesn't also trigger the subscription, because that leaves it in my hands to decide what to do inside my app. As a user of Seed, I can Another Note on 2: The documentation should give an example of a programmatic redirect, e.g.
|
Ad 1. - It's named Ad 2. - My reasoning - all functions that modifies the url directly in the browser window have prefix Programmatic redirect should be done by: Line 61 in a0e01ae
I plan to add it into seed-rs.org guides. And maybe it's somewhere in the docs already. You can also subscribe to
So I don't have a strong opinion about it - I haven't got problems with
Possible next steps:
|
There's nothing wrong with staying close to the browser specs. That makes it easier for experienced folks to move to Seed because things work as expected. Only thing that tripped me was the term "go" which, due to lack of more details in docs, I interpreted as firing an
Ok, that's definitely possible. You could name it
No, please don't do that, you would be taking away from the flexibility we have now. There are situations where it makes sense to change the URL (in-place or by adding a new history entry) in the browser without going through a full "page changed" scenario inside the app. Good next step IMO:
So generally, leave API as is, there's nothing wrong with being a thin wrapper, and I don't think adding anything on top of what you have will make it better. Only thing that would be convenient to have is automated serialization/deserialization of routes, but that's a luxury feature that almost no one has. Your examples are great, and they do contain the critical pieces. Still, it can be hard for a newcomer to take all that good info in, and find the right example at the right time. With routing, in particular, things seem to have changed over the last versions. One thing that could help is to compile a FAQ that works like this website: http://microjs.com/ i.e. there is a list of the things that people commonly ask how to do them, and then, as an answer, the site shows one small paragraph that explains, and a link to the corresponding example. So, there would be "I need to..." and a choice box. One choice: "redirect to another URL". Answer: "The Seed way to work with the browser URL is to use the URL subscription API (link). All you have to do to redirect to another page is to notify the |
Btw, another way to manually handle link clicks is currently to use preventDefault and preventPropagation on the link in question. Intercepting |
Ok, I agree. I'll come back later to this issue (before Seed 0.8.0 release) and we can discuss better names (here or on the chat).
|
I did a review of the url-api. My motivation is that I did not understand how this module is intended to be used and saw an opportunity to improving discoverability and perceived consistency of the api.
I believe I understand the intention behind the provided functionality. I understand its usecases for routing and I do not want to remove any features from the module.
Name the new parts of the url
The Url struct is not the typical url. It represents more than just the url (it has extra features for routing). All parts of a typical url are already named corretly (path, hash, search). The "Base path" is a concept introduced by the routing-functionaliyt and is implicitly named.
I suggest embracing concept of the base-path. In current terms, it is the parts of the path that are "behind" of the url. The functions
to_base_url
andskip_base_path
hint at that fact.If there is a "base-path", there should also be a name for the rest. I see two possibilities:
path = base-path + head-path
. The namehead_path
is the best name I could came up with, it is to be bikeshed.absolute-path = base-path + path
. This would be a breaking change and is quite disruptive.The following describe suggested changes to functions:
to_base_url
This method clones the url and truncates the path. Suggestions:
&mut self
to avoid cloning inside the library - users can still clone if they like to.next_path_part
Instead of "Advances the internal path iterator", the documentation of this method desccribe somthing along the lines of: "the next part of the url is moved to the base-url section of the path".
return string slices
base_path(&self) -> &[String]
.remaining_path_parts
should behead_path(&self) -> &[String]
(nomut
, return slice instead of vec)documentation
consistent subtitle
URL used for routing can serve as a subtitle for seed's concept of url and could to be communicated more. This highlights that this is not the typical url-struct (just data) and serves the specific purpose. It should also documented that the url-path is split into
const DUMMY_BASE_URL
This is a const to "example.com". This seems a bit odd, currently the url-struct represents relative urls (which is nice). Having this const in the framework does not make much sense.
struct_urls macro seems off
It generates a newtype around a base-url. I understand that the custom methods (like
home()
) can be useful, but I doubt that this is the best abstraction.I suggest removing the
struct_urls!
macro and having the users require to store the base-path inside the model. The functions likehome()
can still be implemented somewere.reorder URL-methods
I had a difficult time understanding the nature of the url-module because the main mehtods for the entry-level user are quite hidden. Is there any possibility to reorder the methods?
path
,search
, ...)go_*
Alternatively, one could extend the struct-level documentation to include examples about the most commonly used functions in simple apps (
path
,next
, ...).The text was updated successfully, but these errors were encountered: