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

Add the lens component #587

Merged
merged 7 commits into from
Sep 18, 2024
Merged

Add the lens component #587

merged 7 commits into from
Sep 18, 2024

Conversation

DJMcNab
Copy link
Member

@DJMcNab DJMcNab commented Sep 13, 2024

See https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/Lens.20View

Usage:

fn app_logic(state: &mut FlightPlanner) -> impl WidgetView<FlightPlanner> {
    lens(date_picker, state, |state| &mut state.date)
}

struct FlightPlanner {
    date: Date,
    available_flights: Vec<Flight>,
}

Also extends the docs features in Xilem Core, and increases the complexity threshold

@DJMcNab DJMcNab marked this pull request as ready for review September 17, 2024 11:04
Copy link
Contributor

@Philipp-M Philipp-M left a comment

Choose a reason for hiding this comment

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

Quality code as usual. Nice job on the docs.

# The default clippy value for this is 250, which causes warnings for rather simple types
# like Box<dyn Fn(&mut Env, &T)>, which seems overly strict. The new value of 400 is
# a simple guess. It might be worth lowering this, or using the default, in the future.
type-complexity-threshold = 400
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

child: V,
phantom: PhantomData<fn() -> (ParentState, ChildState)>,
phantom: PhantomData<fn(ParentState) -> (ChildState, Action, Context, Message)>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch, has this kind caused issues already in practice?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so, but I could foresee it being troublesome for the tests.

It might have been fine.

I will add a comment that the variance consequences of this have not been reasoned about.

xilem_core/src/views/map_state.rs Outdated Show resolved Hide resolved
/// # struct AppData;
/// fn log_lifecycle(data: &mut AppData) -> impl PhantomView<AppData, (), ViewCtx> {
/// fn log_lifecycle(data: &mut AppData) -> impl WidgetView<AppData, ()> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I just noticed this (+docs.rs), nice trick.

Co-authored-by: Philipp Mildenberger <[email protected]>
@DJMcNab DJMcNab added this pull request to the merge queue Sep 18, 2024
Merged via the queue into linebender:main with commit 0d56c59 Sep 18, 2024
17 checks passed
@DJMcNab DJMcNab deleted the lens branch September 18, 2024 08:16
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

Successfully merging this pull request may close these issues.

2 participants