Fork me on GitHub
#clojurescript
<
2019-12-13
>
Hi08:12:23

hello! how this translates to Clojurescript?

let response = await fetch('/article/fetch/post/user', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json;charset=utf-8'
  },
  body: JSON.stringify(user)
});
I have tried with
(def fe (js/fetch ""
                    #js {:method "POST"
                         :body "567985679865796579"
                         }))
but something does not work. It sends empty POST request from browser to the host but body is not included.

p-himik09:12:36

Are you sure?

Hi09:12:19

hmm. this is crazy - now it works. I must have observed previous failed attaempt šŸ˜®

Hi09:12:24

thanks!

šŸ‘ 4
Hi12:12:02

how to check if value in map is a number or type of cljs.core.Delay ? will this work (if (= 'cljs.core.Delay (type val.....` ? the data I have prints into REPL like this {:hash_ #object[cljs.core.Delay {:status :pending, :val nil}], ...

p-himik12:12:33

cljs.user=> (instance? Delay (delay 1))
true

4
victord12:12:24

Hello, The documentation of swap! functions states:

Atomically swaps the value of atom to be:
(apply f current-value-of-atom args)
But when i try it in the repl, i got strange behavior with assoc function:
cljs.user=> (def a (atom {:a 1 :b 2 :c 3}))
#'cljs.user/a
cljs.user=> (apply assoc @a [:a 24])
{:a 24, :b 2, :c 3}
cljs.user=> (swap! a assoc [:a 24])
{:a 1, :b 2, :c 3, [:a 24] nil, nil nil}
On the 3 line i just do what the doc said: (apply f current-value-of-atom args). And i got the result i expected, but when i finally use swap!, i give a different result. Do you think it's a documentation issue or i missed something?

lsenjov12:12:59

So you've done (swap! a assoc [:a 24]), which transforms into (assoc @a [:a 24])

lsenjov12:12:19

Remember that (apply assoc @a [:a 24]) becomes (assoc @a :a 24)

lsenjov12:12:35

You may be thinking of assoc-in , which goes (assoc-in @a [:a] 24)

thheller12:12:15

@victord args will be ([:a 24]) so its a seq of args

p-himik12:12:18

I've done a similar mistake in the past, and I've always wondered - where does the nil nil pair come from?

thheller12:12:49

(apply assoc @a '([:a 24]))

p-himik12:12:15

Yeah, I meant - where does it come from when using apply assoc?

lsenjov12:12:38

At a guess for some reason it's calling it with 3 additional undefined in the cljs?

lsenjov12:12:59

It throws an exception clj side

victord12:12:23

Thanks for the answers, My original idea was to update multiple key/values at once with:

cljs.user=> (apply assoc {:a 1 :b 2 :c 3} [:a 24 :b 23])
Which actually works. How could i obtain the same behavior with the constraints that the key/values to update are in vec and the map to update is an atom?

lsenjov12:12:32

You just want (swap! a apply assoc [:a 24]) ?

p-himik12:12:06

swap! works exactly like apply in this sense. (swap! a assoc :a 24 :b 23) .

lsenjov12:12:39

(swap! a (partial apply assoc) [:a 24])

lsenjov12:12:42

I think that works

victord12:12:16

@p-himik that's true but i need my input to be a vec:[:a 24 :b 23]

victord12:12:19

Thanks Isenjov, (swap! a (partial apply assoc) [:a 24]) It works. I'm now considering to use a map instead šŸ™‚ (swap! a merge {:a 24 :b 32})

šŸ‘ 8
lilactown21:12:17

I have an implementation namespace like lib.impl.foo that has some macros + runtime functions (itā€™s a .cljc file). in my lib.core namespace, I have a macro foo that emits a call to lib.impl.foo/bar-macro which emits a call to the lib.impl.foo/baz function. When I use the lib.core/foo in another namespace, I get a bunch of warnings about ā€œUse of undeclared var lib.impl.foo/bazā€ This makes sense to me, since itā€™s emitting a bunch of calls to a namespace that doesnā€™t appear in that ns requires. However, Iā€™m not sure how to solve this problem without moving everything in lib.impl.foo into lib.core Any ideas?

Aleed00:12:45

mind if I ask what an "implementation namespace" refers to? (saw them inside helix, too)

lilactown00:12:01

itā€™s a pattern that some library authors use to sort of hide implementation details without declaring stuff as ā€œprivateā€

lilactown21:12:47

nevermind, the issue was that I had neglected to require the impl namespace in my CLJS lib.core ns