This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-21
Channels
- # announcements (12)
- # atom-editor (2)
- # babashka (44)
- # beginners (4)
- # calva (3)
- # clj-kondo (10)
- # clj-yaml (1)
- # cljsrn (1)
- # clojars (5)
- # clojure (68)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (75)
- # clojure-uk (2)
- # clojurescript (23)
- # conjure (1)
- # datomic (2)
- # defnpodcast (7)
- # emacs (23)
- # etaoin (7)
- # fulcro (7)
- # funcool (2)
- # honeysql (3)
- # hyperfiddle (40)
- # interop (4)
- # jobs (3)
- # lsp (1)
- # malli (16)
- # off-topic (16)
- # parinfer (2)
- # podcasts-discuss (1)
- # portal (61)
- # reitit (6)
- # releases (1)
- # remote-jobs (6)
- # scittle (4)
- # shadow-cljs (18)
- # spacemacs (4)
- # vim (22)
- # xtdb (12)
How can I tell Hyperfiddle how to serialize things like Dates so I don’t get this INFO log? I have time-literals installed on front & back, so it should know how to serialize #time/date "2018-10-09"
(just like that).
: Unserializable reference transfer: java.time.LocalDate 2018-10-09
data is transferred with transit, so you need to install the transit handlers in the app. Here's a https://github.com/hyperfiddle/electric/blob/0bc5f4bcd96b632f4522de328af66b44f1220fe4/src-docs/wip/demo_custom_types.cljcshowing how you can do that today
hmm, the following does not seem to work:
(ns xtx.transit
"Connect time-literals to transit.
Sourced and edited from:
"
(:require
[time-literals.read-write]
[cognitect.transit :as transit]
#?(:cljs [java.time :refer [Period
LocalDate
LocalDateTime
ZonedDateTime
Instant
ZoneId
DayOfWeek
LocalTime
Month
Duration
Year
YearMonth]]))
#?(:clj (:import
(java.time Period
LocalDate
LocalDateTime
ZonedDateTime
Instant
ZoneId
DayOfWeek
LocalTime
Month
Duration
Year
YearMonth))))
;; uhmm I think these have to be fully namespaces
(def time-classes
{'period Period
'time/date LocalDate
'date-time LocalDateTime
'zoned-date-time ZonedDateTime
'instant Instant
'time LocalTime
'duration Duration
'year Year
'year-month YearMonth
'zone ZoneId
'day-of-week DayOfWeek
'month Month})
(def write-handlers
(into {}
(for [[tick-class host-class] time-classes]
[host-class (transit/write-handler (constantly (name tick-class)) str)])))
(def read-handlers
(into {} (for [[sym fun] time-literals.read-write/tags]
[(name sym) (transit/read-handler fun)])))
;; Demo shows how to serialize custom types in Electric
;; Todo cleanup, there are better ways to do this
#?(:clj (alter-var-root #'
merge write-handlers)) ; server: write only
#?(:cljs (set!
(merge read-handlers))) ; client: read only
maybe because tags not fully-namespaced? cc @U09FL65DKI'd suggest taking a single class, e.g. Period
, use it manually and get that working. Then you can expand to subsume above.
Any chance you're failing to transfer a date/time type from client to server? The config only sets up server->client
Hmm, even this complains if I try to send a LocalDate (from server to client only):
(def write-handler (transit/write-handler
(fn [_] 'time/date) ; this tag must be namespaced!
str))
(def read-handler (transit/read-handler 12345.67)) ;; just overriding it for now to see if it can send from server to client
#?(:clj (alter-var-root #'
assoc LocalDate write-handler)) ; server: write only
#?(:cljs (set!
(assoc
"time/date" read-handler))) ; client: read only
Do I need to call alter-var-root from somewhere specific? Error:
INFO : Unserializable reference transfer: java.time.LocalDate 2000-01-01
Tried with string tag vs symbol tag.Here's a minimal working example where a JVM LocalDate is represented as a string "LOCALDATE: <date-here>" on the client
lets change the tutorial to this
also tutorial should provide both directions imo
and also link to any supporting documentation/examples for transit
I have to re-eval the transit handler namespace on server to get changes to show up, which I find unexpected given that my “app” namespace :require’s my transit handler namespace. The auto-builder does not seem to pick up changes to that namespace, which is confusing when trying to debug why handlers aren’t working.
Hmm, maybe because alter-var-root is in #?(:clj …) directive?
Hmm, can’t seem to use Specter in Electric functions, which kind of makes sense with all it’s crazy macros:
(->> (:entry/_tx tx)
(S/transform [S/ALL :entry/amount] float)) ;; because (sort-by :entry/amount ...) chokes on bigdec [TaggedValue f...] some or other.
Unable to resolve symbol: pathcache83102
{:file "xtx/electric.cljc", :cljs.analyzer/no-resolve true, :no-doc true, :private true, :in [pathcache83102]}
ExceptionInfo: Unable to resolve symbol: pathcache83102
hyperfiddle.electric.impl.compiler/analyze-form (compiler.clj:643)
hyperfiddle.electric.impl.compiler/analyze-form
I suspect the problem to be specter macroexpanding to inline def
s, which in turn confuse electric compiler because the symbol doesn't refer to a top-level var
• [TaggedValue f...]
seems like a type you didn't expect, maybe the serialization returns something else than you expect?
• I think specter will work if you call it in a clojure context, not electric. As a first step try to push the specter code in a toplevel cc/defn
we have a bug related to certain things that should be float coming across as TaggedValue ratio
Is there a quickfix for TaggedValue? I’m seeing decimals come over the wire as e.g. [TaggedValue: f, -2402.97]
or should I coerce to float or string before sending from server to client?
I have a crazy idea- I'm gonna use my cloud box to do the heavy lifting for me, and code via SSH 😄 probably lots of fellows already doing this i bet
I think I found an issue w/ electric-examples-app
a fresh clone gives. me
cloning:
Checking out: at 447810b9401d66d6f6d5a7bf3da685f406efa7a5
Cloning:
Downloading: com/google/guava/guava/31.1-jre/guava-31.1-jre.pom from central
Downloading: com/google/guava/guava-parent/31.1-jre/guava-parent-31.1-jre.pom from central
Downloading: thheller/shadow-cljs/2.22.10/shadow-cljs-2.22.10.pom from clojars
Downloading: markdown-clj/markdown-clj/1.11.4/markdown-clj-1.11.4.pom from clojars
Checking out: at ac038ebf6e5da09dd2b8a31609e9ff4a65e36852
Error building classpath. Failed to read artifact descriptor for com.datomic:dev-local:jar:1.0.243
org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for com.datomic:dev-local:jar:1.0.243
... 21 more
which is `Could not transfer artifact com.datomic:dev-local:pom:1.0.243 from/to cognitect-dev-tools ( ): status code: 401, reason phrase: Unauthorized (401)
datomic dev-local requires registration and out of band maven configuration, you can remove the datomic from deps.edn and comment out any references to the datomic example
I replaced it :deps {com.datomic/datomic-free {:mvn/version "0.9.5697"}
in deps.edn and seems to be working
Now I get The required JS dependency "@codemirror/language" is not available, it was required by "contrib/electric_codemirror.cljc".
maybe npm dep?
I do want to use datomic, just not sure how to accommodate the codemirror thang, but i'm looking into it 😅
or, npm install
datomic free is not a drop in replacement i don’t think
Maybe I can just add datomic to the starter-app and be good to go, I just require sessions, eventually, and figure it better to work with them from the outset
yes i recommend that, use the starter todos app and port datascript to datomic free
this little story above is a great example of how it might be great for Datomic to loosen up on the maven config requirements for dev-local tutorial-level users and tutorial-level creators (if possible)! @U1QJACBUM