Skip to content

Commit 9c46a3c

Browse files
cursoragentlovasoa
andcommitted
Refactor dynamic component property extraction
Co-authored-by: contact <[email protected]>
1 parent 863852e commit 9c46a3c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/dynamic_component.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ fn extract_dynamic_properties(data: &mut JsonValue) -> anyhow::Result<Option<Jso
8383
.or_else(|| data.get("COMPONENT"))
8484
.and_then(|v| v.as_str());
8585
if component == Some("dynamic") {
86-
let Some(properties) = data
87-
.get_mut("properties")
88-
.or_else(|| data.get_mut("PROPERTIES"))
89-
.map(JsonValue::take)
90-
else {
86+
let properties_opt = if let Some(v) = data.get_mut("properties") {
87+
Some(v.take())
88+
} else if let Some(v) = data.get_mut("PROPERTIES") {
89+
Some(v.take())
90+
} else {
91+
None
92+
};
93+
let Some(properties) = properties_opt else {
9194
anyhow::bail!(
9295
"The dynamic component requires a property named \"properties\". \
9396
Instead, it received the following: {data}"

src/render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use anyhow::{bail, format_err, Context as AnyhowContext};
5454
use awc::cookie::time::Duration;
5555
use handlebars::{BlockContext, JsonValue, RenderError, Renderable};
5656
use serde::Serialize;
57-
use serde_json::{json, Value};
57+
use serde_json::json;
5858
use std::borrow::Cow;
5959
use std::convert::TryFrom;
6060
use std::fmt::Write as _;

0 commit comments

Comments
 (0)