Skip to content

Commit

Permalink
Source value can be nil to remove rendered component.
Browse files Browse the repository at this point in the history
Previously only the initial value of a live component's source could
be nil and a placeholder will be rendered instead of the component.

Now the source value can change back to nil and the component will be
replaced with a placeholder.

This is because we aren't using go blocks as the conveyence mechanism anymore.
  • Loading branch information
tatut committed Jun 28, 2023
1 parent b7f94fb commit 62892bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ see namespace docstring for an integration source in `ripley.integration.<type>`

## Changes

### 2023-06-28
- Source value can be `nil` now and component is replaced with placeholder

### 2023-06-10
- Support client side success and failure callbacks

Expand Down
11 changes: 10 additions & 1 deletion src/ripley/html.clj
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,15 @@
`(let ~bindings
~(compile-html body)))

(defn wrap-placeholder [component-fn]
(fn [value]
(if (some? value)
(component-fn value)
(let [id (dynamic/consume-component-id!)]
(out! "<script type=\"ripley/placeholder\" data-rl=\""
id
"\"></script>")))))

(defn compile-live
"Compile special :ripley.html/live element."
[live-element]
Expand All @@ -413,7 +422,7 @@
~comp-sym ~(or component
`(fn [thing#]
(out! (str thing#))))
~id-sym (p/register! dynamic/*live-context* ~source-sym ~comp-sym
~id-sym (p/register! dynamic/*live-context* ~source-sym (wrap-placeholder ~comp-sym)
~(merge
{}
(when patch
Expand Down
2 changes: 1 addition & 1 deletion src/ripley/live/context.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
(p/close! source)

:else
(when (and update? (some? val)) ;; PENDING: allow nil as value now that we are not using channels
(when update?
(let [target-id (if (patch/target-parent? patch)
parent
id)
Expand Down

0 comments on commit 62892bc

Please sign in to comment.