cljfx

https://github.com/cljfx/cljfx
EmmanuelOga 2020-08-02T02:07:45.167500Z

just a lil venting... I spent literal hours trying to find my error here:

EmmanuelOga 2020-08-02T02:07:52.167900Z

(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))))

EmmanuelOga 2020-08-02T02:08:08.168300Z

I suspect some ppl here may see my mistake immediately

EmmanuelOga 2020-08-02T02:09:16.169Z

I mean, this is not even a type checking error is it... just my own stupidity haha.

EmmanuelOga 2020-08-02T02:10:44.170500Z

the other common kind of error I commit is either specifying`{:type :something}` instead of {:fx/type :something} . A variation: {:fx/type :SomethingWRONG}

EmmanuelOga 2020-08-02T02:11:39.171Z

I think in those cases I tend to get a very long backtrace

EmmanuelOga 2020-08-02T02:12:55.172Z

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

EmmanuelOga 2020-08-02T02:13:31.172800Z

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

EmmanuelOga 2020-08-02T03:42:35.173100Z

---

EmmanuelOga 2020-08-02T03:43:31.174300Z

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.

EmmanuelOga 2020-08-02T03:49:22.174700Z

I guess "advance" means "update" ?

EmmanuelOga 2020-08-02T03:57:31.175500Z

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?

EmmanuelOga 2020-08-02T05:19:48.176100Z

---

EmmanuelOga 2020-08-02T05:20:15.176700Z

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

vlaaad 2020-08-02T07:14:04.182100Z

I would suggest integrating monaco editor: https://github.com/Microsoft/monaco-editor

vlaaad 2020-08-02T07:14:24.182400Z

This is the editor used in vs code, pretty modern

vlaaad 2020-08-02T07:16:01.182600Z

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

👍 1
EmmanuelOga 2020-08-02T07:35:29.182900Z

got it! It is an interesting idea in that learning a lil bit about monaco could be useful outside javafx context too

EmmanuelOga 2020-08-02T05:20:54.176800Z

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

EmmanuelOga 2020-08-02T05:21:23.177100Z

Perhaps there's a "cljfx way" of doing something similar, probably would represent quite some work, but I like that idea.

EmmanuelOga 2020-08-02T05:21:55.177300Z

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

EmmanuelOga 2020-08-02T05:22:27.177500Z

finally, I saw some ppl are using HTML5 code editors like Ace in a webview, which should be simple enough to setup

EmmanuelOga 2020-08-02T05:23:03.177700Z

so, not sure what would ppl more proficient with cljfx choose to use for some code editing control.

EmmanuelOga 2020-08-02T05:27:56.177900Z

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! 🙂

vlaaad 2020-08-02T05:45:19.178300Z

I don't see it :)

EmmanuelOga 2020-08-02T05:46:11.178500Z

the event handler for ::type has # as prefix so the code is not actually called!

EmmanuelOga 2020-08-02T05:46:25.178700Z

I don't know why I put that # there 😕

EmmanuelOga 2020-08-02T05:48:34.179Z

I mean, if I get it right the event handler just return an "inert" function that is never called, so nothing appears to happen

vlaaad 2020-08-02T05:52:14.179200Z

Haha, yeah, I imagine this can be frustrating

vlaaad 2020-08-02T05:54:31.179400Z

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

EmmanuelOga 2020-08-02T05:57:33.179600Z

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

vlaaad 2020-08-02T05:58:06.179800Z

Yes :)

vlaaad 2020-08-02T05:58:25.180Z

"Move existing component to a new state"

👍 1
vlaaad 2020-08-02T05:59:07.180200Z

This is the point of :fx/key, yes

👍 1
EmmanuelOga 2020-08-02T05:59:24.180400Z

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

EmmanuelOga 2020-08-02T05:59:30.180600Z

(or so)

EmmanuelOga 2020-08-02T06:00:31.180800Z

I've already learn there is something wrong with the data when I get it... it starts with:

EmmanuelOga 2020-08-02T06:00:34.181Z

user=> java.lang.IllegalArgumentException: No implementation of method: :create of protocol: #'cljfx.lifecycle/Lifecycle found for class: clojure.lang.Keyword

EmmanuelOga 2020-08-02T06:01:14.181200Z

... 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

EmmanuelOga 2020-08-02T06:01:46.181400Z

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

vlaaad 2020-08-02T06:39:28.181800Z

I think this makes sense! Please create an issue. PRs also welcome :D

👍 1
EmmanuelOga 2020-08-02T07:36:39.183200Z

--

EmmanuelOga 2020-08-02T07:37:30.184300Z

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!

EmmanuelOga 2020-08-02T07:48:43.184500Z

(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)