Update the text in window_dom.rs

This commit is contained in:
Keavon Chambers
2020-11-01 01:45:01 -07:00
parent 24b79d7e97
commit 0eed8878ff
+19 -19
View File
@@ -21,12 +21,12 @@ impl<'a> WindowDom<'a> {
fn build_dom_from_component( fn build_dom_from_component(
root_component: &str, root_component: &str,
layout_attributes: &LayoutAttributes, layout_attributes: &LayoutAttributes,
parameters: &Vec<AttributeArg>, props: &Vec<Prop>,
loaded_components: &'a ResourceCache<FlatComponent>, loaded_components: &'a ResourceCache<FlatComponent>,
) -> rctree::Node<DomNode> { ) -> rctree::Node<DomNode> {
// Instantiate the DOM node and put it in a tree node // Instantiate the DOM node and put it in a tree node
let component = loaded_components.get(root_component).unwrap(); let component = loaded_components.get(root_component).unwrap();
let dom_node = DomNode::from_component(component, layout_attributes, parameters); let dom_node = DomNode::from_component(component, layout_attributes, props);
let mut tree = rctree::Node::new(dom_node); let mut tree = rctree::Node::new(dom_node);
// Recursively build the child `DomNode` tree node instances // Recursively build the child `DomNode` tree node instances
@@ -39,7 +39,7 @@ impl<'a> WindowDom<'a> {
let component_name = LayoutSystem::component_name((namespace, name)); let component_name = LayoutSystem::component_name((namespace, name));
// Recursively build the child `DomNode` component instance // Recursively build the child `DomNode` component instance
Self::build_dom_from_component(&component_name[..], &child.layout_arguments, &child.user_arguments, loaded_components) Self::build_dom_from_component(&component_name[..], &child.layout, &child.props, loaded_components)
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
@@ -56,11 +56,11 @@ impl<'a> WindowDom<'a> {
pub struct DomNode { pub struct DomNode {
pub cache_name: String, pub cache_name: String,
pub layout_attributes: LayoutAttributes, pub layout_attributes: LayoutAttributes,
pub variable_bindings: HashMap<String, Vec<TypeValueOrArgument>>, pub variable_bindings: HashMap<String, Vec<TypedValueOrVariableName>>,
} }
impl DomNode { impl DomNode {
pub fn new(cache_name: String, layout_attributes: LayoutAttributes, variable_bindings: HashMap<String, Vec<TypeValueOrArgument>>) -> Self { pub fn new(cache_name: String, layout_attributes: LayoutAttributes, variable_bindings: HashMap<String, Vec<TypedValueOrVariableName>>) -> Self {
Self { Self {
cache_name, cache_name,
layout_attributes, layout_attributes,
@@ -68,36 +68,36 @@ impl DomNode {
} }
} }
pub fn from_component(component: &FlatComponent, layout_attributes: &LayoutAttributes, parameters: &Vec<AttributeArg>) -> Self { pub fn from_component(component: &FlatComponent, layout_attributes: &LayoutAttributes, props: &Vec<Prop>) -> Self {
// Cached name of the loaded component // Cached name of the loaded component
let (namespace, name) = &component.own_info.name; let (namespace, name) = &component.own_info.name;
let cache_name = LayoutSystem::component_name((&namespace[..], &name[..])); let cache_name = LayoutSystem::component_name((&namespace[..], &name[..]));
// Every VARIABLE_NAME binding defined as a parameter on this component // Every VARIABLE_NAME binding defined in the prop definitions on this component
let mut variable_bindings = component let mut variable_bindings = component
.own_info .own_info
.parameters .prop_definitions
.iter() .iter()
.map(|parameter| { .map(|prop_definition| {
( (
// HashMap key is the parameter name // HashMap key is the prop name
parameter.name.clone(), prop_definition.variable_name.clone(),
// HashMap value is the parameter's defined default value // HashMap value is the prop definition's default value
parameter prop_definition
.type_sequence_default .type_sequence_default
.iter() .iter()
.map(|value| TypeValueOrArgument::TypeValue(value.clone())) .map(|value| TypedValueOrVariableName::TypedValue(value.clone()))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
) )
}) })
.collect::<HashMap<_, _>>(); .collect::<HashMap<_, _>>();
// Overwrite the defaults for given parameters // Overwrite the default values for the provided props
for parameter in parameters { for prop in props {
if !variable_bindings.contains_key(&parameter.name[..]) { if !variable_bindings.contains_key(&prop.name[..]) {
panic!("Invalid argument {} given to the {} component", parameter.name, cache_name); panic!("Invalid argument {} given to the {} component", prop.name, cache_name);
} }
variable_bindings.insert(parameter.name.clone(), parameter.value.clone()); variable_bindings.insert(prop.name.clone(), prop.value_sequence.clone());
} }
Self::new(cache_name, layout_attributes.clone(), variable_bindings) Self::new(cache_name, layout_attributes.clone(), variable_bindings)