-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add SSR to the multipage example #51
Conversation
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.
The game renders as a constant set of cells but update them once the game loads.
`Transmitter` and `Receiver` always have a `'static` lifetime (?) so can be safely passed as references throughout the applicaiton.
Each `<li>` in the `GameList` (from `GameList::game_li`) should be clickable and trigger a message which can be translated to a `Route::Game`.
Change the "Games" link to navigate to a `GameList`.
Implement `get_game` and get_game_list` in terms of `fetch`.
Clicking a cell triggers a PATCH to the server, the server responds with an updated board state. The board view is replaced on each update.
Using `Uuid` means `Copy` can be derived for structs and enums as well because `Uuid` is `Copy`.
Use the `From` trait to turn a `String` into a `Route` and the `Display` trait to turn a `Route` into a `String`.
`RouteDispatcher::push_state` more closely resembles the underlying browser based implementation which uses `History::push_state_with_url` to add to the history stack.
Pass the initial route to the `App` setup.
b740114
to
fd3b3ff
Compare
I was looking at how you were handling things in the mogwai-realworld project while I was doing this exploration. I landed on not being able to use the same pattern for navigation as you use in nav.rs because I wanted to use the history API rather than "hashchange" events. The history API has a "popstate" event (that I didn't implement, oops) but that only works when going back not when navigating to a new screen. |
Move `view_builder` function from `RouteDispatcher` to `From<Route>` implementation for `ViewBuilder<HtmlElement>`. Remove the `RouteDispatcher` struct.
Or rather, let `Gizmo::from` do it for us.
I've stripped away some of the things you pointed out that didn't make sense any more for the example. I think it's ready for another look! |
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.
LGTM. Are you ready for a merge?
Yep! |
The
RouteDispatcher
is likely overkill for this example (after I paired it down) but it encapsulates the functionality of pushing state into browser history which I think is still useful to do. The SSR parts are cobbled together from some examples but does the job.This has a pile of commits because it started as an experiment for interacting with a server I have defined in a separate repository but once I got SSR working I thought it could be paired down to a useful extension of the multipage example.
Refs #32