tatut / ripley

Server rendered UIs over WebSockets
MIT License
300 stars 10 forks source link

ClassCastException on render #11

Closed misuba closed 1 year ago

misuba commented 1 year ago
Exception while rendering! #error {
 :cause class java.lang.String cannot be cast to class clojure.lang.IFn (java.lang.String is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')
 :via
 [{:type java.lang.ClassCastException
   :message class java.lang.String cannot be cast to class clojure.lang.IFn (java.lang.String is in module java.base of loader 'bootstrap'; clojure.lang.IFn is in unnamed module of loader 'app')
   :at [ripley.live.context$render_with_context$fn__13925 invoke context.clj 220]}]
 :trace
 [[ripley.live.context$render_with_context$fn__13925 invoke context.clj 220]
  [ring.util.io$piped_input_stream$fn__205 invoke io.clj 28]
  [clojure.core$binding_conveyor_fn$fn__5823 invoke core.clj 2047]
  [clojure.lang.AFn call AFn.java 18]
  [java.util.concurrent.FutureTask run FutureTask.java 317]
  [java.util.concurrent.ThreadPoolExecutor runWorker ThreadPoolExecutor.java 1144]
  [java.util.concurrent.ThreadPoolExecutor$Worker run ThreadPoolExecutor.java 642]
  [java.lang.Thread run Thread.java 1589]]}

This feels faintly like I haven't sussed out one of the wrapping functions that's needed; I think I have them all, but let's find out. Here's the calling view code:

(defn node [obj]
  (let [[selected-tab select-tab] (source/use-state 0)]
    (hc/html
     [:main#nodeview
      [:header
       [:details {:open true}
        [:summary
         [:nav#breadcrumb]
         [:h1 (:title obj)]]

        [:article (:body obj)]

        [:nav#nodelinks]
        [:aside#incominglinks]]]
      [::h/live {:source selected-tab
                 :component (fn [tab]
                              (h/html [:section#nodetabs.two-up
                                       [:nav [:ul
                                              [:li {:on-click (fn [] (select-tab 0))}
                                               (when (= tab 0) {:set-attributes {:class "open"}}) [:h6 "Subnodes"]]
                                              [:li {:on-click (fn [] (select-tab 1))}
                                               (when (= tab 1) {:set-attributes {:class "open"}}) [:h6 "Properties"]]]]
                                       (when (= tab 0) [:aside#subnodes.active
                                                        (subnodes obj)])
                                       (when (= tab 1) [:aside#properties
                                                        [:div.place (if (:props obj) "props!" "no props")]])]))}]])))

The hc namespace is hiccup, and h is ripley.html. I was getting a different error on top of this one with h/html (at line 3 above, I mean), that using hiccup's at the top of this function got rid of... if that makes sense.

tatut commented 1 year ago

I don't understand why you use hiccup as it doesn't understand ::h/live definitions. I wouldn't expect that to work.

Also you can use [::h/when inside h/html macros or you need to use h/html again inside the when blocks. For an example of tab component, you could look at https://github.com/tatut/xtdb-inspector/blob/main/src/xtdb_inspector/ui/tabs.clj