Skip to content

How to initialize a state of a complex lazy component, directly after components constructor call? #1951

Closed Answered by nicksenger
AlphaAmphib asked this question in Q&A
Discussion options

You must be logged in to vote

If I'm understanding correctly, you want to create a component which manages some internal state, but also expose the ability for its creator to customize that state in the initial view call that produces the component.

That's definitely possible, but Iced will, by way of the type system, force you to address potential awkward behaviors that could come about from doing it.

Let's say the state is type T: you can do what you want by setting the State associated type on the component trait to SomeNewType(Option<T>). The requirement for T to implement default can be avoided by implementing the Default trait manually for "SomeNewType." Then, store &T on whatever struct it is you are implementing

Replies: 5 comments 16 replies

Comment options

You must be logged in to vote
1 reply
@AlphaAmphib
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@AlphaAmphib
Comment options

@lufte
Comment options

@AlphaAmphib
Comment options

@AlphaAmphib
Comment options

Comment options

You must be logged in to vote
11 replies
@AlphaAmphib
Comment options

@nicksenger
Comment options

@AlphaAmphib
Comment options

@nicksenger
Comment options

Answer selected by AlphaAmphib
@AlphaAmphib
Comment options

@nicksenger
Comment options

@AlphaAmphib
Comment options

@nicksenger
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants