Skip to content

Commit

Permalink
Reuse Transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Dec 3, 2019
1 parent 9ed69e4 commit 946016b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crates/macro/src/html_tree/html_tag/tag_attributes.rs
Expand Up @@ -127,7 +127,7 @@ impl Parse for TagAttributes {
let callback = listener.value;
listeners.push(quote_spanned! {name.span()=>
::yew::html::#name::Wrapper::new(
<::yew::virtual_dom::vtag::VTag as ::yew::virtual_dom::vtag::Transformer<_, _>>::transform(
<::yew::virtual_dom::vtag::VTag as ::yew::virtual_dom::Transformer<_, _>>::transform(
#callback
)
)
Expand Down
6 changes: 6 additions & 0 deletions src/virtual_dom/mod.rs
Expand Up @@ -194,3 +194,9 @@ pub trait VDiff {
ancestor: Option<VNode>,
) -> Option<Node>;
}

/// Transform properties to the expected type.
pub trait Transformer<FROM, TO> {
/// Transforms one type to another.
fn transform(from: FROM) -> TO;
}
8 changes: 1 addition & 7 deletions src/virtual_dom/vcomp.rs
@@ -1,6 +1,6 @@
//! This module contains the implementation of a virtual component `VComp`.

use super::{VDiff, VNode};
use super::{Transformer, VDiff, VNode};
use crate::html::{Component, ComponentUpdate, HiddenScope, NodeRef, Scope};
use std::any::TypeId;
use std::cell::RefCell;
Expand Down Expand Up @@ -235,12 +235,6 @@ impl VDiff for VComp {
}
}

/// Transform properties to the expected type.
pub trait Transformer<FROM, TO> {
/// Transforms one type to another.
fn transform(from: FROM) -> TO;
}

impl<T> Transformer<T, T> for VComp {
fn transform(from: T) -> T {
from
Expand Down
10 changes: 3 additions & 7 deletions src/virtual_dom/vtag.rs
@@ -1,6 +1,8 @@
//! This module contains the implementation of a virtual element node `VTag`.

use super::{Attributes, Classes, Listener, Listeners, Patch, Reform, VDiff, VList, VNode};
use super::{
Attributes, Classes, Listener, Listeners, Patch, Reform, Transformer, VDiff, VList, VNode,
};
use crate::html::NodeRef;
use log::warn;
use std::borrow::Cow;
Expand Down Expand Up @@ -534,12 +536,6 @@ pub(crate) fn not<T>(option: &Option<T>) -> &Option<()> {
}
}

/// Transform properties to the expected type.
pub trait Transformer<FROM, TO> {
/// Transforms one type to another.
fn transform(from: FROM) -> TO;
}

impl<T> Transformer<T, T> for VTag {
fn transform(from: T) -> T {
from
Expand Down

0 comments on commit 946016b

Please sign in to comment.