This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-25
Channels
- # architecture (4)
- # bangalore-clj (3)
- # beginners (11)
- # chestnut (1)
- # cider (24)
- # cljs-dev (14)
- # clojure (97)
- # clojure-finland (1)
- # clojure-gamedev (19)
- # clojure-italy (11)
- # clojure-nl (31)
- # clojure-norway (1)
- # clojure-uk (52)
- # clojurescript (71)
- # core-async (4)
- # cursive (60)
- # datascript (8)
- # datomic (115)
- # emacs (29)
- # figwheel (11)
- # fulcro (3)
- # garden (1)
- # hoplon (1)
- # lein-figwheel (1)
- # leiningen (7)
- # luminus (13)
- # mount (1)
- # off-topic (51)
- # onyx (31)
- # pedestal (2)
- # portkey (1)
- # re-frame (22)
- # reagent (22)
- # reitit (6)
- # remote-jobs (1)
- # schema (1)
- # shadow-cljs (73)
- # specter (2)
- # sql (1)
- # unrepl (3)
- # vim (11)
- # yada (4)
yep. what inputs are you about to use
it kinda looks like a little ear š :<- for listening
Hi, I have a cljs macro question/issue. I have some macro code that generates re-frame subscriptions based on a mini-DSL. I think Iāve followed all the guidance for them. The macro is in a separate namespace, and in a .cljc, etc. I need to have the macro execute when the file loads so I have an inline call to it in the file where itās included. It seemed to be working at one point but now it doesnāt seem to get called at all, and I canāt figure out why
;;; macros.cljc
(defn gen-calc-sub
[calcs [field [calc args]]]
(print "creating sub for: " field)
`(rf/reg-sub
~field
(fn [_# _#]
~(mapv (fn [arg] (if (calcs arg)
`(rf/subscribe [~arg])
`(rf/subscribe [:form/cur-field ~arg]))) args))
(fn [args#]
(calc/run-calc ~calc args#))))
(defmacro gen-calc-subs
[calcs]
(print "creating subs for: " calcs)
(let [calc-fields (set (map first calcs)) ;for quick membership test
]
`(do ~@(map #(gen-calc-sub calc-fields %) calcs))))
;;; file where it's used
(ns f.....events-subs
...
(:require-macros [....macros :as fm]))
...
;;; invocation
(fm/gen-calc-subs {:sf425/cash-on-hand
[:calc/subtract [:sf425/cash-received :sf425/cash-disbursed]] })
Iāve done something similar in Clojure with no problems, so I guess Iām missing some other CLJS specific thing. Iāve checked the expansion in the CLJS and CLJ repls, and Iām getting the expected output in both placesyeah, ok, hmm, i need to call reg-sub
with functions that i need to create programmattically so i kind of think i do
now the base sub is just a vector, so might work, maybe, but env then itās a vectory of function calls that shouldnāt be evalāed at that point
Yeah, if you need to postpone evaluation, then you're stuck. Don't know much about your problem, unfortunately
yeah itās frustrating, I was so close to a nice generic solution lol Iād written this crazy chunk of code that would fire off new events if fields that computed fields depended on changed, etc. Then, I just happened to re-read the re-frame docs, Iād kind of blasted through them when I first started playing with it, and realized I pretty much totally missed level 3 subs lol. So replaced like 50 lines of code with that macro
Iām trying to push a full stack clojure(script), datomic, kafka, microservice solution for one of my projects
in 3 different stacks, pure java/react/lagom, then isomorphic kotlin with react on the client and both lagom and axon, vs the clojure stack
the amount of code iām having to write, even with frameworks that provide a lot of plumbing.. is pretty annoying lol
Hey @eoliphant, Did you find the solution to your problem? I have faced a similar issue when I tried Macros in cljs a few days back. I am wondering if its some kind of config (clj->cljs) issue.
No I didnāt š Itās annoying the hell out of me lol. Although, thanks to good oā homoiconicity, I just ran the macro in the REPL, and pasted the code in for now. But I want to get that working as I want to pull this stuff out into a general library
oh and there was another bizarre thing I didnāt mention. There was a weird lapse in referential transparency lol
The macro took a map that was basically a little calculation DSL for form fields {:my-field [:sum [:field :field2])
so I had
(def calcs {:my-field [:sum [:field :field2]))
(re-frame-sub-generator-macro calcs)
was blowing up and saying calcs
wasnāt defined š I didnāt even dig into that and just put the map directly into the callhaha...yeah, in fact I also just pasted the results (for now) to test the system I was building.
@eoliphant ... works in CLJS repl ? o.O
Iām trying to use a NPM module (https://github.com/conorhastings/react-syntax-highlighter) in my project, but I canāt quite figure out how to get it working.
Initially, I just added :npm-deps {"react-syntax-highlighter" "7.0.2"}
to my cljsbuild :compiler
config. This caused figwheel to fail with Error: Cannot find module '@cljs-oss/module-deps'
.
I eventually figure out that I had to run npm install @cljs-oss/module-deps
, which fixed the error. Is there a better way to do this?
Anyway, Iāve since been trying to import the code, but none seem to work. AFAICT Iām supposed to be able to just do (:require [react-syntax-highlighter])
, but that gives me a āNo such namespaceā error. So does pretty much everything else Iāve tried. (FWIW I have verified that node_modules/react-syntax-highlighter
exists).
What am I missing here?
@wombawomba Iām curious, did you have :install-deps true
set as a compiler option?
I did notā¦ will try with that enabled and see how it goes š I guess I did npm install react-syntax-highlighter
to get it in place
I still seem to get No such namespace; react-syntax-highlighter
, even with :install-deps true
enabled
@wombawomba Note: the npm-deps feature will run the npm module through advanced compilation, which may or may not work with the library you want to use. If you are going to use a lot of npm libraries, you will probably be happier with shadow-cljs or using webpack. https://gist.github.com/jmlsf/f41b46c43a31224f46a41b361356f04d
Thatās good to know, thanks! For now, I only want this specific package, so Iād like to see if I can get npm-deps working. Otherwise Iāll definitely try one of those approaches.
From my description above, do you think the advanced compilation is likely to be the culprit, or is it possible that I missed something?
I donāt think thatās the issue. Advanced compilation issues are usually something like āb.c is undefinedā or some kind of reference to a name-mangled symbol
Got it. Thanks
ive got some code to generate a largeish (a few mbs) data structure from a text file; id like to pregenerate this data structure and then distribute it with the rest of the cljs code to live in memory on the client. whats the best way of going about this?
Whatās the purpose of the data structure, is it a javascript object, or is it used as clojure data?
I have a silly little app that uses hiccup
for generating html. Iād like to do this in ClojureScript, since itās going to be in AWS lambda. Iām looking at a few forks of hiccup that promise to work with Cljs but theyāre pretty old. Another strategy would be to do it in React, but it seems like a detour to first generate dom elements and then render them to a string. Any thoughts?
I use https://github.com/teropa/hiccups for now, but itās old and some things from hiccup are not supported. from https://github.com/weavejester/hiccup/issues/127 itās not clear if cljs will be supported by hiccup
the data structure is for use as clojure data... eg its representing a tree and so is queried by clojurescript functions.
Yes, mine is the same, I have cljc function generating the data structures and with either hiccup or hiccups I turn them intro a string
Hey everyone! I have a question about stacktraces within nodejs targets. With :optimizations
set to :simple
I canāt make cljs files appear in them. My assumption is that sourcemaps arenāt used for some reason. Iāve made a simple demo here https://github.com/mkarp/cljs-sourcemap-demo. Any ideas and feedback are welcome!
It looks like clojurescript defines the cljs.spec.alpha
namespace across two files: alpha.cljs
and alpha.cljc
. Is there a defined order those files are read in? Can they not reference each other at all? I made a toy project with a .cljc
, .cljs
, and .clj
all with the same name and namespace which, on require
ing it in a clojure repl, gave me access to stuff from the .clj
file but not the .cljc
file
.cljc
will be searched only if .clj
or .cljs
are not found (depending on the env, of course). (AFAIK)
My guess is that .cljc
only contains specs for macros? Since macros are expanded in Clojure, not CLJS.
(Note, I donāt have first-hand experience here, just Iāve seen this pattern a lot in the channel)
Aha! It's the reverse, in factāthe .cljc
file (mostly) only contains macros for specs, and the .cljs
file's ns
form :refer-macros
s "itself" to "get" them
Thanks for the help! I'm almost entirely a clj
dev but I'm trying to make a library cross-platform
Hah, Iām not even a clj
dev (ā¦yet) ā just been reading a lot š ā note, I think recent CLJS added some :require
sugar so you might not need to do :refer-macros
any more ā need to search for this.
It looks like require('source-map-support').install();
isn't emitted with :target nodejs
and simple optimizations with clojurescript 1.10.238 (it is emitted with "optimzations none"). You can enable sourcemaps by adding (.install (js/require "source-map-support"))
to your code. Is this the expected behavior?
Awesomesauce
This is with cljsbuild
oh, that is suprising a bit, I have noticed the same but I thought "it was just me"
@richiardiandrea yeah not having used the node target before I'm not sure if my expectation ā that the "source-map-support" shim should be included automatically ā is correct
not sure either, would wait for someone like David to answer, I now do what you did above in my lumo code
Just tried it with cljs.main
and it seems to work there. Maybe a lein cljsbuild issue?
Soo Iād like to do this
(let [{:user/keys [id :as user-id]} user
{:company/keys [id]} company]
[user-id id])
What do user and company look like in this scenario?
Assuming I have your use case right, you could do
(let [{{user-id :id} :user/keys} user
{{id :id} :company/keys} company]
[user-id id])
[jim@goliath ~]$ lumo
Lumo 1.8.0
ClojureScript 1.9.946
Node.js v9.2.0
Docs: (doc function-name-here)
(find-doc "part-of-name-here")
Source: (source function-name-here)
Exit: Control+D or :cljs/quit or exit
cljs.user=> (let [user {:user/keys {:id 56}}
#_=> company {:company/keys {:id 28}}
#_=> {{user-id :id} :user/keys} user
#_=> {{id :id} :company/keys} company]
#_=> [user-id id])
[56 28]
oh and there was another bizarre thing I didnāt mention. There was a weird lapse in referential transparency lol
The macro took a map that was basically a little calculation DSL for form fields {:my-field [:sum [:field :field2])
so I had
(def calcs {:my-field [:sum [:field :field2]))
(re-frame-sub-generator-macro calcs)
was blowing up and saying calcs
wasnāt defined š I didnāt even dig into that and just put the map directly into the call