component.rs 962 B

123456789101112131415161718192021222324252627282930313233
  1. //! This file handles the supporting infrastructure for the `Component` trait and `Properties` which makes it possible
  2. //! for components to be used within Nodes.
  3. //!
  4. //! Note - using the builder pattern does not required the Properties trait to be implemented - the only thing that matters is
  5. //! if the type suppports PartialEq. The Properties trait is used by the rsx! and html! macros to generate the type-safe builder
  6. //! that ensures compile-time required and optional fields on props.
  7. use crate::innerlude::FC;
  8. pub type ScopeIdx = generational_arena::Index;
  9. pub trait Properties: PartialEq {
  10. type Builder;
  11. fn builder() -> Self::Builder;
  12. }
  13. pub struct EmptyBuilder;
  14. impl EmptyBuilder {
  15. pub fn build(self) -> () {
  16. ()
  17. }
  18. }
  19. impl Properties for () {
  20. type Builder = EmptyBuilder;
  21. fn builder() -> Self::Builder {
  22. EmptyBuilder {}
  23. }
  24. }
  25. pub fn fc_to_builder<T: Properties>(f: FC<T>) -> T::Builder {
  26. T::builder()
  27. }