Fork me on GitHub
#clojurescript
<
2018-10-28
>
mfikes01:10:49

Give ClojureScript master a spin with your day-to-day work this week. All show-stoppers have been fixed and a release will be cut soon.

llsouder03:10:05

I got atoms with data :string1 :string2 and I want to call clj-ajax/POST but I cannot get it to work. curl calls work fine. Everything I google says to use :params and :format :json but thats not working for me.

dvcrn07:10:38

Hey guys! Another follow up to my code splitting question. I have a browser extension written in clojurescript. Looks like this

worker/
| -- core.cljs

safari/
| -- browser.cljs
chrome/
| -- browser.cljs
browser.cljs contain the browser specific abstractions to interact with it. Like getting settings and so on. Currently browser.cljs are all having the namespace myextension.browser. During build, I use cljsbuild say that for build target chrome, it should use chrome/ and worker/ as source paths. Inside core.cljs I can then just require myextension.browser like I would always do. Now I am trying to port this to the cli to get familiar with it, but have my issues replicating this kind of setup. Module splitting says I could just use :modules and emit multiple modules, then let them include each other, but since all the browser abstractions have the same namespace, this seems a little more difficult One idea was to maybe just export a node/require style package and use that inside my core.cljs, but if possible I'd really like to solve this in cljs alone

dvcrn07:10:09

It would be great if I could keep the abstractions on separate namespaces like myextension.safari.browser, then have a myextension.safari.core entrypoint that uses that, but the code that I share between all the extensions needs functions defined inside the browser package Without import magic, myextension.safari.core should import myextension.safari.browser, then tell myextension.common to use that package

lilactown17:10:08

@dvcrn I think you’ve already come up with the solution; you need to invert the direction of your dependencies

👍 4
lilactown17:10:04

so myextension.common should be a dependency that the safari, chrome, etc. modules bring in

lilactown17:10:09

if you’re going to use module splitting anyway

lilactown17:10:34

I’m not sure that module splitting is the best tool for this. I’m not sure what you mean by > port this to the cli

lilactown17:10:55

it sounds like what you have going on with the different builds is working

dnolen18:10:23

module splitting is not for this scenario

dnolen18:10:47

module splitting is only about managing time to download a large SPA

cullan18:10:50

I am having trouble with boot-reload in my clojurescript project. I am storing the game state in an atom. I want the game to reset to the starting state upon reload. The game loop uses setInterval to make a timer. When my code reloads it seems to wipe out the game state before calling my function that I set with on-jsload and that makes me lose track of the timer. Is there a way to run a function to clear the game state before reloading?

dnolen18:10:17

@dvcrn one simple ways is just by managing your classpath

👍 4
dvcrn01:10:57

you mean how I currently do it in cljsbuild? During build I tell it to use safari/browser + worker/ for Safari builds, For chrome I do chrome/browser + worker/ and so on x/browser is always a implementation of myextension.browser currently, so multiple files have the same namespace, but on build it's only using one of them

dnolen18:10:51

doing this via cli & deps, you can just have aliases refer to different parts of classpath for your different builds

lilactown18:10:21

(deftype State [react-ref]
  IDeref
  (-deref [_]
    (first react-ref))

  IReset
  (-reset! [_ v']
    ((second react-ref) v')
    v')

  ISwap
  (-swap! [o f]
    (-reset! o (f (-deref o)))))


(def foo (State. ["foo" (fn [_] (println "reset"))]))

(swap! foo identity "bar")

lilactown18:10:24

Error: No protocol method ISwap.-swap! defined for type hooks-demo.hooks/State: [object Object]

lilactown18:10:27

what am I missing?

lilactown18:10:19

reset! works

lilactown19:10:29

ah right, swap! is multi-arity. have to implement all of the arities

cullan19:10:42

With some help from the #boot channel I figured out my problem. I needed to create my atom with defonce instead of def.

lilactown19:10:13

god, React context is soooo much nicer to use without the render props boilerplate

Dustin Getz21:10:29

Can you share a snippet or screenshot of what you're talking about specifically

lilactown21:10:19

(hx/defnc Display [_]
  (let [{:keys [name count]} @(<-context state-context)]
    (hx/c [:div name ": " count])))

👏 4
lilactown21:10:01

<-context is just a rename of useContext

Dustin Getz21:10:29

Can you share a snippet or screenshot of what you're talking about specifically

lilactown21:10:58

here’s what a component looks like using render props for comparison