This PR contains just the breaking changes required for the upcoming store implementation. It adds two new primitives: Mutable mapped signals (without a different subscriber list). This lets you scope a writable value and pass it to a child component. It requires two closures to map the immutable and mutable references to the inner signal. With stores, these closures will be derived Boxed readable and writable values (ReadSignal, and WriteSignal). Any readable or writable types can be converted to a read signal or write signal with the boxed method or built in types are automatically converted into the boxed variants when passing into props * map signals mutably * boxed signals * remove mutable borrow type from boxed writable * improve map mut example * restore boxed_mut helper * make boxed readable/writable types copy * Move away from the ReadOnlySignal alias in examples * automatically convert Write * Fix some tests * ReadSignal and WriteSignal * move read only signal alias * make maps copy * store prototype * implement derive macro * Handle generics in the derive macro * Make Selector boxable * derive boxed conversion * Get rid of store type * Remove hardcoded type from derive macro * selector -> store * Refactor store implementation * more vec methods * todo mvc store example * Implement Storable for HashMap * fix write * restore sorting logic in todomvc * derive readable and writable * improve todomvc store example * Result store * Option store * collect dead subscribers * fix clippy and formatting * recognize some common foreign types automatically * fix foreign stores in props * slice and array selectors * clean up store example * remove stores * writable is child owned * fix typo * fix clippy * fix doc tests
149 lines
4.1 KiB
Rust
149 lines
4.1 KiB
Rust
#[test]
|
|
fn rsx() {
|
|
let t = trybuild::TestCases::new();
|
|
t.compile_fail("tests/rsx/trailing-comma-0.rs");
|
|
}
|
|
|
|
/// This test ensures that automatic `into` conversion occurs for default values.
|
|
///
|
|
/// These are compile-time tests.
|
|
/// See https://github.com/DioxusLabs/dioxus/issues/2373
|
|
#[cfg(test)]
|
|
mod test_default_into {
|
|
use dioxus::prelude::*;
|
|
|
|
#[derive(Props, Clone, PartialEq)]
|
|
struct MyCoolProps {
|
|
// Test different into configurations
|
|
#[props(into, default = true)]
|
|
pub val_into_w_default_val: u16,
|
|
|
|
#[props(into, default)]
|
|
pub val_into_w_default: u16,
|
|
|
|
#[props(default = true.into())]
|
|
pub val_default: u16,
|
|
|
|
// Test different into configurations with strings
|
|
#[props(into, default = "abc")]
|
|
pub str_into_w_default_val: String,
|
|
|
|
#[props(into, default)]
|
|
pub str_into_w_default: String,
|
|
|
|
#[props(default = "abc".into())]
|
|
pub str_default: String,
|
|
|
|
// Test options
|
|
#[props(into, default = Some("abc"))]
|
|
pub opt_into_w_default_val: Option<String>,
|
|
|
|
#[props(into, default)]
|
|
pub opt_into_w_default: Option<String>,
|
|
|
|
#[props(default = Some("abc"))]
|
|
pub opt_default: Option<String>,
|
|
|
|
// Test no default
|
|
#[props(into)]
|
|
pub some_data: bool,
|
|
|
|
pub some_other_data: bool,
|
|
|
|
// Test default values for signals
|
|
#[props(default)]
|
|
read_only_w_default: ReadSignal<bool>,
|
|
|
|
#[props(default = true)]
|
|
read_only_w_default_val: ReadSignal<bool>,
|
|
|
|
#[props(default = ReadSignal::new(Signal::new(true)))]
|
|
read_only_w_default_val_explicit: ReadSignal<bool>,
|
|
|
|
// Test default values for callbacks/event handlers
|
|
#[props(default)]
|
|
callback_w_default: Callback,
|
|
|
|
#[props(default = move |_| {})]
|
|
callback_w_default_val_closure: Callback,
|
|
|
|
#[props(default = {
|
|
fn test(_: ()) {}
|
|
test
|
|
})]
|
|
callback_w_default_val_expr_fn: Callback,
|
|
|
|
#[props(default = Callback::new(move |_: ()| {}))]
|
|
callback_w_default_val_explicit: Callback,
|
|
|
|
#[props(default)]
|
|
event_handler_w_default: EventHandler<KeyboardEvent>,
|
|
|
|
#[props(default = move |_| {})]
|
|
event_handler_w_default_val_closure: EventHandler<KeyboardEvent>,
|
|
|
|
#[props(default = {
|
|
fn test(_: KeyboardEvent) {}
|
|
test
|
|
})]
|
|
event_handler_w_default_val_expr_fn: EventHandler<KeyboardEvent>,
|
|
|
|
#[props(default = EventHandler::new(move |_: KeyboardEvent| {}))]
|
|
event_handler_w_default_val_explicit: EventHandler<KeyboardEvent>,
|
|
}
|
|
}
|
|
|
|
/// This test ensures that read-only signals that contain an option (`Signal<Option<u16>>`)
|
|
/// are correctly created as default when not provided.
|
|
///
|
|
/// These are compile-time tests.
|
|
/// See https://github.com/DioxusLabs/dioxus/issues/2648
|
|
#[cfg(test)]
|
|
#[allow(unused)]
|
|
mod test_optional_signals {
|
|
use dioxus::prelude::*;
|
|
|
|
// Test if test components fail to compile.
|
|
#[component]
|
|
fn UsesComponents() -> Element {
|
|
rsx! {
|
|
PropsStruct {
|
|
regular_read_signal: ReadSignal::new(Signal::new(1234)),
|
|
}
|
|
PropsStruct {
|
|
optional_read_signal: 1234,
|
|
regular_read_signal: 123u16,
|
|
}
|
|
PropParams {}
|
|
PropParams {
|
|
opt_read_sig: 1234
|
|
}
|
|
DoubleOption {}
|
|
DoubleOption { optional: Some(1234) }
|
|
}
|
|
}
|
|
|
|
// Test props as struct param.
|
|
#[derive(Props, Clone, PartialEq)]
|
|
struct MyTestProps {
|
|
pub optional_read_signal: ReadSignal<Option<u16>>,
|
|
pub regular_read_signal: ReadSignal<u16>,
|
|
}
|
|
|
|
#[component]
|
|
fn PropsStruct(props: MyTestProps) -> Element {
|
|
rsx! { "hi" }
|
|
}
|
|
|
|
// Test props as params.
|
|
#[component]
|
|
fn PropParams(opt_read_sig: ReadSignal<Option<u16>>) -> Element {
|
|
rsx! { "hi!" }
|
|
}
|
|
|
|
#[component]
|
|
fn DoubleOption(optional: Option<Option<u16>>) -> Element {
|
|
rsx! { "hi!" }
|
|
}
|
|
}
|