Closed
Description
Proposed changes (1st draft):
Replace App::builder
with:
App::start("app", init, update, view);
"app"
implementsMountPoint
/RootEl
.update
andview
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 tobase
'shref
. (Base for routing #369) - Seed tries to
hydrate
/overtake
HTML in its mount point / root element. If it's not possible, fallbacks torender
/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
andGMsg
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 yourModel
(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
inBeforeMount
. BeforeMount
andAfterMount
can be confusing - I would think that it meansBefore mounting to DOM
andAfter 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.