-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
xilem_html: Introduce DOM interface traits to make per DOM element ty…
…ping possible and flexible
- Loading branch information
Showing
25 changed files
with
1,496 additions
and
1,254 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use std::borrow::Cow; | ||
|
||
use xilem_core::{Id, MessageResult}; | ||
|
||
use crate::{sealed::Sealed, AttributeValue, ChangeFlags, Cx, View, ViewMarker}; | ||
|
||
use super::interfaces::{for_all_dom_interfaces, Element}; | ||
|
||
pub struct Attr<E> { | ||
pub(crate) element: E, | ||
pub(crate) name: Cow<'static, str>, | ||
pub(crate) value: Option<AttributeValue>, | ||
} | ||
|
||
impl<E> ViewMarker for Attr<E> {} | ||
impl<E> Sealed for Attr<E> {} | ||
|
||
impl<T, A, E: Element<T, A>> View<T, A> for Attr<E> { | ||
type State = E::State; | ||
type Element = E::Element; | ||
|
||
fn build(&self, cx: &mut Cx) -> (Id, Self::State, Self::Element) { | ||
cx.add_new_attribute_to_current_element(&self.name, &self.value); | ||
self.element.build(cx) | ||
} | ||
|
||
fn rebuild( | ||
&self, | ||
cx: &mut Cx, | ||
prev: &Self, | ||
id: &mut Id, | ||
state: &mut Self::State, | ||
element: &mut Self::Element, | ||
) -> ChangeFlags { | ||
cx.add_new_attribute_to_current_element(&self.name, &self.value); | ||
self.element.rebuild(cx, &prev.element, id, state, element) | ||
} | ||
|
||
fn message( | ||
&self, | ||
id_path: &[Id], | ||
state: &mut Self::State, | ||
message: Box<dyn std::any::Any>, | ||
app_state: &mut T, | ||
) -> MessageResult<A> { | ||
self.element.message(id_path, state, message, app_state) | ||
} | ||
} | ||
|
||
macro_rules! impl_dom_interface_for_attr { | ||
($dom_interface:ident) => { | ||
impl<T, A, E: $crate::interfaces::$dom_interface<T, A>> | ||
$crate::interfaces::$dom_interface<T, A> for Attr<E> | ||
{ | ||
} | ||
}; | ||
} | ||
|
||
for_all_dom_interfaces!(impl_dom_interface_for_attr); |
2 changes: 1 addition & 1 deletion
2
...xilem_html/src/element/attribute_value.rs → crates/xilem_html/src/attribute_value.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.