forked from bkase/gameboy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Machinery in place to use future-signals to drive a GUI
- Loading branch information
Showing
4 changed files
with
77 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use futures::{Future, FutureExt}; | ||
use futures_signals::signal::{Signal, SignalExt}; | ||
use virtual_dom_rs::prelude::*; | ||
use web_utils; | ||
|
||
fn sample_view<In: Signal<Item = u32>>(model: In) -> impl Signal<Item = VirtualNode> { | ||
model.map(|m| { | ||
let greetings = format!("Hello, World! {}", m); | ||
html! { <div> { greetings } </div> } | ||
}) | ||
} | ||
|
||
pub fn run<In: Signal<Item = u32>>(rx: In) -> impl Future<Output = ()> { | ||
let start_view = html! { <div> Hello </div> }; | ||
|
||
let body = web_utils::document().body().unwrap(); | ||
|
||
let mut dom_updater = DomUpdater::new_append_to_mount(start_view, &body); | ||
|
||
sample_view(rx) | ||
.map(move |vdom| dom_updater.update(vdom)) | ||
.to_future() | ||
.map(|_| ()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use futures::task::Poll; | ||
use futures::Future; | ||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
pub fn tick<F: Future + Unpin>(f: Rc<RefCell<F>>) -> Poll<F::Output> { | ||
let waker = futures_util::task::noop_waker(); | ||
// TODO: Is this safe? | ||
let mut pin = unsafe { std::pin::Pin::new_unchecked(f.borrow_mut()) }; | ||
pin.as_mut().poll(&waker) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters