cljfx

Andrey Subbotin 2024-05-25T03:56:05.932819Z

Please consider the following code:

(defn application-menu
  [_ctx]
  {:fx/type :menu
   :text    "Apple"
   :items   [{:fx/type    fx/ext-on-instance-lifecycle
              :fx/key     ::quit
              :on-created (fn [^MenuItem mi]
                            (.setOnAction mi (fxcoerce/event-handler
                                              (fn [_event]
					      	  ;; A
						  )))))
              :desc       {:fx/type fx/ext-instance-factory
                           :create  #(.createQuitMenuItem menu-toolkit "App Name")}}]}
TL;DR Question: How would one dispatch a cljfx event from the action handler at the mark A? Some constraints I seemingly can't figure out how to resolve: • There's no dispatch fn available to a component descriptor fn to use. • I can't merely use the :on-action property and provide it an event map it seems, as the node itself is created by an external Java library and I need to override the default behaviour it gives to the menu item in the :on-created lifecycle handler. As a workaround I could potentially store the dispatch fn on the context, which would make it available to descriptor fns to use as they please, but that doesn't seem right...

vlaaad 2024-06-03T20:04:07.991009Z

Unfortunately, there is no way to go from fx/ext-on-instance-lifecycle to event handlers, instead you should define a lifecycle that creates menu items, and define props that set :on-action.