you probably want something like:
(with-open [rdr (<http://clojure.java.io/reader|clojure.java.io/reader> "page")
pb-rdr (java.io.PushbackReader. rdr)]
(clojure.edn/read pb-rdr))
but there are several ways to read an edn file depending on the exact semantics required
thanks! string and vector respectively… it balks at a conversion of the string to a vector via vec, however.
It’s not technically an edn file.
well, you need some way to parse the file. what type of file is it?
throws
[ is not a valid element name.
check (prn (vec (slurp "page")))
in this case, no type, just a plain file.
does the file contain edn?
if it contains edn, then clojure.edn/read
should work
it doesn’t.
just the plain vector.
just
[:html [:p "hello"]]
which
(prn (vec (slurp "page")))
turned into
[\[ \: \h \t \m \l \space \[ \: \p \space \" \h \e \l \l \o \" \] \]]
and when it’s fed into hiccup, it complains that
[ is not a valid element name.
the above code with the edn reader should work
ok, I can give that a go.
you'll probably need to require:
(require '<http://clojure.java.io|clojure.java.io>
'clojure.edn)
seems to be available, but that throws
java.lang.String cannot be cast to java.io.PushbackReader
so weird. basically, I just can’t coerce the file into a proper vector, it seems.
are you copied the code correctly?
for eg.:
(with-open [rdr (<http://clojure.java.io/reader|clojure.java.io/reader> "deps.edn")
pb-rdr (java.io.PushbackReader. rdr)]
(clojure.edn/read pb-rdr))
This works for meanother way to read edn data from a file is (read-string (slurp "page"))
although it will cause issues for some edge cases
I got it!
(read-string (slurp "page"))
and totally grateful for the help!
I'm looking into licenses and ClojureScript is under EPL along with a lot of ClojureScript libraries. Since JavaScript in a browser is technically a distribution (from what I understand) then anyone developing a website with ClojureScript would have to disclose the source code and also include the EPL license. Is my understanding of this correct?
https://en.wikipedia.org/wiki/Eclipse_Public_License#Derivative_works
"Linking to code (for example to a library) licensed under EPL automatically does not mean that your program is a derivative work."
As long as you are not modifying clojurescript or lib source code you are fine.
this is what I understand.
Thanks @phoenixai2082, that would make sense. If anyone else has a different view, please share!
Hi There,
I am working on a react-app, I have this function for for map icons, I am having an issue when I click on Icons in `yarn start` it works (it gets the id), but when I use the `yarn build` build file and click on Icon, it gets id as nil. I am not sure whats causing this to behave this way.
Uncaught (in promise) Error: Vector's key for assoc must be a number.
(defn on-click-map-icons [event props page]
(def feature (first event.features))
(println feature.properties.itemid)
(when (= page "results")
(if (= feature.source "selected-item") (router/redirect! props :router {:page "item" :item (:id {:id itemid })}) ))
(when (= page "item")
(if (= feature.source "subitem")
(router/redirect! props :router {:page "item" :item (:id {:id itemid } ) :subitem (:sub-id {:sub-id subitemid}) }))))
Don't use .
that way.
Stuff like event.features
should be (.-features ^js event)
. The ^js
part can be there only once where you first define the name - in this case, right in the signature, like [^js event props page]
.
Thanks @p-himik for pointing that out, I’ve tried using
(defn on-click-map-icons [event props page]
(def feature (first (.-features ^js event)))
(when (= page "results")
(if (= feature.source "selected-item") (router/redirect! props :router {:page "item" :item (:id {:id feature.properties.itemid })}) ))
(when (= page "item")
(if (= feature.source "subitem")
(router/redirect! props :router {:page "item" :item (:id {:id itemid } ) :subitem (:sub-id {:sub-id feature.properties.subitemid}) }))))
Still got Error: Vector's key for assoc must be a number.
I didn't mean just that interop with event
- I meant all interop field access in your code.
Also, you probably want to use let instead of def.
Ah I see
@p-himik I am able to get to properties like
(.-properties ^js feature)
#js {:title sample_note, :noteid 3}
how do I go inside the object and get title?
For example feature.properties.titleChoose any one or a combination or them:
(.. feature -properties -title)
(.-title (.-properties feature))
(-> feature .-properties .-title)
(. (. feature -properties) -title)
CLJS/JS interop and CLJ/Java interop are almost identical. Completely identical if you don't go outside of the .
and -
.
Thank You
When using webpack in javascript, I can do something like:
function dynamic-load() {
require("path/to/module");
}
Is there any way to do this sort of thing in clojurescript (when using the :bundle
target)?No, all requires have to be a part of an ns
form.
I'm not familiar with dynamic load in webpack. Is it loading the module during the run time, when e.g. some relevant component is requested? If so, then CLJS have module splitting for that.
I’m using ^:export
to export a sort-of feature flag to be changed from the console but it looks like the boolean value is inlined wherever it is being used, meaning setting it does not actually propagate to the various sites where it’s used. Is there a way to avoid this type of inlining for specific vars? (In the meantime I fixed this by using an atom.)
@martinklepsch I don't think you can export value? I recall running into this - only functions
writing a CLJC lib that returns either Clojure promise or a JS Promise and really missing async
/`await` 😞
gotta split my test suite between CLJ and CLJS, even though the semantics are basically the same
the dream would be I could do:
#?(:clj @(f/send n msg)
:cljs (await (f/send n msg)))
Alas,You can't use <p!
?
The test framework has no more special support for core.async
than for Promises and I suspect <p!
is cljs-only as well
Well I was thinking cause he wants to block on the promise return is my guess. So if he makes the cljs code in a go block with <p! he'd get the blocking behavior. But I guess not really since the go block itself will be async now. The same way you said await would just move the problem up as well.
I think I'd just make the clj code async as well. Maybe use CompletableFuture instead of a Clj promise, since those have a much similar interface to JS promises
Using Promesa maybe could also help. It is already Clj and Cljs compatible.
I did end up using core.async and <p!
it still required me to split my tests between CLJ and CLJS as I needed to wrap things in async
and go
In general I'm trying not to pull in too many external libs
Fair enough. I think nilern is right though, I'm not sure await would have helped, because you can only use await inside of async, similar to how you can only use <p! inside go. So you might have had to shenanigan things either way. It's the whole colored function problem.
yeah like I said, I'm stating my dream; not a call to action 😛
Haha ya. Its going to get a bit weirder too, because Java will get green threads, and CLJ will probably use that for async. But CLJS will need to stick to async/await or go/<p!
Oh, nice solution you found in the end!