Developing mobile digital key applications with ClojureScript

by swannodetteon 5/25/2021, 2:14 PMwith 12 comments

by swannodetteon 5/25/2021, 5:21 PM

Some technical points about Krell. It leverages the ClojureScript `:bundle` target which was released last year https://clojurescript.org/news/2020-04-24-bundle-target. By simply producing output that is JS bundler friendly we can just piggieback on Facebook's Metro just like we piggieback on Webpack etc. when targeting the web.

We simply reuse the debug loader provided by Google Closure and load ClojureScript and Google Closure JavaScript files through the Metro server. But this is the core of ClojureScript's hot-reloading capabilities without caveats. In Google Closure namespaces can be represented as nested JavaScript objects which delivers pervasive late-binding - which simply cannot be done with ES6 modules because imports will be captured (early bound).

The REPL bit (which is an independent piece from the hot-reloader) just runs on top of react-native-tcp-socket.

The only tricky part is that we need to be able to require Node libraries and assets into ClojureScript during development. This is done by a compiler pass - first we start at the entry point of the ClojureScript React Native project and follow the dep graph collecting all libraries required from `node_modules`. This is dumped to a file that is required transitively by `index.js`.

Asset handling is done as a simple compiler pass over every AST node searching for JavaScript `require` statements in the ClojureScript.

The end result is that we have an extremely rapid development workflow that simply is not possible with other existing technologies - not React Native, not Flutter, not SwiftUI. All of our apps are built via live-coding from our text editor of choice + REPL (either embedded in IDE or via shell).

Happy to answer any further questions!

by smokeonlineon 5/25/2021, 7:53 PM

It's a very good example of a front-end REPL. I used to think hot reloading was good, but to keep the state between reloads is a whole new level.

by schmuddeon 5/25/2021, 4:34 PM

Krell looks pretty cool. The article talks about using storybook.js, but I'd love to see it used with clojure.spec. The latter is such a nice way to vet business logic with domain experts.

by slifinon 5/25/2021, 4:57 PM

Who should I be sponsoring on Github to help get documentation for Krell with https://microsoft.github.io/react-native-windows/ ?

by mark_l_watsonon 5/25/2021, 9:50 PM

I read this article recently and tried Krell, cool stuff.

I just finished writing a Clojure AI book (free PDF download on my web site) and the idea of writing iOS apps in ClojureScript is enticing. Anyone have Apple App Store issues?

by dwiamoon 5/25/2021, 2:47 PM

This is great, really interesting