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

App start - API update #382

Closed
MartinKavik opened this issue Mar 8, 2020 · 2 comments
Closed

App start - API update #382

MartinKavik opened this issue Mar 8, 2020 · 2 comments
Labels
API design Proposal for a new or updated Seed API.

Comments

@MartinKavik
Copy link
Member

MartinKavik commented Mar 8, 2020

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.
@David-OConnor
Copy link
Member

I like it

@MartinKavik MartinKavik added this to the 2. Stable basic Seed API milestone Mar 9, 2020
@MartinKavik MartinKavik added the API design Proposal for a new or updated Seed API. label Mar 9, 2020
@MartinKavik
Copy link
Member Author

Implemented in PR #388.


Seed looks for element in and eventually sets base url for its router according to base's href.

Not implemented in the above PR, will be resolved with #369 and #383.

Seed tries to hydrate / overtake HTML in its mount point / root element. If it's not possible, fallbacks to render / append.

Fallback will be implemented once needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API design Proposal for a new or updated Seed API.
Projects
None yet
Development

No branches or pull requests

2 participants