Skip to content

Commit 0aed37b

Browse files
committed
fix: Expose App::mailbox; rerender VDOM on handler invocation without Msg
1 parent 4a20d3f commit 0aed37b

File tree

5 files changed

+13
-46
lines changed

5 files changed

+13
-46
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
- [BREAKING] Renamed `to_kbevent` to `to_keyboard_event`.
5050
- [BREAKING] `after_next_render` returns `RenderInfo`.
5151
- `web_sys` and `wasm_bindgen` available in `seed::web_sys` and `seed::wasm_bindgen`.
52-
- Added `WebSocket`.
52+
- Added `WebSocket` + related items.
53+
- Exposed `App::mailbox`.
5354

5455
## v0.6.0
5556
- Implemented `UpdateEl` for `Filter` and `FilterMap`.

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ impl<Ms, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> App<Ms, Mdl, INodes
556556
);
557557
}
558558

559-
fn mailbox(&self) -> Mailbox<Ms> {
559+
pub fn mailbox(&self) -> Mailbox<Ms> {
560560
Mailbox::new(enclose!((self => s) move |option_message| {
561561
if let Some(message) = option_message {
562562
s.update(message);

src/app/orders/container.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ impl<Ms: 'static, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> Orders<Ms,
8181
Box
8282
);
8383

84-
let cmd = cmd.map(move |msg| {
85-
if let Some(msg) = handler(msg) {
86-
app.update(msg)
87-
}
88-
});
84+
let cmd = cmd.map(move |msg| app.mailbox().send(handler(msg)));
8985
CmdManager::perform_cmd(cmd);
9086
self
9187
}
@@ -103,11 +99,7 @@ impl<Ms: 'static, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> Orders<Ms,
10399
Box
104100
);
105101

106-
let cmd = cmd.map(move |msg| {
107-
if let Some(msg) = handler(msg) {
108-
app.update(msg)
109-
}
110-
});
102+
let cmd = cmd.map(move |msg| app.mailbox().send(handler(msg)));
111103
CmdManager::perform_cmd_with_handle(cmd)
112104
}
113105

@@ -204,11 +196,7 @@ impl<Ms: 'static, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> Orders<Ms,
204196
Box
205197
);
206198

207-
let stream = stream.map(move |msg| {
208-
if let Some(msg) = handler(msg) {
209-
app.update(msg)
210-
}
211-
});
199+
let stream = stream.map(move |msg| app.mailbox().send(handler(msg)));
212200
StreamManager::stream(stream);
213201
self
214202
}
@@ -226,11 +214,7 @@ impl<Ms: 'static, Mdl, INodes: IntoNodes<Ms> + 'static, GMs: 'static> Orders<Ms,
226214
Box
227215
);
228216

229-
let stream = stream.map(move |msg| {
230-
if let Some(msg) = handler(msg) {
231-
app.update(msg)
232-
}
233-
});
217+
let stream = stream.map(move |msg| app.mailbox().send(handler(msg)));
234218
StreamManager::stream_with_handle(stream)
235219
}
236220
}

src/app/orders/proxy.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,7 @@ impl<'a, Ms: 'static, AppMs: 'static, Mdl, INodes: IntoNodes<AppMs> + 'static, G
9494
Box
9595
);
9696

97-
let cmd = cmd.map(move |msg| {
98-
if let Some(msg) = handler(msg) {
99-
app.update(f(msg))
100-
}
101-
});
97+
let cmd = cmd.map(move |msg| app.mailbox().send(handler(msg).map(|msg| f(msg))));
10298
CmdManager::perform_cmd(cmd);
10399
self
104100
}
@@ -117,11 +113,7 @@ impl<'a, Ms: 'static, AppMs: 'static, Mdl, INodes: IntoNodes<AppMs> + 'static, G
117113
Box
118114
);
119115

120-
let cmd = cmd.map(move |msg| {
121-
if let Some(msg) = handler(msg) {
122-
app.update(f(msg))
123-
}
124-
});
116+
let cmd = cmd.map(move |msg| app.mailbox().send(handler(msg).map(|msg| f(msg))));
125117
CmdManager::perform_cmd_with_handle(cmd)
126118
}
127119

@@ -224,11 +216,7 @@ impl<'a, Ms: 'static, AppMs: 'static, Mdl, INodes: IntoNodes<AppMs> + 'static, G
224216
Box
225217
);
226218

227-
let stream = stream.map(move |msg| {
228-
if let Some(msg) = handler(msg) {
229-
app.update(f(msg))
230-
}
231-
});
219+
let stream = stream.map(move |msg| app.mailbox().send(handler(msg).map(|msg| f(msg))));
232220
StreamManager::stream(stream);
233221
self
234222
}
@@ -247,11 +235,7 @@ impl<'a, Ms: 'static, AppMs: 'static, Mdl, INodes: IntoNodes<AppMs> + 'static, G
247235
Box
248236
);
249237

250-
let stream = stream.map(move |msg| {
251-
if let Some(msg) = handler(msg) {
252-
app.update(f(msg))
253-
}
254-
});
238+
let stream = stream.map(move |msg| app.mailbox().send(handler(msg).map(|msg| f(msg))));
255239
StreamManager::stream_with_handle(stream)
256240
}
257241
}

src/browser/web_socket/builder.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,9 @@ fn create_js_handler<T: wasm_bindgen::convert::FromWasmAbi + 'static, Ms: 'stati
177177
orders: &impl Orders<Ms>,
178178
) -> Closure<dyn Fn(T)> {
179179
let (app, msg_mapper) = (orders.clone_app(), orders.msg_mapper());
180-
180+
let mailbox = app.mailbox();
181181
// @TODO replace with `Closure::new` once stable.
182182
Closure::wrap(Box::new(move |data| {
183-
if let Some(msg) = handler(data) {
184-
app.update(msg_mapper(msg))
185-
}
183+
mailbox.send(handler(data).map(|msg| msg_mapper(msg)));
186184
}) as Box<dyn Fn(T)>)
187185
}

0 commit comments

Comments
 (0)