Skip to content

Commit

Permalink
feat(core): 🎸 supports Provider to dirty the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Adoo committed Jan 10, 2025
1 parent 676e098 commit 5c563bc
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 71 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he
### Features

- **core**: The `Render::dirty_phase` method has been added to allow widgets to mark only the paint phase as dirty when it is modified. (#689 @M-Adoo)
- **core**: Supports `Provider` to dirty the tree if it's a state writer. (#pr @M-Adoo)
- **macros**: Added the `part_reader!` macro to generate a partial reader from a reference of a reader. (#688 @M-Adoo)
- **macros**: The `simple_declare` now supports the `stateless` meta attribute, `#[simple_declare(stateless)]`. (#688 @M-Adoo)

Expand Down
20 changes: 17 additions & 3 deletions core/src/builtin_widgets/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
//! App::run(w).with_app_theme(theme);
//! ```
use std::hash::Hash;
use std::{convert::Infallible, hash::Hash};

use data_widget::AnonymousAttacher;
use ops::box_it::CloneableBoxOp;
use pipe::PipeNode;
use smallvec::{SmallVec, smallvec};

Expand Down Expand Up @@ -186,6 +187,12 @@ impl ProviderSetup for Classes {
let classes = Box::new(Setup::new(*self)).setup(map);
Box::new(ClassesRestore { overrides, classes })
}

fn unzip(
self: Box<Self>,
) -> (Box<dyn ProviderSetup>, DirtyPhase, CloneableBoxOp<'static, ModifyScope, Infallible>) {
unreachable!();
}
}

impl<R: StateReader<Value = Classes> + Query> ProviderSetup for ClassesReaderSetup<R> {
Expand All @@ -195,6 +202,12 @@ impl<R: StateReader<Value = Classes> + Query> ProviderSetup for ClassesReaderSet
let classes = Box::new(Setup::from_state(classes)).setup(map);
Box::new(ClassesRestore { overrides, classes })
}

fn unzip(
self: Box<Self>,
) -> (Box<dyn ProviderSetup>, DirtyPhase, CloneableBoxOp<'static, ModifyScope, Infallible>) {
unreachable!();
}
}

impl ProviderRestore for ClassesRestore {
Expand Down Expand Up @@ -271,7 +284,8 @@ impl Class {
/// };
/// ```
pub fn provider(name: ClassName, cls_impl: ClassImpl) -> Provider {
Provider::custom(name.type_info(), Box::new(Queryable(cls_impl)))
let setup = Setup::custom(name.type_info(), Box::new(Queryable(cls_impl)));
Provider::Setup(Box::new(setup))
}

fn apply_style<'a>(&self, w: Widget<'a>) -> Widget<'a> {
Expand Down Expand Up @@ -421,7 +435,7 @@ mod tests {
}

impl Classes {
fn into_provider(self) -> Provider { Provider::Setup(Box::new(Setup::new(self))) }
fn into_provider(self) -> Provider { Provider::new(self) }
}

#[test]
Expand Down
8 changes: 4 additions & 4 deletions core/src/builtin_widgets/painting_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ impl<'c> ComposeChild<'c> for PaintingStyleWidget {
// We need to provide the text style for the children to access.
let provider = match this.try_into_value() {
Ok(this) => Provider::new(this.painting_style),
Err(this) => {
let style = this.map_reader(|w| PartData::from_ref(&w.painting_style));
Provider::value_of_state(style)
}
Err(this) => Provider::value_of_writer(
this.map_writer(|w| PartData::from_ref_mut(&mut w.painting_style)),
Some(DirtyPhase::LayoutSubtree),
),
};

Providers::new([provider])
Expand Down
Loading

0 comments on commit 5c563bc

Please sign in to comment.