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

Optimize the default change implementation #690

Merged
merged 2 commits into from
Oct 13, 2019
Merged
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
9 changes: 5 additions & 4 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub use scope::{NodeCell, Scope};

use crate::callback::Callback;
use crate::virtual_dom::{VChild, VList, VNode};
use std::any::TypeId;
use std::fmt;

/// This type indicates that component should be rendered again.
Expand All @@ -37,10 +38,10 @@ pub trait Component: Sized + 'static {
/// Called when the component's parent component re-renders and the
/// component's place in the DOM tree remains unchanged. If the component's
/// place in the DOM tree changes, calling this method is unnecessary as the
/// component is recreated from scratch. It defaults
/// to true if not implemented.
fn change(&mut self, _: Self::Properties) -> ShouldRender {
true
/// component is recreated from scratch. It defaults to true if not implemented
/// and Self::Properties is not the unit type `()`.
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
TypeId::of::<Self::Properties>() != TypeId::of::<()>()
}
/// Called by rendering loop.
fn view(&self) -> Html<Self>;
Expand Down