As far as I can see there are two ways to trigger an update event:
update method of an App instance without (De)Serializationseed::update function with (De)SerializationI wonder what's exactly the difference and which way do you recommend?
Consider this context:
let app = seed::App::build(Model::default(), update, view::app)
.finish()
.run();
let a = app.clone();
let on_message = Closure::wrap(Box::new(move |ev: MessageEvent| {
let txt = ev.data().as_string().unwrap();
let notification: NotificationPayload = serde_json::from_str(&txt).unwrap();
a.update(Msg::ServerMsg(notification));
}) as Box<FnMut(MessageEvent)>);
I could get rid of app.clone() and use seed::update instead:
```diff
What do you think? Is the clone operation faster than serializing and deserializing the message + triggering an extra browser event?
Or what other aspects do I have to take into account?
I would use seed::update where using app is problematic - e.g. https://github.com/David-OConnor/seed/blob/master/examples/animation_frame/src/lib.rs#L81 => we don't have access to App instance here.
And app.update for other cases - I think that clone should be cheap, because all App's fields are Rc (https://github.com/David-OConnor/seed/blob/master/src/vdom.rs#L200).
I agree with MartinKavik. seed::update should only be used when app.update and events can't be used.
Thank you!
I added a small note to the docs (#157).
I still wonder why seed::update is used here:
I still wonder why seed::update is used here:
If I remember correctly
seed::update somewhereIf you think that it's confusing we can add comment to it or rewrite to app.
If you think that it's confusing we can add comment to it or rewrite to app.
I think adding a comment would be enough :)
FYI: There is a cleaner way to do it now, see https://github.com/David-OConnor/seed/blob/master/examples/animation_frame/src/lib.rs#L72. and _2. change_ in https://github.com/David-OConnor/seed/pull/189.
seed::update is deprecated and will be removed. I suggest to close the issue.