Skip to content

Commit

Permalink
refactor: rename pre-diff to prediff
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanceras committed Mar 2, 2024
1 parent 0b1945c commit d69a8a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion crates/sauron-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ with-ric = [] # use of request_idle_callback in javascript
with-raf = [] # use of request_animation_frame in javascript
with-interning = [] # use caching of strings when crossing rust to js, for faster transfer
custom_element = [] # use of register_custom_element, adding this will add the js snippets
pre-diff = [] # diffing optimization
prediff = [] # diffing optimization

[dev-dependencies]
wasm-bindgen-test = "0.3"
Expand Down
9 changes: 4 additions & 5 deletions crates/sauron-core/src/dom/application.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use crate::dom::Cmd;
use crate::vdom::Node;
pub use pre_diff::{diff_if, PreDiff};
pub use prediff::{diff_if, PreDiff};

mod pre_diff;
mod prediff;


/// An Application is the root component of your program.
/// Everything that happens in your application is done here.
///
//#[cfg(not(feature = "pre-diff"))]
pub trait Application<MSG> : Sized + 'static
where
MSG: 'static,
Expand All @@ -28,8 +27,8 @@ where
/// an optimization solution.
/// pre evaluate the expression to determine
/// whether to diff the nodes
#[cfg(feature = "pre-diff")]
fn pre_diff(&self, _other: &Self) -> Option<Vec<PreDiff>> {
#[cfg(feature = "prediff")]
fn prediff(&self, _other: &Self) -> Option<Vec<PreDiff>> {
None
}

Expand Down
12 changes: 6 additions & 6 deletions crates/sauron-core/src/dom/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::dom::program::app_context::WeakContext;
use crate::dom::request_animation_frame;
#[cfg(feature = "with-ric")]
use crate::dom::request_idle_callback;
#[cfg(feature = "pre-diff")]
#[cfg(feature = "prediff")]
use crate::dom::PreDiff;
use crate::dom::{document, now, IdleDeadline, Measurements, Modifier};
use crate::dom::{util::body, AnimationFrameHandle, Application, DomPatch, IdleCallbackHandle};
Expand Down Expand Up @@ -715,7 +715,7 @@ where
}

/// clone the app
#[cfg(feature = "pre-diff")]
#[cfg(feature = "prediff")]
#[allow(unsafe_code)]
pub fn app_clone(&self) -> ManuallyDrop<APP> {
unsafe{
Expand All @@ -737,7 +737,7 @@ where
/// - The view is reconstructed with the new state of the app.
/// - The dom is updated with the newly reconstructed view.
fn dispatch_inner(&mut self, deadline: Option<IdleDeadline>) {
#[cfg(feature = "pre-diff")]
#[cfg(feature = "prediff")]
let old_app = self.app_clone();
self.dispatch_pending_msgs(deadline)
.expect("must dispatch msgs");
Expand All @@ -750,13 +750,13 @@ where
panic!("Can not proceed until previous pending msgs are dispatched..");
}

#[cfg(feature = "pre-diff")]
let treepath = self.app().pre_diff(&old_app).map(|eval| {
#[cfg(feature = "prediff")]
let treepath = self.app().prediff(&old_app).map(|eval| {
log::debug!("eval: {eval:#?}");
PreDiff::traverse(&eval)
});

#[cfg(not(feature = "pre-diff"))]
#[cfg(not(feature = "prediff"))]
let treepath = None;

let cmd = self.app_context.batch_pending_cmds();
Expand Down

0 comments on commit d69a8a9

Please sign in to comment.