chinedufn / percy

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
https://chinedufn.github.io/percy/
Apache License 2.0
2.26k stars 84 forks source link

Add push and pop history to isomorphic app example #99

Open luover opened 5 years ago

luover commented 5 years ago

Percy looks nice, when I learn it, I find the router impl no use the Web history or hash API, I know the JS front framework all use it impl router for building SPA(single page application). There are some rust frameworks also use it.

Does Percy has some docs about building SPA ?

cryptoquick commented 5 years ago

I highly recommend investigating Percy for full stack Rust web apps, but yes, the router does not yet implement history push. That said, it has all the foundation for that. @chinedufn recently worked on a rewrite of the router, and I've found it to be quite robust so far, but that's only in its state management (presentation of views), and not in detection or writing of the URL.

As far as a comparison to the Yew-based examples you listed, Percy is actually not tied to the Elm architecture, in fact, it's completely independent of that project; it feels much more like React and Redux, if you're more familiar with those.

Percy still has some rough edges, I will not lie, history API being one of them, but we're working on it quite actively, and building real applications with it.

chinedufn commented 5 years ago

@luover thanks for opening this issue!

I've renamed it to reflect how I'm interpreting the issue - but please let me know if I'm off the mark.

I've gone into detail below, but the short answer is that this will be supported very soon.


Percy's router-rs will never on its own know about browsers or support push/pop state since it is designed to work in browsers, on the server, or anywhere else that someone wants to use it.


However, this doesn't in any way mean that we can't use the history API.


The plan is to have something like this:

router.set_after_route(|route| {
  // Do whatever you want after a route is visited.
))

And then your client crate can pass in a function that the app crate will use when calling set_after_route.

But your server crate won't pass in anything. So we maintain our goal of having the app crate not know anything about it's environment.


As @cryptoquick mentions we're using Percy's libraries to build real things and ironing out the rough edges as we go. This allows us to choose the minimal solution that solves our real problems instead of coming up with grandiose and complex APIs that aren't actually very good.

So .. with that in mind .. I'm actually using the new router this week for a site that I'm working on .. so while doing that I'll submit some patches to Percy that demonstrate how to use push/popstate.


So these router problems should be fixed very soon!

luover commented 5 years ago

@cryptoquick @chinedufn ah, cool, thanks for your explanation. It is nice Percy will support SPA.

chinedufn commented 5 years ago

Added to the example in #100

If y'all can take a quick look we'll get it merged!

aubaugh commented 5 years ago

I've been experiencing an issue with the push and pop history. When I run the isomorphic example and click "Contributors", I'm able to use the back button.

The issue arises when I try to go back more than once. For example, if after starting the server I click "Contributors" and then click "Isomorphic Web App", I'm able to go back once to the contributors page, but clicking the back button more doesn't change the route. Am I missing something?

chinedufn commented 5 years ago

Hmm I am seeing this as well - must be something with how we're doing it - re-opening this issue