@@ -32,8 +32,7 @@ const ABOUT: &str = "about";
3232fn init ( url : Url , orders : & mut impl Orders < Msg > ) -> Model {
3333 orders
3434 . subscribe ( Msg :: UrlChanged )
35- . stream ( streams:: window_event ( Ev :: Scroll , |_| Msg :: Scrolled ) )
36- . send_msg ( Msg :: UpdatePageTitle ) ;
35+ . stream ( streams:: window_event ( Ev :: Scroll , |_| Msg :: Scrolled ) ) ;
3736
3837 Model {
3938 base_url : url. to_base_url ( ) ,
@@ -93,11 +92,13 @@ pub enum Page {
9392
9493impl Page {
9594 pub fn init ( mut url : Url ) -> Self {
96- match url. remaining_path_parts ( ) . as_slice ( ) {
97- [ ] => Self :: Home ,
98- [ ABOUT ] => Self :: About ,
99- _ => Self :: NotFound ,
100- }
95+ let ( page, title) = match url. remaining_path_parts ( ) . as_slice ( ) {
96+ [ ] => ( Self :: Home , TITLE_SUFFIX . to_owned ( ) ) ,
97+ [ ABOUT ] => ( Self :: About , format ! ( "About - {}" , TITLE_SUFFIX ) ) ,
98+ _ => ( Self :: NotFound , format ! ( "404 - {}" , TITLE_SUFFIX ) ) ,
99+ } ;
100+ document ( ) . set_title ( & title) ;
101+ page
101102 }
102103}
103104
@@ -121,26 +122,16 @@ impl<'a> Urls<'a> {
121122
122123pub enum Msg {
123124 UrlChanged ( subs:: UrlChanged ) ,
124- UpdatePageTitle ,
125125 ScrollToTop ,
126126 Scrolled ,
127127 ToggleMenu ,
128128 HideMenu ,
129129}
130130
131- pub fn update ( msg : Msg , model : & mut Model , orders : & mut impl Orders < Msg > ) {
131+ pub fn update ( msg : Msg , model : & mut Model , _ : & mut impl Orders < Msg > ) {
132132 match msg {
133133 Msg :: UrlChanged ( subs:: UrlChanged ( url) ) => {
134134 model. page = Page :: init ( url) ;
135- orders. send_msg ( Msg :: UpdatePageTitle ) ;
136- } ,
137- Msg :: UpdatePageTitle => {
138- let title = match model. page {
139- Page :: Home => TITLE_SUFFIX . to_owned ( ) ,
140- Page :: About => format ! ( "About - {}" , TITLE_SUFFIX ) ,
141- Page :: NotFound => format ! ( "404 - {}" , TITLE_SUFFIX ) ,
142- } ;
143- document ( ) . set_title ( & title) ;
144135 } ,
145136 Msg :: ScrollToTop => window ( ) . scroll_to_with_scroll_to_options (
146137 web_sys:: ScrollToOptions :: new ( ) . top ( 0. ) ,
0 commit comments