chore: rename all &cx to cx, make clipppy happy
This commit is contained in:
1 parent
e8133e9449
commit
4eefc3f854
85 files changed
+256
-271
No files matched your search
@@ -21,9 +21,12 @@ pub fn use_window(cx: &ScopeState) -> &DesktopContext {
|
||||
|
||||
/// Get a closure that executes any JavaScript in the WebView context.
|
||||
pub fn use_eval(cx: &ScopeState) -> &Rc<dyn Fn(String)> {
|
||||
let desktop = use_window(cx).clone();
|
||||
let desktop = use_window(cx);
|
||||
|
||||
&*cx.use_hook(|| Rc::new(move |script| desktop.eval(script)) as Rc<dyn Fn(String)>)
|
||||
&*cx.use_hook(|| {
|
||||
let desktop = desktop.clone();
|
||||
Rc::new(move |script| desktop.eval(script))
|
||||
} as Rc<dyn Fn(String)>)
|
||||
}
|
||||
|
||||
/// An imperative interface to the current window.
|
||||
|
||||
@@ -44,7 +44,7 @@ From anywhere in our app, we can read our the value of our atom:
|
||||
|
||||
```rust, ignore
|
||||
fn NameCard(cx: Scope) -> Element {
|
||||
let name = use_read(&cx, NAME);
|
||||
let name = use_read(cx, NAME);
|
||||
cx.render(rsx!{ h1 { "Hello, {name}"} })
|
||||
}
|
||||
```
|
||||
@@ -53,7 +53,7 @@ We can also set the value of our atom, also from anywhere in our app:
|
||||
|
||||
```rust, ignore
|
||||
fn NameCard(cx: Scope) -> Element {
|
||||
let set_name = use_set(&cx, NAME);
|
||||
let set_name = use_set(cx, NAME);
|
||||
cx.render(rsx!{
|
||||
button {
|
||||
onclick: move |_| set_name("Fermi"),
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::{
|
||||
/// static COUNT: Atom<u32> = |_| 0;
|
||||
///
|
||||
/// fn Example(cx: Scope) -> Element {
|
||||
/// let mut count = use_atom_state(&cx, COUNT);
|
||||
/// let mut count = use_atom_state(cx, COUNT);
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
/// div {
|
||||
@@ -74,7 +74,7 @@ impl<T: 'static> AtomState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let count = use_state(&cx, || 0);
|
||||
/// let count = use_state(cx, || 0);
|
||||
/// cx.spawn({
|
||||
/// let set_count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -101,7 +101,7 @@ impl<T: 'static> AtomState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// rsx!{
|
||||
/// Component {
|
||||
@@ -128,7 +128,7 @@ impl<T: 'static> AtomState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// // to increment the value
|
||||
/// value.modify(|v| v + 1);
|
||||
@@ -168,7 +168,7 @@ impl<T: 'static> AtomState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// let as_rc = value.get();
|
||||
/// assert_eq!(as_rc.as_ref(), &0);
|
||||
@@ -190,7 +190,7 @@ impl<T: 'static> AtomState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let count = use_state(&cx, || 0);
|
||||
/// let count = use_state(cx, || 0);
|
||||
/// cx.spawn({
|
||||
/// let count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -220,7 +220,7 @@ impl<T: Clone> AtomState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// let val = use_state(&cx, || 0);
|
||||
/// let val = use_state(cx, || 0);
|
||||
///
|
||||
/// val.with_mut(|v| *v = 1);
|
||||
/// ```
|
||||
@@ -243,7 +243,7 @@ impl<T: Clone> AtomState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```ignore
|
||||
/// let val = use_state(&cx, || 0);
|
||||
/// let val = use_state(cx, || 0);
|
||||
///
|
||||
/// *val.make_mut() += 1;
|
||||
/// ```
|
||||
|
||||
@@ -15,8 +15,8 @@ You can always use it "normally" with the `split` method:
|
||||
|
||||
```rust
|
||||
// Rusty-smart-pointer usage:
|
||||
let value = use_state(&cx, || 10);
|
||||
let value = use_state(cx, || 10);
|
||||
|
||||
// "Classic" usage:
|
||||
let (value, set_value) = use_state(&cx, || 0).split();
|
||||
let (value, set_value) = use_state(cx, || 0).split();
|
||||
```
|
||||
@@ -5,7 +5,7 @@
|
||||
///
|
||||
///
|
||||
/// ```ignore
|
||||
/// let (data) = use_ref(&cx, || {});
|
||||
/// let (data) = use_ref(cx, || {});
|
||||
///
|
||||
/// let handle_thing = move |_| {
|
||||
/// to_owned![data]
|
||||
|
||||
@@ -16,7 +16,7 @@ This is moderately efficient because the fields of the map are moved, but the da
|
||||
However, if you used similar approach with Dioxus:
|
||||
|
||||
```rust
|
||||
let (map, set_map) = use_state(&cx, || HashMap::new());
|
||||
let (map, set_map) = use_state(cx, || HashMap::new());
|
||||
set_map({
|
||||
let mut newmap = map.clone();
|
||||
newmap.set(key, value);
|
||||
|
||||
@@ -44,7 +44,7 @@ use crate::{use_context, use_context_provider};
|
||||
/// Stop,
|
||||
/// }
|
||||
///
|
||||
/// let chat_client = use_coroutine(&cx, |rx: UnboundedReceiver<Action>| async move {
|
||||
/// let chat_client = use_coroutine(cx, |rx: UnboundedReceiver<Action>| async move {
|
||||
/// while let Some(action) = rx.next().await {
|
||||
/// match action {
|
||||
/// Action::Start => {}
|
||||
@@ -119,15 +119,15 @@ mod tests {
|
||||
use futures_util::StreamExt;
|
||||
|
||||
fn app(cx: Scope, name: String) -> Element {
|
||||
let task = use_coroutine(&cx, |mut rx: UnboundedReceiver<i32>| async move {
|
||||
let task = use_coroutine(cx, |mut rx: UnboundedReceiver<i32>| async move {
|
||||
while let Some(msg) = rx.next().await {
|
||||
println!("got message: {}", msg);
|
||||
}
|
||||
});
|
||||
|
||||
let task2 = use_coroutine(&cx, view_task);
|
||||
let task2 = use_coroutine(cx, view_task);
|
||||
|
||||
let task3 = use_coroutine(&cx, |rx| complex_task(rx, 10));
|
||||
let task3 = use_coroutine(cx, |rx| complex_task(rx, 10));
|
||||
|
||||
todo!()
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::UseFutureDep;
|
||||
///
|
||||
/// #[inline_props]
|
||||
/// fn app(cx: Scope, name: &str) -> Element {
|
||||
/// use_effect(&cx, (name,), |(name,)| async move {
|
||||
/// use_effect(cx, (name,), |(name,)| async move {
|
||||
/// set_title(name);
|
||||
/// }))
|
||||
/// }
|
||||
@@ -72,17 +72,17 @@ mod tests {
|
||||
|
||||
fn app(cx: Scope<MyProps>) -> Element {
|
||||
// should only ever run once
|
||||
use_effect(&cx, (), |_| async move {
|
||||
use_effect(cx, (), |_| async move {
|
||||
//
|
||||
});
|
||||
|
||||
// runs when a is changed
|
||||
use_effect(&cx, (&cx.props.a,), |(a,)| async move {
|
||||
use_effect(cx, (cx.props.a,), |(a,)| async move {
|
||||
//
|
||||
});
|
||||
|
||||
// runs when a or b is changed
|
||||
use_effect(&cx, (&cx.props.a, &cx.props.b), |(a, b)| async move {
|
||||
use_effect(cx, (cx.props.a, &cx.props.b), |(a, b)| async move {
|
||||
//
|
||||
});
|
||||
|
||||
|
||||
@@ -319,10 +319,10 @@ mod tests {
|
||||
let fut = use_future(cx, (), |_| async move {});
|
||||
|
||||
// runs when a is changed
|
||||
let fut = use_future(cx, (&cx.props.a,), |(a,)| async move {});
|
||||
let fut = use_future(cx, (cx.props.a,), |(a,)| async move {});
|
||||
|
||||
// runs when a or b is changed
|
||||
let fut = use_future(cx, (&cx.props.a, &cx.props.b), |(a, b)| async move { 123 });
|
||||
let fut = use_future(cx, (cx.props.a, &cx.props.b), |(a, b)| async move { 123 });
|
||||
|
||||
let a = use_future!(cx, || async move {
|
||||
// do the thing!
|
||||
|
||||
@@ -19,7 +19,7 @@ use std::{
|
||||
///
|
||||
/// ```ignore
|
||||
/// const Example: Component = |cx| {
|
||||
/// let count = use_state(&cx, || 0);
|
||||
/// let count = use_state(cx, || 0);
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
/// div {
|
||||
@@ -92,7 +92,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let count = use_state(&cx, || 0);
|
||||
/// let count = use_state(cx, || 0);
|
||||
/// cx.spawn({
|
||||
/// let set_count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -119,7 +119,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// rsx!{
|
||||
/// Component {
|
||||
@@ -144,7 +144,7 @@ impl<T: 'static> UseState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// // to increment the value
|
||||
/// value.modify(|v| v + 1);
|
||||
@@ -185,7 +185,7 @@ impl<T: 'static> UseState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let value = use_state(&cx, || 0);
|
||||
/// let value = use_state(cx, || 0);
|
||||
///
|
||||
/// let as_rc = value.get();
|
||||
/// assert_eq!(as_rc.as_ref(), &0);
|
||||
@@ -207,7 +207,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component(cx: Scope) -> Element {
|
||||
/// let count = use_state(&cx, || 0);
|
||||
/// let count = use_state(cx, || 0);
|
||||
/// cx.spawn({
|
||||
/// let count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -237,7 +237,7 @@ impl<T: Clone> UseState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let val = use_state(&cx, || 0);
|
||||
/// let val = use_state(cx, || 0);
|
||||
///
|
||||
/// val.with_mut(|v| *v = 1);
|
||||
/// ```
|
||||
@@ -269,7 +269,7 @@ impl<T: Clone> UseState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let val = use_state(&cx, || 0);
|
||||
/// let val = use_state(cx, || 0);
|
||||
///
|
||||
/// *val.make_mut() += 1;
|
||||
/// ```
|
||||
@@ -448,7 +448,7 @@ impl<T: Div<Output = T> + Copy> std::ops::DivAssign<T> for UseState<T> {
|
||||
fn api_makes_sense() {
|
||||
#[allow(unused)]
|
||||
fn app(cx: Scope) -> Element {
|
||||
let val = use_state(&cx, || 0);
|
||||
let val = use_state(cx, || 0);
|
||||
|
||||
val.set(0);
|
||||
val.modify(|v| v + 1);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use js_sys::Function;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use web_sys::{Element, Node};
|
||||
use web_sys::Element;
|
||||
|
||||
#[wasm_bindgen(module = "/src/interpreter.js")]
|
||||
extern "C" {
|
||||
@@ -18,7 +18,7 @@ extern "C" {
|
||||
pub fn MountToRoot(this: &Interpreter);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn AppendChildren(this: &Interpreter, m: u32);
|
||||
pub fn AppendChildren(this: &Interpreter, m: u32, id: u32);
|
||||
|
||||
#[wasm_bindgen(method)]
|
||||
pub fn AssignId(this: &Interpreter, path: &[u8], id: u32);
|
||||
|
||||
@@ -40,7 +40,7 @@ async fn order_shoes(mut req: WebsocketRequest) -> Response {
|
||||
}
|
||||
|
||||
fn App(cx: Scope) -> Element {
|
||||
let mut count = use_state(&cx, || 0);
|
||||
let mut count = use_state(cx, || 0);
|
||||
cx.render(rsx!(
|
||||
button { onclick: move |_| count += 1, "Incr" }
|
||||
button { onclick: move |_| count -= 1, "Decr" }
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::any::Any;
|
||||
use std::sync::Arc;
|
||||
|
||||
use dioxus_core::ElementId;
|
||||
use dioxus_html::event_bubbles;
|
||||
// use dioxus_html::event_bubbles;
|
||||
use dioxus_html::events::*;
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
@@ -29,7 +29,7 @@ struct ImEvent {
|
||||
contents: serde_json::Value,
|
||||
}
|
||||
|
||||
pub fn trigger_from_serialized(val: serde_json::Value) -> () {
|
||||
pub fn trigger_from_serialized(_val: serde_json::Value) {
|
||||
todo!()
|
||||
// let ImEvent {
|
||||
// event,
|
||||
|
||||
@@ -36,7 +36,7 @@ fn BlogList(cx: Scope) -> Element {
|
||||
}
|
||||
|
||||
fn BlogPost(cx: Scope) -> Element {
|
||||
let id = use_route(&cx).segment("id")?;
|
||||
let id = use_route(cx).segment("id")?;
|
||||
|
||||
log::trace!("rendering blog post {}", id);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ fn simple_test() {
|
||||
}
|
||||
|
||||
fn BlogPost(cx: Scope) -> Element {
|
||||
let _id = use_route(&cx).parse_segment::<usize>("id")?;
|
||||
let _id = use_route(cx).parse_segment::<usize>("id")?;
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -89,7 +89,7 @@ You must provide a valid URL `{scheme}://{?authority}/{?path}`.
|
||||
|
||||
```rust
|
||||
Router {
|
||||
initial_url: "https://dioxuslab.com/blog", // Set the initial url.
|
||||
initial_url: "https://dioxuslab.com/blog", // Set the initial url.
|
||||
Link { to: "/", "Home" },
|
||||
Link { to: "/blog", "Blog" }, // The router will render this route.
|
||||
}
|
||||
@@ -109,7 +109,7 @@ For any route, you can get a handle the current route with the `use_route` hook.
|
||||
|
||||
```rust
|
||||
fn Title(cx: Scope) -> Element {
|
||||
let route = use_route(&cx);
|
||||
let route = use_route(cx);
|
||||
|
||||
assert_eq!(route.segments(), &["dogs", "breeds", "yorkie", "hugo"]);
|
||||
|
||||
@@ -130,7 +130,7 @@ Router {
|
||||
}
|
||||
|
||||
fn BlogPost(cx: Scope) -> Element {
|
||||
let route = use_route(&cx);
|
||||
let route = use_route(cx);
|
||||
|
||||
match route.segment("post").and_then(parse) {
|
||||
Some(post) => cx.render(rsx!{ div { "Post {post}" } })
|
||||
@@ -168,7 +168,7 @@ Listeners can also be attached downstream in your app with the `RouteListener` h
|
||||
|
||||
```rust
|
||||
fn TitleCard(cx: Scope) -> Element {
|
||||
let (title, set_title) = use_state(&cx, || "First");
|
||||
let (title, set_title) = use_state(cx, || "First");
|
||||
|
||||
cx.render(rsx!{
|
||||
h1 { "render {title}" }
|
||||
|
||||
@@ -41,7 +41,7 @@ struct BoxProps {
|
||||
}
|
||||
#[allow(non_snake_case)]
|
||||
fn Box(cx: Scope<BoxProps>) -> Element {
|
||||
let count = use_state(&cx, || 0);
|
||||
let count = use_state(cx, || 0);
|
||||
|
||||
let x = cx.props.x * 2;
|
||||
let y = cx.props.y * 2;
|
||||
@@ -70,8 +70,8 @@ struct GridProps {
|
||||
#[allow(non_snake_case)]
|
||||
fn Grid(cx: Scope<GridProps>) -> Element {
|
||||
let size = cx.props.size;
|
||||
let count = use_state(&cx, || 0);
|
||||
let counts = use_ref(&cx, || vec![0; size * size]);
|
||||
let count = use_state(cx, || 0);
|
||||
let counts = use_ref(cx, || vec![0; size * size]);
|
||||
|
||||
let ctx: &TuiContext = cx.consume_context().unwrap();
|
||||
if *count.get() + 1 >= (size * size) {
|
||||
|
||||
@@ -27,7 +27,7 @@ enum Event {
|
||||
const MAX_EVENTS: usize = 8;
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let events = use_ref(&cx, Vec::new);
|
||||
let events = use_ref(cx, Vec::new);
|
||||
|
||||
let events_lock = events.read();
|
||||
let first_index = events_lock.len().saturating_sub(MAX_EVENTS);
|
||||
|
||||
@@ -5,7 +5,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let radius = use_state(&cx, || 0);
|
||||
let radius = use_state(cx, || 0);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -13,8 +13,8 @@ struct ButtonProps {
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
fn Button(cx: Scope<ButtonProps>) -> Element {
|
||||
let toggle = use_state(&cx, || false);
|
||||
let hovered = use_state(&cx, || false);
|
||||
let toggle = use_state(cx, || false);
|
||||
let hovered = use_state(cx, || false);
|
||||
|
||||
let hue = cx.props.color_offset % 255;
|
||||
let saturation = if *toggle.get() { 50 } else { 25 } + if *hovered.get() { 50 } else { 25 };
|
||||
|
||||
@@ -8,8 +8,8 @@ fn main() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let hue = use_state(&cx, || 0.0);
|
||||
let brightness = use_state(&cx, || 0.0);
|
||||
let hue = use_state(cx, || 0.0);
|
||||
let brightness = use_state(cx, || 0.0);
|
||||
let tui_query: &Query = cx.consume_context().unwrap();
|
||||
// disable templates so that every node has an id and can be queried
|
||||
cx.render(rsx! {
|
||||
|
||||
@@ -17,20 +17,20 @@ fn app(cx: Scope) -> Element {
|
||||
127 * b
|
||||
}
|
||||
|
||||
let q1_color = use_state(&cx, || [200; 3]);
|
||||
let q2_color = use_state(&cx, || [200; 3]);
|
||||
let q3_color = use_state(&cx, || [200; 3]);
|
||||
let q4_color = use_state(&cx, || [200; 3]);
|
||||
let q1_color = use_state(cx, || [200; 3]);
|
||||
let q2_color = use_state(cx, || [200; 3]);
|
||||
let q3_color = use_state(cx, || [200; 3]);
|
||||
let q4_color = use_state(cx, || [200; 3]);
|
||||
|
||||
let q1_color_str = to_str(q1_color);
|
||||
let q2_color_str = to_str(q2_color);
|
||||
let q3_color_str = to_str(q3_color);
|
||||
let q4_color_str = to_str(q4_color);
|
||||
|
||||
let page_coordinates = use_state(&cx, || "".to_string());
|
||||
let element_coordinates = use_state(&cx, || "".to_string());
|
||||
let buttons = use_state(&cx, || "".to_string());
|
||||
let modifiers = use_state(&cx, || "".to_string());
|
||||
let page_coordinates = use_state(cx, || "".to_string());
|
||||
let element_coordinates = use_state(cx, || "".to_string());
|
||||
let buttons = use_state(cx, || "".to_string());
|
||||
let modifiers = use_state(cx, || "".to_string());
|
||||
|
||||
let update_data = move |event: Event<MouseData>| {
|
||||
let mouse_data = event.inner();
|
||||
|
||||
@@ -5,9 +5,9 @@ fn main() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let count = use_state(&cx, || 0);
|
||||
let count = use_state(cx, || 0);
|
||||
|
||||
use_future(&cx, (), move |_| {
|
||||
use_future(cx, (), move |_| {
|
||||
let count = count.to_owned();
|
||||
let update = cx.schedule_update();
|
||||
async move {
|
||||
|
||||
@@ -5,7 +5,7 @@ fn main() {
|
||||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let alpha = use_state(&cx, || 100);
|
||||
let alpha = use_state(cx, || 100);
|
||||
|
||||
cx.render(rsx! {
|
||||
div {
|
||||
|
||||
@@ -26,8 +26,8 @@ use crate::{layout_to_screen_space, TuiDom};
|
||||
/// }
|
||||
///
|
||||
/// fn app(cx: Scope) -> Element {
|
||||
/// let hue = use_state(&cx, || 0.0);
|
||||
/// let brightness = use_state(&cx, || 0.0);
|
||||
/// let hue = use_state(cx, || 0.0);
|
||||
/// let brightness = use_state(cx, || 0.0);
|
||||
/// let tui_query: Query = cx.consume_context().unwrap();
|
||||
/// cx.render(rsx! {
|
||||
/// div{
|
||||
|
||||
@@ -33,7 +33,7 @@ fn key_down() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -70,7 +70,7 @@ fn mouse_down() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -104,7 +104,7 @@ fn mouse_up() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -143,7 +143,7 @@ fn mouse_enter() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -182,7 +182,7 @@ fn mouse_exit() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -221,7 +221,7 @@ fn mouse_move() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -260,7 +260,7 @@ fn wheel() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -300,7 +300,7 @@ fn click() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
@@ -339,7 +339,7 @@ fn context_menu() {
|
||||
dioxus_tui::launch_cfg(app, dioxus_tui::Config::new().with_headless());
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
let render_count = use_state(&cx, || 0);
|
||||
let render_count = use_state(cx, || 0);
|
||||
let tui_ctx: TuiContext = cx.consume_context().unwrap();
|
||||
let render_count_handle = render_count.clone();
|
||||
cx.spawn(async move {
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//! - tests to ensure dyn_into works for various event types.
|
||||
//! - Partial delegation?>
|
||||
|
||||
use dioxus_core::{ElementId, Mutation, Mutations, Template, TemplateAttribute, TemplateNode};
|
||||
use dioxus_core::{Mutation, Template};
|
||||
use dioxus_html::{event_bubbles, CompositionData, FormData};
|
||||
use dioxus_interpreter_js::Interpreter;
|
||||
use futures_channel::mpsc;
|
||||
use js_sys::Function;
|
||||
use std::{any::Any, rc::Rc};
|
||||
use wasm_bindgen::{closure::Closure, JsCast, JsValue};
|
||||
use wasm_bindgen::{closure::Closure, JsCast};
|
||||
use web_sys::{Document, Element, Event};
|
||||
|
||||
use crate::Config;
|
||||
@@ -61,7 +60,7 @@ impl WebsysDom {
|
||||
let i = &self.interpreter;
|
||||
for edit in edits.drain(..) {
|
||||
match edit {
|
||||
AppendChildren { id, m } => i.AppendChildren(m as u32),
|
||||
AppendChildren { id, m } => i.AppendChildren(m as u32, id.0 as u32),
|
||||
AssignId { path, id } => i.AssignId(path, id.0 as u32),
|
||||
CreatePlaceholder { id } => i.CreatePlaceholder(id.0 as u32),
|
||||
CreateTextNode { value, id } => i.CreateTextNode(value.into(), id.0 as u32),
|
||||
@@ -81,7 +80,7 @@ impl WebsysDom {
|
||||
i.SetBoolAttribute(id.0 as u32, name, value)
|
||||
}
|
||||
SetText { value, id } => i.SetText(id.0 as u32, value.into()),
|
||||
NewEventListener { name, scope, id } => {
|
||||
NewEventListener { name, id, .. } => {
|
||||
self.interpreter.NewEventListener(
|
||||
name,
|
||||
id.0 as u32,
|
||||
|
||||
+2
-11
@@ -53,15 +53,11 @@
|
||||
// - Do the VDOM work during the idlecallback
|
||||
// - Do DOM work in the next requestAnimationFrame callback
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
pub use crate::cfg::Config;
|
||||
use crate::dom::virtual_event_from_websys_event;
|
||||
pub use crate::util::use_eval;
|
||||
use dioxus_core::{Element, ElementId, Scope, VirtualDom};
|
||||
use futures_channel::mpsc::unbounded;
|
||||
use futures_util::{pin_mut, FutureExt, StreamExt};
|
||||
use gloo_timers::future::sleep;
|
||||
|
||||
mod cache;
|
||||
mod cfg;
|
||||
@@ -181,7 +177,7 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
wasm_bindgen::intern(s);
|
||||
}
|
||||
|
||||
let should_hydrate = cfg.hydrate;
|
||||
let _should_hydrate = cfg.hydrate;
|
||||
|
||||
let (tx, mut rx) = futures_channel::mpsc::unbounded();
|
||||
|
||||
@@ -193,8 +189,6 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
// } else {
|
||||
let edits = dom.rebuild();
|
||||
|
||||
log::debug!("Initial edits {:#?}", edits);
|
||||
|
||||
websys_dom.load_templates(&edits.templates);
|
||||
websys_dom.apply_edits(edits.edits);
|
||||
|
||||
@@ -214,9 +208,8 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
|
||||
futures_util::select! {
|
||||
_ = work => None,
|
||||
new_template = hotreload_rx.next() => {
|
||||
_new_template = hotreload_rx.next() => {
|
||||
todo!("Implement hot reload");
|
||||
None
|
||||
}
|
||||
evt = rx.next() => evt
|
||||
}
|
||||
@@ -251,8 +244,6 @@ pub async fn run_with_props<T: 'static>(root: fn(Scope<T>) -> Element, root_prop
|
||||
// wait for the animation frame to fire so we can apply our changes
|
||||
work_loop.wait_for_raf().await;
|
||||
|
||||
log::debug!("edits {:#?}", edits);
|
||||
|
||||
websys_dom.load_templates(&edits.templates);
|
||||
websys_dom.apply_edits(edits.edits);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user