Open jelmerderonde opened 4 years ago
Hi!
There is no reason to not support multimethods by default, and adding support seems to be a non-breaking change. Are you interested to make a PR for that? You'll need to modify defaults.clj to make it accept MultiFn
-s in addition to Fn
-s. I can do it too, but first I'll need to find some time to do that.
Meanwhile, you can make your own type->lifecycle
function that checks for multimethods as well:
(require '[cljfx.api :as fx] '[cljfx.lifecycle :as fx.lifecycle])
(defmulti component ::type)
(defmethod component ::label [{:keys [text]}]
{:fx/type :label :text text})
(fx/on-fx-thread
(fx/create-component
{:fx/type :stage
:showing true
:scene {:fx/type :scene
:root {:fx/type :v-box
:children [{:fx/type component
::type ::label
:text "Hello multimethods!"}]}}}
{:fx.opt/type->lifecycle (some-fn
#(when (instance? clojure.lang.MultiFn %)
fx.lifecycle/dynamic-fn->dynamic)
fx/keyword->lifecycle
fx/fn->lifecycle)}))
Hi, I would like to try and make a PR, but it will have to wait till the weekend I suspect ;-).
I created a PR: #60.
Great, thanks! I'll have a look — most probably tomorrow.
I'm getting the error "No implementation of method: :create of protocol: #'cljfx.lifecycle/Lifecycle found for class: clojure.lang.MultiFn" when trying to use a multimethod as a component. As in:
Is this something that could be implemented or are their good reasons not to use multimethods as components?