Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change type of InstanceBuilder.properties to Vec<(Ustr, Variant)> #467

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rbx_dom_weak/src/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl WeakDom {
parent,
name: builder.name,
class: builder.class,
properties: builder.properties,
properties: builder.properties.into_iter().collect(),
},
);

Expand Down
17 changes: 8 additions & 9 deletions rbx_dom_weak/src/instance.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use rbx_types::{Ref, Variant};
use ustr::{Ustr, UstrMap};

use crate::UstrMapExt;

/**
Represents an instance that can be turned into a new
[`WeakDom`][crate::WeakDom], or inserted into an existing one.
Expand Down Expand Up @@ -37,7 +35,7 @@ pub struct InstanceBuilder {
pub(crate) referent: Ref,
pub(crate) name: String,
pub(crate) class: Ustr,
pub(crate) properties: UstrMap<Variant>,
pub(crate) properties: Vec<(Ustr, Variant)>,
pub(crate) children: Vec<InstanceBuilder>,
}

Expand All @@ -52,7 +50,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: UstrMap::new(),
properties: Vec::new(),
children: Vec::new(),
}
}
Expand All @@ -67,7 +65,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name,
class,
properties: UstrMap::with_capacity(capacity),
properties: Vec::with_capacity(capacity),
children: Vec::new(),
}
}
Expand All @@ -78,7 +76,7 @@ impl InstanceBuilder {
referent: Ref::new(),
name: String::new(),
class: Ustr::default(),
properties: UstrMap::new(),
properties: Vec::new(),
children: Vec::new(),
}
}
Expand Down Expand Up @@ -124,18 +122,19 @@ impl InstanceBuilder {

/// Add a new property to the `InstanceBuilder`.
pub fn with_property<K: Into<Ustr>, V: Into<Variant>>(mut self, key: K, value: V) -> Self {
self.properties.insert(key.into(), value.into());
self.properties.push((key.into(), value.into()));
self
}

/// Add a new property to the `InstanceBuilder`.
pub fn add_property<K: Into<Ustr>, V: Into<Variant>>(&mut self, key: K, value: V) {
self.properties.insert(key.into(), value.into());
self.properties.push((key.into(), value.into()));
}

/// Check if the `InstanceBuilder` already has a property with the given key.
pub fn has_property<K: Into<Ustr>>(&self, key: K) -> bool {
self.properties.contains_key(&key.into())
let key = key.into();
self.properties.iter().any(|(k, _)| *k == key)
}

/// Add multiple properties to the `InstanceBuilder` at once.
Expand Down