This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-03
Channels
- # aws (9)
- # beginners (5)
- # calva (5)
- # cljdoc (7)
- # cljsrn (3)
- # clojure (50)
- # clojure-greece (3)
- # clojure-uk (96)
- # clojurescript (18)
- # community-development (2)
- # core-logic (3)
- # cursive (4)
- # datomic (7)
- # emacs (3)
- # figwheel-main (3)
- # fulcro (5)
- # luminus (4)
- # mount (2)
- # nrepl (11)
- # onyx (6)
- # portkey (1)
- # qlkit (3)
- # re-frame (6)
- # shadow-cljs (33)
- # sql (8)
- # test-check (18)
- # yada (3)
Hi I am trying to use spec library in my re-frame project. When I try to run the code in repl it doesn work and I get this error CompilerException java.lang.ClassNotFoundException: cljs.spec.alpha, compiling:
. and CompilerException java.lang.RuntimeException: No such var: s/valid?
Here is the source:
(ns app.db
(:require [cljs.spec.alpha :as s :include-macros true]))
;; Modeling Application state
(s/def ::name string?)
(s/valid? ::name "John Doe")
hey everyone.
I have a bit trouble with with class.eval
function.
I have following wrapper for evaluating strings in clojurescript in nodejs
(defn eval-str [s]
(eval
(empty-state)
(read-string s)
{:eval js-eval
; :load (fn [_ cb] (cb {:lang :clj :source "(ns foo.core) (defn add [a b] (+ a b))"}))
:source-map false
:verbose true
:context :expr
; :ns 'foo.core
:load-macros true}
(fn [result]
(println "result>>" result)
result
)))
It works in simple cases:
(eval-str "(do (defn add [a b] (+ a b))(add 4 6))")
However I'm making trouble to make this work if I want to use library in the code.
E.g. I want to use curds library:
(eval-str "(do (require '[cuerdas.core :as cue])(cue/slug \"Hello\"))")
I see that class eval has different options. Like load-fn, include-macros, even include dependencies. I tried different variations but failing for now.
Maybe someone knows about working code examples on blogs in similar topic?@podviaznikov require
is a top-level thing in ClojureScript (it can’t be properly processed inside a do
)
The biggest challenge will be in defining the load-fn; I'd recommend perhaps taking a look at the Lumo codebase for an example of how this can be done with Node
Is it safe nowadays to access a nested javacript property like this (.. e -target -value)
?
Will it be properly handled by advanced compilation?
@viebel there’s a compiler option :infer-externs
that works in many cases. However it’s not bullet proof but you can add (set! *warn-on-infer* true)
on top of the file you’re working with to see if it’s working or if you need to provide extra hints for the compiler to generate needed externs.
If you want to play safe you can use libs from cljsjs
where someone else has already created the externs file for you.
What about code that relies on native javascript properties like (.. e -target -value)
in a event handler?
@viebel I think the best bet is to use getValueByKeys from https://google.github.io/closure-library/api/goog.object.html or https://github.com/appliedsciencestudio/js-interop/
Yeah. Currently, I am using purnam but it is not maintained any more. So I’ll probably migrate to https://github.com/appliedsciencestudio/js-interop/ @rakyi
AFAIK there’s no problem with any of the cljs oob interop patterns with :advanced
unless you’re accessing objects/functions in :foreign-libs
.