Skip to content

[idea] Deeper integration with transit-js #419

@harold

Description

@harold

Hi! Thanks for squint, been having an absolute blast thinking about it and playing with it over the last couple weeks.

Is your feature request related to a problem? Please describe.
Experimenting with building a component of one of our systems in squint, interoperating over the network with existing clj/cljs systems, it occurred to me that transit-js (https://github.com/cognitect/transit-js) could be a nice bridging point - especially in the sense that it provides a "pure js" (https://github.com/cognitect/transit-js#transit-maps) notion of Clojure data.

I was pleasantly surprised when doing so essentially "just worked", but now I wonder about deepening the integration.

In one sense, this is sort of about destructuring (the exact example below), but in another sense it's about extending squint to be more fluent with a few more Clojure data types (esp. keywords, times (dates), uuids, sets (?)).

squint.edn:

{:paths ["src"]
 :extension "js"
 :output-dir "out"}

src/index.cljs:

(ns index
  (:require ["transit-js" :as t]))

(def transit-str "[[\"^ \",\"~:msg\",\"Squint\"],[\"^ \",\"^0\",\"is\"],[\"^ \",\"^0\",\"rad!\\n\"]]")
(def r (t/reader "json"))

;; Rad:
(println "Working:")
(def data [{:msg "Squint"} {:msg "is"} {:msg "rad!\n"}])
(println (->> data
              (reduce (fn [eax {:keys [msg]}]
                        (str eax msg " "))
                      "")))

;; Interesting:
(println "Also working:")
(println (->> (.read r transit-str)
              (reduce (fn [eax m]
                        (str eax (.get m (t/keyword "msg")) " "))
                      "")))

;; Someday?
(println "🤔:")
(println (->> (.read r transit-str)
              (reduce (fn [eax {:keys [msg]}]
                        (str eax msg " "))
                      "")))

(println "\nDone...")

Then...

$ bun install squint-cljs
$ bun install transit-js
$ bun squint watch

And in another terminal:

$ bun out/index.js 
Working:
Squint is rad!
 
Also working:
Squint is rad!
 
🤔:
   

Done...

Describe the solution you'd like
Not 100% sure what all this even implies, but perhaps it's thought provoking.

Describe alternatives you've considered
The component I'm building will, for now, need to be done in cljs instead of squint, which is fine. But I think this project is super-interesting, so I'm happy to contribute ideas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions