Added support for QML to Weasel
Qt 5.3 added a QtWebsockets module which makes Weasel the perfect candidate for a QML/JS Clojurescript repl.
I added a weasel.repl.qml namespace which tries to mirror weasel.repl as much as possible.
I also added a trivial weasel.impls.print ns to so that the same repl server can set the print function regardless of whether it's a regular Websocket, QML or possibly say a Node.js repl.
I posted details here about how I actually got a REPL working in QML: https://groups.google.com/forum/#!topic/clojurescript/bSBfH1hazSg
Wow, this sounds very cool! I will take a look this weekend.
Overall this looks very nice! I'll have some more 'bigger picture' comments later. I'm very excited by the prospect of running Weasel REPL clients in non-browser JS environments!
I'd love to play around with this but I'm stuck on getting a QML + ClojureScript example set up. Do you have a demo project somewhere where I could try this out?
I'm concerned by how much code is duplicated from weasel.repl in weasel.repl.qml. Notice how weasel.repl doesn't call much Closure WebSocket code directly, but instead calls functions defined on the net/IConnection protocol and the polymorphic event/listen function to listen for events on the current connection object.
We could make weasel.repl totally implementation-agnostic by allowing connect to take an optional keyword parameter as a "connection constructor function", defaulting to ws/websocket-connection, and an optional parameter of keyword arguments to pass on to the net/connect function after the server URL. Then we could have a new namespace weasel.impls.qml which contains implementations of net/IConnection and event/EventType (as well as the appropriate event dispatching code) for the QML WebSocket type and the appropriate connection constructor.
Connecting from QML might look something like:
(ns example
(:require [weasel.impls.qml :as qml-ws])
(weasel.repl/connect
:connection-fn qml-ws/connection
:connection-args {:qml-parent ... })
What do you think?
So, getting QML and Clojurescript running together isn't super easy - it was actually somewhat of a feat to figure it out and there are still some idiosyncracies. I described my approach here: https://groups.google.com/forum/#!topic/clojurescript/bSBfH1hazSg. I intend to put together a little example project or even a lein template... I'll let you know when I have something...
I do agree that it would be nice to have a common implementation. I think my initial thought was to do it this way, but because it seemed complex I did it the quickest way that worked. In QML, for instance, the event system is very different. It probably is possible if I implement a type that implements goog.events.Listenable and converts the status. Also, I'm not sure how to use extend-type on QML types yet because QML doesn't give you a type constructor directly but requires this sort of convoluted Qt.createQmlObject to be called with a string of QML. But, I could wrap the WebSocket in a deftype and it should work. So, I think it's possible but just a little more complex. Would you want me to see if I can create an impl that uses weasel.repl directly as it is?
How about doing what you said with a connection-fn but also creating a helper function such as this?
(defn qml-repl [parent url ...]
(weasel.repl/connect
:connection-fn qml-ws/connection
:connection-args {:qml-parent ... }))
Hey Tom, I made a lein template that should hopefully work.
If you execute lein new qml-cljs test-qml-cljs --snapshot this should generate an example project which has a README.md with quickstart instructions.
If you get a chance to try this, let me know if you run into any problems. Thx!
Hey! I haven't forgotten about this, just have been lacking time. I should be able to carve out some time this weekend to hopefully land this!
autogenerated with https://github.com/MalloZup/doghub: pr inactive since 200 days. Please update the PR or close it
autogenerated with https://github.com/MalloZup/doghub: issue inactive since 450 days. Please update the issue or close it