Fork me on GitHub
#beginners
<
2020-10-24
>
dumrat05:10:07

Trying to integrate https://github.com/nadbm/react-datasheet into a re-frame project. `(defn main-panel []   (let [name (re-frame/subscribe [::subs/name])]     [:div      [:h1 "Hello from " @name]      [(r/adapt-react-class ReactDataSheet)       {:data [[{:val 1} {:val 2}] [{:val 3} {:val 4}]]        :valueRenderer #(:val %)}]]))` This results in: <div><h1>Hello from re-frame</h1><span tabindex="0" class="data-grid-container"><table class="data-grid"><tbody><tr><td class="cell"><span class="value-viewer"></span></td><td class="cell selected"><span class="value-viewer"></span></td></tr><tr><td class="cell"><span class="value-viewer"></span></td><td class="cell"><span class="value-viewer"></span></td></tr></tbody></table></span></div> So no data is visible. Am I doing something wrong?

herald11:10:46

The valueRenderer function will get passed a JS object keyed by string. I think #(.-val %) will work, although it might break with closure advanced compilation, so I'd use cljs-oops #(oget % :val) instead.

seancorfield05:10:50

Maybe #re-frame and/or #react channels will have folks with more knowledge @dumrat?

germ1307:10:27

12:07 AM I have this:

(def op ["+" "-" "*" "/"])
((first op) 4 3)
This isn't working like I think it should. What I really want is to have it evaluate to this (+ 4 3) => 7. How do I achieve this given op?

delaguardo13:10:31

((resolve (symbol (first op))) 4 3)

germ1321:10:07

@U04V4KLKC that's what i needed. thanks.

practicalli-johnny02:10:49

If you can change op to a hash-map then it makes the code far simpler

(def operands {"+" + "-" - "*" * "/" /}
((operands "+") 4 3)

germ1323:10:16

@U05254DQM i did have that option, but i wanted to get a deeper understanding of symbols and evaluation in clojure. thanks.

Marek Jovic07:10:38

Hello! I am searching for information on solutions on how to synchronize debit/credit transactions in Clojure. I am thinking to have a database as well. I want to have atomic operations. But maybe possibly have good performance. Please suggest any hints, articles, advice, books, etc...

rakyi09:10:34

for a high level overview http://dataintensive.net is very good

💪 6
Mark Wardle20:10:33

Hi. Please may I ask some advice on clojure.spec.alpha? I’d like to generate the definition for the contents of a map from an existing vector I’m already using elsewhere. I naively tried this:

(def field-names ["PCD2" "PCDS" "DOINTR" "DOTERM" "OSEAST100M"
                  "OSNRTH100M" "OSCTY" "ODSLAUA" "OSLAUA" "OSWARD"
                  "MSOA11" "CALNCV" "STP"])

(s/def ::postcode-data (s/keys :req (map #(keyword (str *ns*) %) field-names)))
(s/describe ::postcode-data)
(s/valid? ::postcode-data {})
But as s/keys is a macro, it doesn’t evaluate the map. Is there an alternative approach? Do I have to write my own macro to get this to work?

seancorfield21:10:45

It's not easy with Spec 1 but it will be easier with Spec 2 -- although that isn't ready for production use yet.

👍 3
Mark Wardle08:10:00

Thanks. I hadn’t thought of that!

seancorfield21:10:03

What we've done at work is go the opposite way: we start with the spec, then get its form and pull the list of keys out and use that programmatically @mark354

schmee21:10:16

@mark354 there is also Malli which just hit 1.0 https://github.com/metosin/malli

Mark Wardle08:10:57

Wow. That looks really interesting. Thanks for the pointer. Looks like a better way to both specify AND document your structures.

yubrshen23:10:56

How to express in deps.edn with clj (CLI) to place a directory in classpath for yogthos/config? I have environment definitions at config/dev/config.edn thus I need to have config/dev on the classpath. I figured out the following deps.edn would work, but looks ugly:

yubrshen23:10:09

{:paths
 ["src" "config/dev"]
 :deps
 {org.clojure/clojure           {:mvn/version "1.10.1"}
  com.datomic/datomic-pro      {:mvn/version "1.0.6202"} ; for peer API, found the version number in the Datomic software installation directory, and has to insall by bin/maven_install
  org.postgresql/postgresql     {:mvn/version "9.3-1102-jdbc41"}
  http-kit/http-kit                      {:mvn/version "2.4.0"}
  metosin/reitit                {:mvn/version "0.5.5"}
  yogthos/config                {:mvn/version "1.1.7"}}
 :aliases
 {:server {:main-opts ["-m" "grok.core"]}
  :dev {:extra-path ["config/dev"  "env/dev"]}
  :test {:extra-paths ["test" "config/test"]
         :extra-deps {lambdaisland/kaocha           {:mvn/version "0.0-529"}
                      lambdaisland/kaocha-cloverage {:mvn/version "1.0.63"}}
         :main-opts ["-m" "kaocha.runner"]}
  :socket-repl {:jvm-opts ["-Dclojure.server.repl={:port,50505,:accept,clojure.core.server/repl}"]}
  }}
by placing "config/dev" to the array of :paths, based on the tutorials, I should just to place with the aliases where I need the functionalities. But I could not get it working yet. (Edit: with help from @seancorfield, my mistake was the mis-spelling of "extra-paths" to "extra-path")

seancorfield23:10:27

@yubrshen this line

:dev {:extra-path ["config/dev"  "env/dev"]}
should be :extra-paths

seancorfield23:10:19

If you're using aliases for :dev, :test, then you wouldn't need "config/dev" in :paths I think?

yubrshen23:10:43

@seancorfield Thanks! Amazing you know the answer before my finishing my question!

seancorfield23:10:05

And then when you build for prod? Or is that just the default?

yubrshen23:10:10

I hope so, after your correction.

3
yubrshen23:10:36

@seancorfield Thanks a million! You're right. With your corrections, the following works:

{:paths
 ["src"]
 :deps
 {org.clojure/clojure           {:mvn/version "1.10.1"}
  com.datomic/datomic-pro      {:mvn/version "1.0.6202"} ; for peer API, found the version number in the Datomic software installation directory, and has to insall by bin/maven_install
  org.postgresql/postgresql     {:mvn/version "9.3-1102-jdbc41"}
  http-kit/http-kit                      {:mvn/version "2.4.0"}
  metosin/reitit                {:mvn/version "0.5.5"}
  yogthos/config                {:mvn/version "1.1.7"}}
 :aliases
 {:server {:main-opts ["-m" "grok.core"]}
  :dev {:extra-paths ["config/dev"  "env/dev"]}
  :test {:extra-paths ["test" "config/test" "config/dev"] ; added "config/dev" for 'clj -M:test --watch' to work
         :extra-deps {lambdaisland/kaocha           {:mvn/version "0.0-529"}
                      lambdaisland/kaocha-cloverage {:mvn/version "1.0.63"}}
         :main-opts ["-m" "kaocha.runner"]}
  :socket-repl {:jvm-opts ["-Dclojure.server.repl={:port,50505,:accept,clojure.core.server/repl}"]}
  }}