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

fix(core): 🐛 split state not notify data, but notify framework #492

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions core/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,28 +526,31 @@ mod tests {
let track_split = Sc::new(Cell::new(0));

let c_origin = track_origin.clone();
origin.modifies().subscribe(move |_| {
c_origin.set(c_origin.get() + 1);
origin.modifies().subscribe(move |s| {
c_origin.set(c_origin.get() + s.bits());
});

let c_split = track_split.clone();
split.modifies().subscribe(move |_| {
c_split.set(c_split.get() + 1);
split.modifies().subscribe(move |s| {
c_split.set(c_split.get() + s.bits());
});

*split.write() = 1;
*split.write() = 0;
Timer::wake_timeout_futures();
AppCtx::run_until_stalled();

assert_eq!(track_origin.get(), 0);
assert_eq!(track_split.get(), 1);
assert_eq!(track_origin.get(), ModifyScope::DATA.bits());
assert_eq!(track_split.get(), ModifyScope::BOTH.bits());

origin.write().b = 1;
origin.write().b = 0;
Timer::wake_timeout_futures();
AppCtx::run_until_stalled();
assert_eq!(track_origin.get(), 1);
assert_eq!(
track_origin.get(),
ModifyScope::DATA.bits() + ModifyScope::BOTH.bits()
);
// splitted downstream will not be notified.
assert_eq!(track_split.get(), 1);
assert_eq!(track_split.get(), ModifyScope::BOTH.bits());
}

#[test]
Expand Down
11 changes: 10 additions & 1 deletion core/src/state/splitted_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ where
self.create_at > self.origin.time_stamp(),
"A splitted writer is invalid because its origin state is modified after it created."
);

let modify_scope = orig.modify_scope;

// the origin mark as a silent write, because split writer not effect the origin
// state in ribir framework level. But keep notify in the data level.
assert!(!orig.modified);
orig.modify_scope.remove(ModifyScope::FRAMEWORK);
orig.modified = true;

let value = orig
.value
.take()
Expand All @@ -191,7 +200,7 @@ where
WriteRef {
value,
modified: false,
modify_scope: orig.modify_scope,
modify_scope,
control: self,
}
}
Expand Down
2 changes: 1 addition & 1 deletion macros/src/pipe_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl ToTokens for PipeMacro {
#refs
let _ctx_handle_ಠ_ಠ = ctx!().handle();
MapPipe::new(
ModifiesPipe::new(#upstream.box_it()),
ModifiesPipe::new(#upstream.filter(|s| s.contains(ModifyScope::FRAMEWORK)).box_it()),
move |_: ModifyScope| {
_ctx_handle_ಠ_ಠ
.with_ctx(|ctx!(): &BuildCtx<'_>| { #(#expr)* })
Expand Down