Skip to content

Commit 2357eb2

Browse files
committed
Made several El methods chainable. Fixed bug in El.set_text.
1 parent 4a71e90 commit 2357eb2

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ and `El::new_text` respectively
99
in addition to semicolons
1010
- Fixed typos in a few attributes (Breaking)
1111
- Fixed a bug where an HTML namespace was applied to raw html/markdown elements
12-
- New conditionaln syntax added in `class!` macro: ``
12+
- New conditional syntax added in `class!` macro, similar to `Elm`'s `classList`
1313
- `Listener` now implements `MessageMapper`
14+
- `El methods` `add_child`, `add_style`, `add_attr`, and `set_text` now return the elements,
15+
allowing chaining
16+
- Fixed a bug with `set_text`
1417

1518

1619
## v0.3.6

CONTRIBUTING.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ Required tools to build and test:
99

1010
Before submitting a PR, please run `cargo make verify`: This will run `fmt`, `clippy`, build all examples, and run all tests.
1111

12-
We're currently moving quickly and making breaking API changes, when appropriate.
12+
Recommended starting points:
13+
- Open issues
14+
- Adding and improving tests
15+
- Friction points in your Seed apps
16+
- `//todo` comments in code
17+

examples/server_integration/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/window_events/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ fn update(msg: Msg, model: &mut Model, _: &mut Orders<Msg>) {
4141
/// This func demonstrates use of custom element tags, and the class! and
4242
/// id! convenience macros
4343
fn misc_demo() -> El<Msg> {
44-
let mut custom_el = El::empty(Tag::Custom("mytag".into()));
45-
custom_el.set_text(""); // Demo of set_text.
44+
let custom_el = El::empty(Tag::Custom("mytag".into())).set_text(""); // Demo of set_text.
4645

4746
let mut attributes = attrs! {};
4847
attributes.add_multiple(At::Class, &["a-modicum-of", "hardly-any"]);

src/dom_types.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -835,23 +835,28 @@ impl<Ms> El<Ms> {
835835
}
836836

837837
/// Add a new child to the element
838-
pub fn add_child(&mut self, element: El<Ms>) {
838+
pub fn add_child(mut self, element: El<Ms>) -> Self {
839839
self.children.push(element);
840+
self
840841
}
841842

842843
/// Add an attribute (eg class, or href)
843-
pub fn add_attr(&mut self, key: String, val: String) {
844+
pub fn add_attr(mut self, key: String, val: String) -> Self {
844845
self.attrs.vals.insert(key.into(), val);
846+
self
845847
}
846848

847849
/// Add a new style (eg display, or height)
848-
pub fn add_style(&mut self, key: String, val: String) {
850+
pub fn add_style(mut self, key: String, val: String) -> Self {
849851
self.style.vals.insert(key, val);
852+
self
850853
}
851854

852855
/// Replace the element's text node. (ie between the HTML tags)
853-
pub fn set_text(&mut self, text: &str) {
854-
self.text = Some(text.into())
856+
pub fn set_text(mut self, text: &str) -> Self {
857+
// todo: Allow text to be impl ToString?
858+
self.children.push(El::new_text(text));
859+
self
855860
}
856861

857862
/// Shortcut for finding the key, if one exists

0 commit comments

Comments
 (0)