Skip to content

Commit 4ba04d3

Browse files
committed
[nested-v-grid] Resize cross-sizes more safely
1 parent 3ce44b5 commit 4ba04d3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/re_com/nested_v_grid.cljs

+10-2
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@
309309
theme/args-desc
310310
(part/describe-args part-structure))))))
311311

312+
(defn safe-assoc
313+
[v idx val]
314+
(if (< idx (count v))
315+
(assoc v idx val)
316+
(into (vec (concat v (repeat (- idx (count v)) nil))) [val])))
317+
312318
(defn nested-v-grid [{:keys [row-tree column-tree
313319
row-tree-depth column-tree-depth
314320
row-header-widths column-header-heights
@@ -397,12 +403,14 @@
397403
safe-column-header-heights (r/reaction
398404
(->> (concat @internal-column-header-heights
399405
(repeat (u/deref-or-value column-header-height)))
406+
(map #(or % column-header-height))
400407
(take @column-depth)
401408
vec))
402409
safe-row-header-widths (r/reaction
403410
(->> (concat @internal-row-header-widths
404411
(repeat (u/deref-or-value row-header-width)))
405412
(take @row-depth)
413+
(map #(or % row-header-width))
406414
vec))
407415
column-header-height-total (r/reaction (apply + @safe-column-header-heights))
408416
column-width-total (r/reaction (:sum-size @column-traversal))
@@ -520,8 +528,8 @@
520528
resize-column-header-height? true
521529
on-resize (fn [{:keys [header-dimension size-dimension keypath size]}]
522530
(case [header-dimension size-dimension]
523-
[:column :height] (swap! internal-column-header-heights assoc-in keypath size)
524-
[:row :width] (swap! internal-row-header-widths assoc-in keypath size)
531+
[:column :height] (swap! internal-column-header-heights safe-assoc (first keypath) size)
532+
[:row :width] (swap! internal-row-header-widths safe-assoc (first keypath) size)
525533
[:row :height] (swap! internal-row-tree update-in keypath assoc :size size)
526534
[:column :width] (swap! internal-column-tree update-in keypath assoc :size size)))}}]
527535
(let [ensure-reactivity u/deref-or-value

0 commit comments

Comments
 (0)