Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.7] Implement Into<Signal<T>> & Into<MaybeSignal<T>> for stores and their fields #2947

Open
brofrain opened this issue Sep 7, 2024 · 2 comments

Comments

@brofrain
Copy link
Contributor

brofrain commented Sep 7, 2024

Is your feature request related to a problem? Please describe.
MaybeSignal is a convenient wrapper for both dynamic and static values. All the primitive signals implement Into<MaybeSignal<T>> except for the newly added stores.

Describe the solution you'd like
All of the store-related types (Field, AtIndex, Subfield and Store) should be convertible to MaybeSignal using Into trait, so for example they can be used with #[prop(into)] value: MaybeSignal<T> syntax.

@brofrain
Copy link
Contributor Author

brofrain commented Sep 7, 2024

@gbj
From my observations, converting a Memo / RwSignal / ... to Signal / MaybeSignal usually comes down to creating an inner SignalTypes wrapping the original signal. With reactive_stores a new approach may be needed, because reactive_graph is a dependency of reactive_stores, so SignalTypes cannot be expanded by a new variant.
Could you give me some hints on how to tackle this properly?

@gbj
Copy link
Collaborator

gbj commented Sep 7, 2024

It can just use Signal::derive() and MaybeSignal::derive().

Something like this:

impl<T> From<Field<T>> for Signal<T> where T: Clone {
  fn from(value: Field<T>) -> Signal<T> {
    Signal::derive(move || value.get())
  } 
}

brofrain added a commit to brofrain/leptos that referenced this issue Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants