-
Notifications
You must be signed in to change notification settings - Fork 570
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8b78405
First cut at request_update
raphlinus 2ca7dca
Clear up parent/child context confusion
raphlinus 6c88295
Clean up patch
raphlinus 7c57604
Merge branch 'master' into request_update
raphlinus 800fe1c
Fix commit number
raphlinus 49fdad4
Add test
raphlinus bb47a0e
Doc update, per review
raphlinus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -463,3 +463,27 @@ fn register_after_adding_child() { | |
assert_eq!(harness.get_state(id_5).children.entry_count(), 5); | ||
}) | ||
} | ||
|
||
#[test] | ||
/// Test that request_update actually causes the request. | ||
fn request_update() { | ||
const REQUEST_UPDATE: Selector = Selector::new("druid-tests.request_update"); | ||
let updated: Rc<Cell<bool>> = Default::default(); | ||
let updated_clone = updated.clone(); | ||
|
||
let widget = ModularWidget::new(()) | ||
.event_fn(|_, ctx, event, _data, _env| { | ||
if matches!(event, Event::Command(cmd) if cmd.is(REQUEST_UPDATE)) { | ||
ctx.request_update(); | ||
} | ||
}) | ||
.update_fn(move |_, _ctx, _old_data, _data, _env| { | ||
updated_clone.set(true); | ||
}); | ||
Harness::create_simple((), widget, |harness| { | ||
harness.send_initial_events(); | ||
assert!(!updated.get()); | ||
harness.submit_command(REQUEST_UPDATE, None); | ||
assert!(updated.get()); | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice to see how straight forward and readable this is. |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.