Skip to content

Provide &Dependency to Lazy widget view fn#1646

Merged
hecrj merged 1 commit intoiced-rs:masterfrom
nicksenger:feat/dependency-in-lazy
Jan 12, 2023
Merged

Provide &Dependency to Lazy widget view fn#1646
hecrj merged 1 commit intoiced-rs:masterfrom
nicksenger:feat/dependency-in-lazy

Conversation

@nicksenger
Copy link
Contributor

This is a small ergonomics improvement that I noticed would be beneficial when working with the Lazy widget. The change is just to call the provided view function with a reference to the specified Dependency.

This is useful when the data provided for Dependency originates from the widget tree state, and so we don't have a reference to it which lives for the required 'a lifetime bound on Dependency. In this case we need to take ownership of the data to use it for Dependency. Unfortunately, the provided view function must also satisfy the 'a bound, so the data needs to be cloned again if we want to move it into the view function for use there.

By providing view with a reference to the dependency stored in the lazy widget, we can defer this second clone until the cache is actually invalidated rather than doing it on every view. I think it also makes using Lazy a bit more intuitive.

I'd be happy to write an RFC if more explanation/examples are required to make this change

@nicksenger nicksenger changed the title Provide &Dependency to Lazy widget View Provide &Dependency to Lazy widget view fn Jan 11, 2023
@hecrj hecrj added the feature New feature or request label Jan 12, 2023
@hecrj hecrj added this to the 0.7.0 milestone Jan 12, 2023
@hecrj hecrj added the widget label Jan 12, 2023
Copy link
Member

@hecrj hecrj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense! Thanks 🙇

@hecrj hecrj merged commit 902131e into iced-rs:master Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request widget

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments