Fork me on GitHub
#beginners
<
2018-07-06
>
Sen16:07:24

Does anyone know some nice source on how Clojure prevents dead-locks and concurrency problems with managing database? Want to use it to show my team why Clojure can fix our problems

Roy Truelove17:07:42

If the deadlocks are happening on the database I don’t know how / if Clojure can help with that much. Unless the database is Datomic 🙂

Sen17:07:12

Yeah, I'm sorry for not clarifying it, I meant using Clojure with Clojure related tech stack such as Datomic

ghadi17:07:59

immutable values by default, and the "atomic succession model" are pervasive

👍 1
ghadi17:07:11

(f v) ==> v'

sova-soars-the-sora18:07:55

clojurescript set background color?

Sen18:07:33

(defn simple-component []
  [:div
   [:p "I am a component!"]
   [:p.someclass
    "I have " [:strong "bold"]
    [:span {:style {:color "red" :background-color "black"}} " and red "] "text."]])

[simple-component]

sova-soars-the-sora18:07:16

right on. i mean using (set! ... )

Sen18:07:44

😆 well, I knew it should be something harder

sova-soars-the-sora18:07:08

(set! (.-innerHTML element) text) works great, but i cannot figure out the syntax to change backgroundcolor or even color (font color) for that matter

bronsa18:07:52

just look at how you'd do it in javascript, translating it to cljs should be trivial

sundarj18:07:40

it would be something like (set! (.. element -style -backgroundColor) "black")

noisesmith18:07:49

unless you are using a proper DOM management lib, in which case it's a no-op because someone else is going to clobber your DOM :D

1
noisesmith18:07:15

(and you end up with something like what Sen suggests above)

sova-soars-the-sora18:07:30

(set! (.-backgroundColor (.-style (.getElementById js/document "title"))) "blue") works

👍 1
sova-soars-the-sora19:07:03

okay, i had messed up the syntax completely: (set! (whatever element thing sub thing) prop) ... had my props living nestedly

sova-soars-the-sora19:07:34

nevermind, i don't know why it works in a live repl and not in my actual code lol

noisesmith19:07:19

are you using something like reagent or om?

sova-soars-the-sora19:07:27

OR I was editing code in a conditional that never eval'd to true!

sova-soars-the-sora19:07:45

very barebones at the moment. lol gotta laugh at yourself sometimes.

justinlee21:07:18

is there a way to set properties using doto?

noisesmith21:07:06

what kind of properties?

justinlee21:07:54

the XY is I have js code that looks like this:

ctx.fillStyle = 'rgb(213, 224, 236)';
      ctx.strokeStyle = '#cecece';
      ctx.beginPath();
      ctx.moveTo(0, 0);
because that’s just how the 2d context object’s api works. doto would be nice (i think) to clean up all of the method invocations, but it isn’t clear if it is possible to intersperse the lines where you set properties on the object

noisesmith21:07:10

yeah, but you'd likely need a function helper to get ctx into the right argument position

noisesmith21:07:27

(for the assignments that is)

noisesmith21:07:04

and then set! might be a macro which means actually a macro helper

noisesmith21:07:15

@lee.justin.m this works perfectly with the goog.object api

(cmd)cljs.user=> (def o #js{})
#'cljs.user/o
(ins)cljs.user=> (doto o (goog.object/add "foo" "bar") (goog.object/add "baz" "quux"))
#js {:foo "bar", :baz "quux"}
(ins)cljs.user=> (.-foo o)
"bar"
(ins)cljs.user=> (.-baz o)
"quux"

noisesmith21:07:46

so I guess goog already wrote that helper function I was thinking of

justinlee21:07:21

yea okay i just got to a similar place by writing a oset function that wraps goog.object/set

noisesmith21:07:02

I wonder what the difference between g.o/add and g.o/set is

noisesmith21:07:27

oh, add is strict about the key being absent, so set is probably a better choice

justinlee21:07:29

my brain has never really liked using string literals as l-values but i guess is should just get over that

noisesmith21:07:11

it would be trivial to make something that accepts a keyword and just calls name under the hood

justinlee21:07:24

oh duh right. good call

noisesmith21:07:16

while you were at it you could let it accept var-args like assoc, and use doto :D

noisesmith21:07:18

(defn oassoc [o & kvs] (doseq [[k v] (partition 2 kvs)] (g.o/set o (name k) v)))
something like this

justinlee21:07:02

this is where scooby doo goes in six directions at the same time

noisesmith21:07:58

(cmd)cljs.user=> (require '[goog.object :as g.o])
nil
(ins)cljs.user=> (defn oassoc [o & kvs] (doseq [[k v] (partition 2 kvs)] (g.o/set o (name k) v)) o)
#'cljs.user/oassoc
(ins)cljs.user=> (oassoc #js{} :foo 1 :bar 2)
#js {:foo 1, :bar 2}
LGTM

justinlee21:07:32

that partition/doseq is a nice idiom to remember

noisesmith21:07:52

I learned it from let - or a variation of it - IIRC

noisesmith21:07:41

oh, destructure, which let uses

justinlee21:07:47

cool that works quite nicely

noisesmith21:07:35

for java to run it, don't use uberwar, use uberjar

noisesmith21:07:03

uberwar is for passing the object to an external container

noisesmith21:07:32

usually with an uberwar you are going to pass the thing to apache tomcat (what amazon's elastic beanstalk uses) or to a jetty server

😀 1