Skip to content

Commit

Permalink
fix(core): 🐛 split state not notify data, but notify framework
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Nov 30, 2023
1 parent 1c1c5e8 commit 1e83dc8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
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

0 comments on commit 1e83dc8

Please sign in to comment.