Skip to content

App start - API update #382

Closed
Closed
@MartinKavik

Description

@MartinKavik

Proposed changes (1st draft):

Replace App::builder with:

App::start("app", init, update, view);
  • "app" implements MountPoint / RootEl.
  • update and view without changes.
  • init example:
fn init(url: Url, &mut impl Orders<Msg>) -> Model {
    orders.subscribe(subs::UrlChanged, Msg::UrlChanged);
    Model::default()
}

New behavior:

  • Seed looks for <base> element in <head> and eventually sets base url for its router according to base's href. (Base for routing #369)
  • Seed tries to hydrate / overtake HTML in its mount point / root element. If it's not possible, fallbacks to render / append. (Mount takeover behavior concerns. #277)
  • You can simulate UrlHandling::PassToRoutes by:
fn init(url: Url, &mut impl Orders<Msg>) -> Model {
    orders.subscribe(subs::UrlChanged, Msg::UrlChanged).notify(subs::UrlChanged(url));
    Model::default()
}

Motivation

  • PubSub API was introduced in this PR. It makes routes, window_events, sink and GMsg redundant. So it's a good time to revisit and improve App builder API.
  • Builder API is too complex:
    • I don't remember all function signatures so I have to often copy-paste them from app_builder example.
    • We need a dedicated example (app_builder) for it to demonstrate all options.
    • I often forget to "register" some functions in the builder and then I'm surprised that my app doesn't work.
    • It's harder to read in docs and maintain.
    • There are very cryptic compiler error messages - e.g. when you forgot to implement Default for your Model (Improve error message when Model doesn't implement Default #376).
    • There are many implicit options, Seed-specific names and calls, probably confusing for beginners - UrlHandling, MountType, Model::default (if it's possible), BeforeMount, AfterMount, sink..
  • I don't know why I should want to use url in BeforeMount.
  • BeforeMount and AfterMount can be confusing - I would think that it means Before mounting to DOM and After mounting to DOM - which is not true because it hasn't been rendered yet. Also it deviates from standard Elm architecture and doesn't make sense in submodules context.

Implementation notes

  • Remove comment at UrlChange - /// - Url change is fired also on application start by default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    API designProposal for a new or updated Seed API.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions