Merge pull request #99 from hecrj/fix/web-render-after-command
Schedule render after `Command` futures finish in `iced_web`
This commit is contained in:
commit
ff0dc44cd7
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
### Fixed
|
||||||
|
- Render not being scheduled after `Command` futures finishing.
|
||||||
|
|
||||||
## [0.1.0] - 2019-11-25
|
## [0.1.0] - 2019-11-25
|
||||||
### Added
|
### Added
|
||||||
|
@ -138,19 +138,9 @@ pub trait Application {
|
|||||||
Self: 'static + Sized,
|
Self: 'static + Sized,
|
||||||
{
|
{
|
||||||
let (app, command) = Self::new();
|
let (app, command) = Self::new();
|
||||||
let mut instance = Instance::new(app);
|
|
||||||
|
|
||||||
instance.spawn(command);
|
let instance = Instance::new(app);
|
||||||
|
instance.run(command);
|
||||||
let window = web_sys::window().unwrap();
|
|
||||||
|
|
||||||
let document = window.document().unwrap();
|
|
||||||
document.set_title(&instance.title);
|
|
||||||
|
|
||||||
let body = document.body().unwrap();
|
|
||||||
let vdom = dodrio::Vdom::new(&body, instance);
|
|
||||||
|
|
||||||
vdom.forget();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,6 +148,7 @@ pub trait Application {
|
|||||||
struct Instance<Message> {
|
struct Instance<Message> {
|
||||||
title: String,
|
title: String,
|
||||||
ui: Rc<RefCell<Box<dyn Application<Message = Message>>>>,
|
ui: Rc<RefCell<Box<dyn Application<Message = Message>>>>,
|
||||||
|
vdom: Rc<RefCell<Option<dodrio::VdomWeak>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> Instance<Message>
|
impl<Message> Instance<Message>
|
||||||
@ -168,6 +159,7 @@ where
|
|||||||
Self {
|
Self {
|
||||||
title: ui.title(),
|
title: ui.title(),
|
||||||
ui: Rc::new(RefCell::new(Box::new(ui))),
|
ui: Rc::new(RefCell::new(Box::new(ui))),
|
||||||
|
vdom: Rc::new(RefCell::new(None)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,11 +184,35 @@ where
|
|||||||
|
|
||||||
for future in command.futures() {
|
for future in command.futures() {
|
||||||
let mut instance = self.clone();
|
let mut instance = self.clone();
|
||||||
let future = future.map(move |message| instance.update(message));
|
|
||||||
|
let future = future.map(move |message| {
|
||||||
|
instance.update(message);
|
||||||
|
|
||||||
|
if let Some(ref vdom) = *instance.vdom.borrow() {
|
||||||
|
vdom.schedule_render();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
wasm_bindgen_futures::spawn_local(future);
|
wasm_bindgen_futures::spawn_local(future);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn run(mut self, command: Command<Message>) {
|
||||||
|
let window = web_sys::window().unwrap();
|
||||||
|
|
||||||
|
let document = window.document().unwrap();
|
||||||
|
document.set_title(&self.title);
|
||||||
|
|
||||||
|
let body = document.body().unwrap();
|
||||||
|
|
||||||
|
let weak = self.vdom.clone();
|
||||||
|
self.spawn(command);
|
||||||
|
|
||||||
|
let vdom = dodrio::Vdom::new(&body, self);
|
||||||
|
*weak.borrow_mut() = Some(vdom.weak());
|
||||||
|
|
||||||
|
vdom.forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Message> dodrio::Render for Instance<Message>
|
impl<Message> dodrio::Render for Instance<Message>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user