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

First cut at request_update #1128

Merged
merged 7 commits into from
Aug 20, 2020
Merged

First cut at request_update #1128

merged 7 commits into from
Aug 20, 2020

Conversation

raphlinus
Copy link
Contributor

Fixes #1073. This version is largely for discussion, as it hasn't been
tested at all.

Fixes #1073. This version is largely for discussion, as it hasn't been
tested at all.
///
/// After this, `update` will be called on the widget in the next update cycle, even
/// if there's not a data change.
pub fn request_update<T, W>(&mut self) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Generic parameters aren't needed here

@rjwittams
Copy link
Collaborator

This does now work for e.g Tabs in my binding-scroll branch

Remove the `request_update_child` variant, as it likely won't be used.
Add changelog.
I forgot a commit number was already assigned, as this was in draft.

Also remove generic parameters, as per review.
@raphlinus raphlinus marked this pull request as ready for review August 20, 2020 15:55
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

If this is a case we need to support (and zulip conversation is convincing), then this patch looks good to me, modulo some slightly scarier docs.

Comment on lines 476 to 479
if let Event::Command(cmd) = event {
if cmd.is(REQUEST_UPDATE) {
ctx.request_update();
}
Copy link
Member

Choose a reason for hiding this comment

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

I would now probably write this as,

if matches!(event, Event::Command(cmd) if cmd.is(REQUEST_UPDATE)) {
    ctx.request_update();
}

but either works I think.

/// Request an update cycle.
///
/// After this, `update` will be called on the widget in the next update cycle, even
/// if there's not a data change.
Copy link
Member

Choose a reason for hiding this comment

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

I think it's worth highlighting that this method is only exposed for special cases, such as when a container widget is synthesizing data for its children, and that in general it should be unnecessary/avoided.

assert!(!updated.get());
harness.submit_command(REQUEST_UPDATE, None);
assert!(updated.get());
})
Copy link
Member

Choose a reason for hiding this comment

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

nice to see how straight forward and readable this is.

@raphlinus raphlinus merged commit ad78b8b into master Aug 20, 2020
@raphlinus raphlinus deleted the request_update branch August 20, 2020 16:36
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.

Updating child widgets?
3 participants