just a lil venting... I spent literal hours trying to find my error here:
(defn map-event-handler
[event]
(case (:event/type event)
::set-done (swap! *state assoc-in [:by-id (:id event) :done] (:fx/event event))
::type #(swap! *state assoc :typed-text (:fx/event event))))
I suspect some ppl here may see my mistake immediately
I mean, this is not even a type checking error is it... just my own stupidity haha.
the other common kind of error I commit is either specifying`{:type :something}` instead of {:fx/type :something}
. A variation: {:fx/type :SomethingWRONG}
I think in those cases I tend to get a very long backtrace
my first reaction is attempt to "fix" these issues... perhaps have a few functions that construct valid component data ("valid by construction") the second reaction is maybe perform some sort of spec check
for now I'm just playing with the examples, see if I can familiarize myself with the kind of errors I get when I f%ck up some example code
---
so been reading the docs sequentially top to bottom (Readme). Getting to this point: https://github.com/cljfx/cljfx#special-keys the example was (is?) a bit jarring because we haven't been introduced to fx/create-component
yet (EDIT: it is the first example actually, d'oh). Also, I don't know what fx/advance-component
means or does.
I guess "advance" means "update" ?
Ok, I think the point of "Special Keys" 1) is that updating the component just reorders and keeps the very same identical instances as before instead of *recreating* things?
---
Kind of an unrelated to anything I said before, but I was wondering what would be a good way to implement a code editor when working with cljfx
I would suggest integrating monaco editor: https://github.com/Microsoft/monaco-editor
This is the editor used in vs code, pretty modern
Rolling your own like we did in Defold will require you to maintain it, it might make sense if your product's defining characteristic is editor
got it! It is an interesting idea in that learning a lil bit about monaco could be useful outside javafx context too
I found a few resources. Defold seems to be using canvas drawing annotations on top of javafx controls directly: https://github.com/defold/defold/blob/869a87718757bdb7bfd6ed078047fa7bfb451de9/editor/src/clj/editor/code/view.clj
Perhaps there's a "cljfx way" of doing something similar, probably would represent quite some work, but I like that idea.
There's also this "RichTextFX" which I imagine shouldn't be too hard to wrap into something cljfx can use https://github.com/FXMisc/RichTextFX/wiki/JavaFX-Controls-for-Code-Editing
finally, I saw some ppl are using HTML5 code editors like Ace in a webview, which should be simple enough to setup
so, not sure what would ppl more proficient with cljfx choose to use for some code editing control.
oh no! RichTextFX's https://github.com/FXMisc/RichTextFX/blob/master/richtextfx-demos/src/main/java/org/fxmisc/richtext/demo/XMLEditorDemo.java parses XML with regular expressions! 🙂
I don't see it :)
the event handler for ::type has #
as prefix so the code is not actually called!
I don't know why I put that #
there 😕
I mean, if I get it right the event handler just return an "inert" function that is never called, so nothing appears to happen
Haha, yeah, I imagine this can be frustrating
I think some spec can help with :type
vs :fx/type
, but it might be harder with :SomethingWrong
because you can extend fx/types to anything
a lil bit, sharing my experience mostly to vent a bit haha but also cause it could be interesting to share what kind of things a noob stumbles upon
Yes :)
"Move existing component to a new state"
This is the point of :fx/key, yes
gotcha. I was wondering if there could be a way to capture the error when something unexpected happens here, perhaps throw a more specific exception? Usually I get a 100 line exception when I pass the wrong thing
(or so)
I've already learn there is something wrong with the data when I get it... it starts with:
user=> java.lang.IllegalArgumentException: No implementation of method: :create of protocol: #'cljfx.lifecycle/Lifecycle found for class: clojure.lang.Keyword
... which makes sense... I think it would be even more helpful if it told me something like "Can't create a JavaFX object out of :thing-with-typo" or something like that
in this instance is telling me a keyword is causing an error, so I need to go kw by kw trying to check which one is the offending one
I think this makes sense! Please create an issue. PRs also welcome :D
--
I just finished reading the docs about subscriptions and contexts... flew a lil over my head ATM... guess will have to revisit. I was thinking on doing some reagent and then taking a look at reframe too. So much to learn!
(mention this since the docs talk so much abut the inspiration on reframe, I assume some familiarity with reframe should really help understand the concepts)