-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Feature Request
Description
Currently, Dioxus Signals lacks a Writable::map
feature, making it difficult to derive a Signal<T>
from a parent Signal<Vec<T>>
. This is particularly important in scenarios like dynamic form generation or nested component state management, where child components require fine-grained reactivity while maintaining synchronization with the parent state.
For example, a parent component may receive a Signal<Vec<T>>
and need to pass individual Signal<T>
to its children. The lack of Writable::map
forces developers to pass the Signal<Vec<T>>
and the index separately and manually index into the vector on every access.
Implement Suggestion
Introduce a Writable::map
function to create a mutable view into a subset of a signalized structure. With this, developers can map a Signal<Vec<T>>
to individual Signal<T>
for child components in an ergonomic and efficient manner.
Example:
forms_signal.map_mut(move |forms| &mut forms[index])
This approach would simplify the following common use case:
#[component]
fn ParentComponent(props: ParentProps) -> Element {
let forms_signal = props.forms_signal;
rsx! {
div {
forms_signal.read().iter().enumerate().map(|(index, form)| rsx!(
ChildComponent {
form_signal: ???, // Derive Signal<T> here
}
))
}
}
}
With Writable::map
, it becomes easy to pass individual signals to children while ensuring modifications in children sync back to the parent signalized vector.
Why This Feature Matters
This feature is crucial for:
- Dynamic form generation (e.g., JSON-driven forms).
- Nested component state management.
- Any pattern requiring signalized collections with fine-grained reactivity.
It improves code ergonomics, reduces verbosity, and minimizes potential errors from manual indexing.
Workaround
Currently, developers can pass the Signal<Vec<T>>
and index separately to child components and manually index into the vector. However, this approach is less ergonomic and more verbose compared to having a dedicated Writable::map
.
Related Discussions and Issues
- Discussion #3570
- Related Issue: Common reactive interface #1805
You can now submit this issue on the project’s GitHub!