@@ -346,13 +346,13 @@ impl InitAPIData for UndefinedInitAPI {
346346 }
347347}
348348
349- /// Used to create and store initial app configuration, ie items passed by the app creator
349+ /// Used to create and store initial app configuration, ie items passed by the app creator.
350350pub struct Builder < Ms : ' static , Mdl : ' static , ElC : View < Ms > , GMs , InitAPIType > {
351351 update : UpdateFn < Ms , Mdl , ElC , GMs > ,
352352 view : ViewFn < Mdl , ElC > ,
353353
354354 routes : Option < RoutesFn < Ms > > ,
355- window_events : Option < WindowEvents < Ms , Mdl > > ,
355+ window_events : Option < WindowEventsFn < Ms , Mdl > > ,
356356 sink : Option < SinkFn < Ms , Mdl , ElC , GMs > > ,
357357
358358 // TODO: Remove when removing legacy init fields.
@@ -443,6 +443,19 @@ impl<
443443 }
444444 }
445445
446+ /// Select HTML element where the app will be mounted and how it'll be mounted.
447+ ///
448+ /// See `BeforeMount::mount_point` and `BeforeMount::mount_type` docs for more info.
449+ ///
450+ /// # Example
451+ ///
452+ /// ```rust,no_run
453+ ///fn before_mount(_url: Url) -> BeforeMount {
454+ /// BeforeMount::new()
455+ /// .mount_point("main")
456+ /// .mount_type(MountType::Takeover)
457+ ///}
458+ /// ```
446459 pub fn before_mount (
447460 self ,
448461 before_mount : impl FnOnce ( routing:: Url ) -> BeforeMount + ' static ,
@@ -459,10 +472,22 @@ impl<
459472 }
460473 }
461474
462- pub fn after_mount < NewIAM : ' static + IntoAfterMount < Ms , Mdl , ElC , GMs > > (
475+ /// You can create your `Model` and handle initial URL in this method.
476+ ///
477+ /// See `AfterMount::url_handling` for more info about initial URL handling.
478+ ///
479+ /// # Example
480+ ///
481+ /// ```rust,no_run
482+ ///fn after_mount(_url: Url, _orders: &mut impl Orders<Msg, GMsg>) -> AfterMount<Model> {
483+ /// let model = Model { clicks: 0 };
484+ /// AfterMount::new(model).url_handling(UrlHandling::None)
485+ ///}
486+ /// ```
487+ pub fn after_mount < AM : ' static + IntoAfterMount < Ms , Mdl , ElC , GMs > > (
463488 self ,
464- after_mount : NewIAM ,
465- ) -> Builder < Ms , Mdl , ElC , GMs , BeforeAfterInitAPI < NewIAM > > {
489+ after_mount : AM ,
490+ ) -> Builder < Ms , Mdl , ElC , GMs , BeforeAfterInitAPI < AM > > {
466491 Builder {
467492 update : self . update ,
468493 view : self . view ,
@@ -476,13 +501,34 @@ impl<
476501 }
477502
478503 /// Registers a function which maps URLs to messages.
504+ ///
505+ /// When you return `None`, Seed doesn't call your `update` function
506+ /// and also doesn't push the new route or prevent page refresh.
507+ /// It's useful if the user clicked on a link and Seed shouldn't intercept it,
508+ /// because it's e.g. a download link.
509+ ///
510+ /// # Example
511+ ///
512+ /// ```rust,no_run
513+ ///fn routes(url: Url) -> Option<Msg> {
514+ /// Some(Msg::UrlChanged(url))
515+ ///}
516+ /// ```
479517 pub fn routes ( mut self , routes : RoutesFn < Ms > ) -> Self {
480518 self . routes = Some ( routes) ;
481519 self
482520 }
483521
484522 /// Registers a function which decides how window events will be handled.
485- pub fn window_events ( mut self , window_events : WindowEvents < Ms , Mdl > ) -> Self {
523+ ///
524+ /// # Example
525+ ///
526+ /// ```rust,no_run
527+ ///fn window_events(_model: &Model) -> Vec<Listener<Msg>> {
528+ /// vec![keyboard_ev(Ev::KeyDown, Msg::KeyPressed)]
529+ ///}
530+ /// ```
531+ pub fn window_events ( mut self , window_events : WindowEventsFn < Ms , Mdl > ) -> Self {
486532 self . window_events = Some ( window_events) ;
487533 self
488534 }
@@ -492,6 +538,16 @@ impl<
492538 /// The sink function is a function which can update the model based
493539 /// on global messages. Consider to use a sink function when a
494540 /// submodule needs to trigger changes in other modules.
541+ ///
542+ /// # Example
543+ ///
544+ /// ```rust,no_run
545+ ///fn sink(g_msg: GMsg, _model: &mut Model, _orders: &mut impl Orders<Msg, GMsg>) {
546+ /// match g_msg {
547+ /// GMsg::SayHello => log!("Hello!"),
548+ /// }
549+ ///}
550+ /// ```
495551 pub fn sink ( mut self , sink : SinkFn < Ms , Mdl , ElC , GMs > ) -> Self {
496552 self . sink = Some ( sink) ;
497553 self
@@ -506,7 +562,7 @@ impl<
506562 InitAPIType : InitAPI < Ms , Mdl , ElC , GMs , Builder = Self > ,
507563 > Builder < Ms , Mdl , ElC , GMs , InitAPIType >
508564{
509- /// Build and run the app.
565+ /// Build, mount and start the app.
510566 pub fn build_and_start ( self ) -> App < Ms , Mdl , ElC , GMs > {
511567 InitAPIType :: build ( self ) . run ( )
512568 }
0 commit comments