//! Types related to the DOM.

use crate::dom::element::DomElement;

pub mod dialog;
pub mod element;
pub mod event;
pub mod text;

pub mod node;
pub mod node_list;

/// A component output function's DOM element output.
pub trait DomOutput {
    /// Create the DOM element.
    fn create_element(self) -> DomElement;

    /// Rerender the DOM element.
    fn render(self, element: DomElement);
}

/// A function for creating and a function for rerendering a DOM element.
pub struct DomElementCreateAndRender<CreateFn, RenderFn>
where
    CreateFn: FnOnce() -> DomElement,
    RenderFn: FnOnce(DomElement),
{
    /// Create the DOM element.
    pub create: CreateFn,
    /// Rerender the DOM element.
    pub render: RenderFn,
}

impl<CreateFn, RenderFn> DomOutput for DomElementCreateAndRender<CreateFn, RenderFn>
where
    CreateFn: FnOnce() -> DomElement,
    RenderFn: FnOnce(DomElement),
{
    fn create_element(self) -> DomElement {
        (self.create)()
    }

    fn render(self, element: DomElement) {
        (self.render)(element)
    }
}
