Skip to content

Setting Default For Signal Props Is Verbose #3920

@DogeDark

Description

@DogeDark

Request

If you have a ReadOnlySignal<bool> or Signal<bool>, it can be verbose to use the #[props(default = x)] syntax. For example:

#[derive(Props, Clone, PartialEq)]
pub struct SomeProps {

    // This sets bool to be false
    #[props(default)] 
    value: ReadOnlySignal<bool>,

    // This is what I'd like, except it wants a ReadOnlySignal
    #[props(default = true)] 
    value: ReadOnlySignal<bool>,

    // Instead you have to do this:
    #[props(default = ReadOnlySignal::new(Signal::new(true)))]
    value: ReadOnlySignal<bool>,

   // Same for signals:
   #[props(default = Signal::new(true))]
   value: Signal<bool>,
}

Implement Suggestion

Detect if the prop type is a ReadOnlySignal or Signal and automatically create boilerplate code, injecting the provided expression as the input to the ::new functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions