-
Notifications
You must be signed in to change notification settings - Fork 153
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
scalable application support #189
scalable application support #189
Conversation
171f3a1
to
f86e52b
Compare
// Rebased on the current master & force-pushed - conflicts resolved. |
Looks like a load of improvements, espcecially towards flexiblity with complex projects. Review in prog. |
There shouldn't be any hacks. The most "tricky" part for review will be probably |
Awesome changes, @MartinKavik. Your real world example really is the mother of all examples. It would be great to reflect the changes here in the documentation page.
|
Hi there, In previous version, if you directly open URL "https://seed-rs.org/changelog", it shows the changelog (as expected, I guess). But since the upgrade, it goes on the home page whatever the URL entered (you can try on Seed webpage). In order to go to changelog, you need to explicitely navigate from the home page, by clicking the ChangeLog link on the top banner. I've seen the same change in my app and I found a workaround (inspired by seed-rs-realworld app) : Now, the behaviour is as expected (ie as before the upgrade). |
(necessary since seed 0.4.0 - PR #189 'scalable application support'') seed-rs/seed#189 (comment)
(necessary since seed 0.4.0 - PR #189 'scalable application support'') seed-rs/seed#189 (comment)
Appreciated at this! |
Well, RealWorld example is almost done (code is complete, I need to update readme, create demo and write some tests). So I can finally create PR with improvements which I created while I was working on it.
There are relatively many changes so I'll try to explain them on examples.
Let's look at
examples/animation_frame/src/lib.rs
:1. Change:
From:
To:
Order
isn'tstruct
buttrait
now, so we have to use keywordimpl
. It's a breaking change but it has advantages which I'll describe later.2. Change
From:
To:
orders
has a new methods -clone_app
andmsg_mapper
. They allow us to send app instance into closures without magic likeseed::update
or passing it somehow throughModel
(it was relatively often requested feature). It's possible thanks toimpl Orders
because it "hides"App
type parameters. So we don't need to deriveSerialize
&Deserialize
and registertrigger_update_handler
anymore. Note: I also changedClosure::wrap
toClosure::new
where possible in the whole codebase.3. Change
From:
To:
This change removes the need to call
app.update
and create special handling withMsg::Init
. It also allows us to choose the rightModel
according toUrl
so we don't have to create a special defaultModel
for the case "I don't know which page to display yet". It's the second breaking change.Let's look at
examples/server_integration/client/src/lib.rs
:4. Change:
From:
To:
There is another new method in
orders
:proxy
. It removes boilerplate for plumbing sub-modules and allows us to passorders
instead of creating new ones. So we can passapp
instance andeffect
queue through modules. Note: I've removed helper functioncall_update
- it's the third breaking change.Let's look at
src/routing.rs
:5. Change
From:
To:
The main goal is to don't refresh browser tab on click the element with empty link (i.e. click on
<a href=""></a>
does nothing.).Let's look at
src/fetch.rs
:6. Change
From:
To:
A - more ergonomic API - you can pass
url
as aString
or&'static str
B - if request fails, you want to know why and get more information or e.g. try another deserializer
C - if deserialization fails, you can try it again with another deserializer
D - more ergonomic API -
Debug
was needed because of ugly code, fixedMotivation for B+C:
Example - Server sends either status 200 + expected data (like list of blog articles) or 4xx and list of errors. => So we try to parse response data into articles if the status code is 200 or try to parse errors if code is 400 or at least log problems. It's more comfortable with those changes.
4th breaking change.
Let's look at the RealWorld example, because I haven't written example yet. Realworld's lib.rs:
7. Change
From:
// Nothing - it's a new feature.
To:
It's a new concept for communication among modules.
sink
it's almost the same likeupdate
but you receivedGMsg
("global message") instead of module'sMsg
. I'm using it in RealWorld example to notify root module that we want to change page/url (de factochild -> parent
communication) or for sending session data into pages (event producer -> event sinks
).How to use it:
GMsg
Orders
inupdate
,init
andsink
functions (just add 2nd parameter):&mut impl Orders<Msg, GMsg>
(Note: Default global message is()
)Orders
methods:orders.send_g_msg(GMsg::Something)
ororders.perform_g_cmd(...)
app
instance:app.sink(GMsg::Foo)
.Smaller changes:
md
.Closure::wrap
toClosure::new
except 2 cases inlib.rs
:set_interval
andset_timeout
(Addedtodo
that we should remove them because we are usinggloo
).dyn
everywhere (probably same as PR Dyn trait objects #188).examples/animation_frame/index.html
. (They was failing with non-root path in url).example/server_integration
.md!
andraw!
toexamples/server_interaction/src/lib.rs
so they are tested.Makefile.toml
.examples/websocket/src/server.rs
.Readme.md
.