Skip to content

Commit c5d62a5

Browse files
committed
remove now redundant 'dynamic' handling from the render logic
1 parent 1cdd2de commit c5d62a5

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

src/render.rs

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,12 @@ pub struct RenderContext<W: std::io::Write> {
274274
pub writer: W,
275275
current_component: Option<SplitTemplateRenderer>,
276276
shell_renderer: SplitTemplateRenderer,
277-
recursion_depth: usize,
278277
current_statement: usize,
279278
}
280279

281280
const DEFAULT_COMPONENT: &str = "table";
282281
const PAGE_SHELL_COMPONENT: &str = "shell";
283282
const FRAGMENT_SHELL_COMPONENT: &str = "shell-empty";
284-
const DYNAMIC_COMPONENT: &str = "dynamic";
285-
const MAX_RECURSION_DEPTH: usize = 256;
286283

287284
impl<W: std::io::Write> RenderContext<W> {
288285
pub async fn new(
@@ -293,12 +290,7 @@ impl<W: std::io::Write> RenderContext<W> {
293290
) -> anyhow::Result<RenderContext<W>> {
294291
log::debug!("Creating the shell component for the page");
295292

296-
let mut initial_rows =
297-
if get_object_str(&initial_row, "component") == Some(DYNAMIC_COMPONENT) {
298-
Self::extract_dynamic_properties(&initial_row)?
299-
} else {
300-
vec![Cow::Borrowed(&initial_row)]
301-
};
293+
let mut initial_rows = vec![Cow::Borrowed(&initial_row)];
302294

303295
if !initial_rows
304296
.first()
@@ -336,7 +328,6 @@ impl<W: std::io::Write> RenderContext<W> {
336328
writer,
337329
current_component: None,
338330
shell_renderer,
339-
recursion_depth: 0,
340331
current_statement: 1,
341332
};
342333

@@ -367,11 +358,6 @@ impl<W: std::io::Write> RenderContext<W> {
367358
let new_component = get_object_str(data, "component");
368359
let current_component = self.current_component().await?.name();
369360
match (current_component, new_component) {
370-
(_current_component, Some(DYNAMIC_COMPONENT)) => {
371-
self.render_dynamic(data).await.with_context(|| {
372-
format!("Unable to render dynamic component with properties {data}")
373-
})?;
374-
}
375361
(
376362
_,
377363
Some(
@@ -398,44 +384,6 @@ impl<W: std::io::Write> RenderContext<W> {
398384
Ok(())
399385
}
400386

401-
fn extract_dynamic_properties(data: &Value) -> anyhow::Result<Vec<Cow<'_, JsonValue>>> {
402-
let properties_key = "properties";
403-
let properties_obj = data
404-
.get(properties_key)
405-
.with_context(|| format!("Missing '{properties_key}' key."))?;
406-
Ok(match properties_obj {
407-
Value::String(s) => match serde_json::from_str::<JsonValue>(s).with_context(|| {
408-
format!(
409-
"Unable to parse the 'properties' property of the dynamic component as JSON.\n\
410-
Invalid json: {s}"
411-
)
412-
})? {
413-
Value::Array(values) => values.into_iter().map(Cow::Owned).collect(),
414-
obj @ Value::Object(_) => vec![Cow::Owned(obj)],
415-
other => bail!(
416-
"Expected properties string to parse as array or object, got {other} instead."
417-
),
418-
},
419-
obj @ Value::Object(_) => vec![Cow::Borrowed(obj)],
420-
Value::Array(values) => values.iter().map(Cow::Borrowed).collect(),
421-
other => bail!("Expected properties of type array or object, got {other} instead."),
422-
})
423-
}
424-
425-
async fn render_dynamic(&mut self, data: &Value) -> anyhow::Result<()> {
426-
anyhow::ensure!(
427-
self.recursion_depth <= MAX_RECURSION_DEPTH,
428-
"Maximum recursion depth exceeded in the dynamic component."
429-
);
430-
for dynamic_row_obj in Self::extract_dynamic_properties(data)? {
431-
self.recursion_depth += 1;
432-
let res = self.handle_row(&dynamic_row_obj).await;
433-
self.recursion_depth -= 1;
434-
res?;
435-
}
436-
Ok(())
437-
}
438-
439387
#[allow(clippy::unused_async)]
440388
pub async fn finish_query(&mut self) -> anyhow::Result<()> {
441389
log::debug!("-> Query {} finished", self.current_statement);

0 commit comments

Comments
 (0)