Skip to content
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

Merged
merged 40 commits into from
Oct 23, 2020
Merged

Conversation

bryanjswift
Copy link
Contributor

@bryanjswift bryanjswift commented Oct 17, 2020

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

Copy link
Owner

@schell schell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! I just had a couple comments and a couple questions. Also, I wrote a similar component for the mogwai-realworld demo (WIP) that I think is worth a gander:

  • route.rs
  • nav.rs dispatches Routes
  • lib.rs where view messages from nav.rs are bound to model messages for App in lib.rs

examples/multipage/src/app.rs Outdated Show resolved Hide resolved
examples/multipage/src/lib.rs Outdated Show resolved Hide resolved
examples/multipage/src/main.rs Show resolved Hide resolved
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.
@bryanjswift
Copy link
Contributor Author

This is great! I just had a couple comments and a couple questions. Also, I wrote a similar component for the mogwai-realworld demo (WIP) that I think is worth a gander:

  • route.rs
  • nav.rs dispatches Routes
  • lib.rs where view messages from nav.rs are bound to model messages for App in lib.rs

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.
@bryanjswift
Copy link
Contributor Author

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!

Copy link
Owner

@schell schell left a 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?

@bryanjswift
Copy link
Contributor Author

LGTM. Are you ready for a merge?

Yep!

@schell schell merged commit 9c6b280 into schell:master Oct 23, 2020
@bryanjswift bryanjswift deleted the multipage-ssr branch October 23, 2020 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants