Fork me on GitHub
#clojurescript
<
2017-10-09
>
lovuikeng01:10:13

@genec that sounding more like the old IBM/BPEL for this kind of bidirectional feedback loop, which gets messy once the processes get too complex. You may want to check out http://www.onyxplatform.org/ with commercial backing of http://pyroclast.io/, otherwise https://nervous.io/

Chris Bidler01:10:34

Precisely so - I replaced an Oracle BPEL workflow engine with AWS Simple Workflow, which is the predecessor to Step Functions - though Pyroclast looks very interesting also. I was aware of it but hadn’t taken the time to look into it, so thanks for posting that link!

jmb02:10:00

Hey guys. I'm trying to build a fitness tracker site using Chestnut (+http-kit +garden +reagent). It's an SPA with a front end and backend. I've integrated Secretary and Accountant for client-routing and modified the app div in my one HTML page using Reagent components. My question is should I create separate folders and/or files for routing and loading content into my div?

lovuikeng02:10:37

@jmb you may use re-frame-template as reference for the secretary setup lein new re-frame myapp +handler +routes

jmb02:10:00

I'll take a look. Thanks. I've been trying to organize my app in a way that's manageable

alice03:10:15

Having growing paiins after switchiing from Reagent to Rum, anyone have experience?

lovuikeng04:10:47

there is experimental https://github.com/chpill/re-frankenstein/, otherwise stick with re-frame+reagent as the best match 🙂

thedavidmeister06:10:07

@alice i use hoplon/javelin, it's not react based though

alice06:10:22

Thanks for the input, but I have a strong love for React 😊

thedavidmeister06:10:30

@alice have you looked at hoplon?

tatut06:10:25

which just keeps state in one atom and the UI code gets a handle to send events (records)

rauh08:10:25

Slightly OT: I have super fast reloads of JS files with figwheel in Chrome, it basically downloads all files in parallel. Though, in Firefox it's very slow. It just downloads them consecutively. Any tips? Server is Openresty w/ HTTP/2.

pesterhazy08:10:48

@rauh, is there a reason why you are using another server on top of figwheel?

rauh08:10:48

@pesterhazy Not really, Openresty actually doesn't pipe them thru to Figwheel web server but serves them from disk. I haven't checked in a while: Does Figwheel server run HTTP/2 nowadays? By switching to Openresty last year my full page refresh got to 2sec from like 6+ seconds with figwheel.

pesterhazy08:10:29

ah that I don't know

dominicm08:10:43

@rauh I'd be curious to know if it's faster with Fx 57

dominicm08:10:49

Just because "everything" is

pesterhazy08:10:34

firefox and chrome are different when it comes to caching resources - chrome defaults to aggressively caching every js file that doesn't have caching headers set

rauh08:10:16

@dominicm IDK, haven't tried 57.

dominicm08:10:18

I'd be curious: your problem might go away by itself 🙂

rauh08:10:01

@pesterhazy I don't think it's a caching problem. The files (possibly 20-30) are loaded consecutively, instead of all together. Do reloads for you guys in FF happen in parallel?

rauh08:10:38

320 Request, 8.6 MB Transferred, 1.55sec in Chrome vs 16.2sec in FF 😞

rauh08:10:40

@dominicm Not really faster with FF 57.

pesterhazy08:10:29

why would requests be made serially? That doesn't make sense... unless you already have a ton of connections to the server open maybe?

dominicm09:10:03

@pesterhazy I'm wondering the opposite, how does chrome do them in parallel? They're initiated by js.

dominicm09:10:38

It must keep do something clever like figuring out that the next line of code doesn't depend on the js being loaded (how is that even possible?) and then continue execution until they find a point it becomes ambigous.

pradyumna09:10:40

hi, i am using doo for testing clojurescript with node. when i set watch-mode to auto, the tests run twice. not able to figure out why. any advice?

pesterhazy09:10:26

so maybe it is about caching?

rauh09:10:44

I have an ugly hack that works with the latest figwheel version, which allows for a custom loader. It's very fast now. It's not super clean since it'll call figwheel :on-js-load too early. But I don't care about that

rauh09:10:47

(defn figwheel-load-js-file
  [url cb]
  (let [fulfil #()
        reject #()]
    (js/document.head.appendChild
      (doto (.createElement js/document "script")
        (set! -type "text/javascript")
        (set! -charset "UTF-8")
        (set! -src url)
        (set! -onload fulfil)
        (set! -onreadystatechange fulfil)
        (set! -onerror reject))))
   ;; HACK:
  (cb true))
(gobj/set goog.global "FIGWHEEL_IMPORT_SCRIPT" figwheel-load-js-file)

rauh09:10:31

@pesterhazy It's def not about caching since my Openresty server will actually return a 304 for all unchanged files and a 200 for all changed ones. Probably another reason I get super fast reloads in general.

pesterhazy09:10:31

you could try reproducing the problem with figwheel-template to see if it's specific to your setup

dominicm09:10:15

@rauh it could be client-side cahcing?

dominicm09:10:34

Chrome is aggressively caching the js files (even though http hasn't told it to) and firefox isn't.

pesterhazy09:10:49

@dominicm, that's what I referred to above 🙂

dominicm09:10:01

Yeah, I figured that's what you had intended 🙂

dominicm09:10:22

I'm a bit confused that version of figwheel-load-js-file is faster...

dominicm09:10:29

than goog.loadMany() I'm guessing..

rauh09:10:38

I don't think it's caching, if it were it'd load faster. I also don't have issues with stale files, just reloading performance.

rauh09:10:55

For you the reloading is fast? As in sub-second? Even with 20-30 files reloading?

dominicm09:10:30

I don't recall it being particularly slow. But I'm not an active figwheel user anymore.

Bravi10:10:11

is it possible to call an event from another event?

(re-frame/reg-event-db
  :end-game
  (fn [db]
    (assoc db :has-ended? true)))

(re-frame/reg-event-db
  :select-color
  (fn [db [_ color]]
    (when (= (:real db) color)
      ;=> somehow call :end-game
      )))

Bravi10:10:58

so if I can’t control the order, then I won’t be able to do this, right?

Bravi10:10:39

or perhaps I misunderstood

juhofriman10:10:01

I quess you could for something like:

(re-frame/reg-event-fx
  :select-color
  (fn [{:keys [db] :as cofx} [_ color]]
    (when (= (:real db) color)
      {:dispatch [:end-game]}
      )))

juhofriman10:10:19

Pseudocode, did not try that one out 🙂

Bravi10:10:22

oh, so I can change the state values too. I thought it needed to be an interceptor without touching the state

Bravi10:10:28

but now it makes sense, thanks!

Bravi10:10:53

baby steps 😄

Bravi10:10:13

I love the syntax and all

Bravi10:10:25

trying so hard to properly learn it

Bravi10:10:35

during my lunch times 😄

Bravi10:10:03

one more question if I may. can I add a timeout to \

Bravi10:10:19

(re-frame/reg-event-fx
  :select-color
  (fn [{:keys [db] :as cofx} [_ color]]
    (when (= (:real db) color)
      {:dispatch [:end-game]} <----- this dispatch right here
      )))

Bravi10:10:01

but then I need to be able to clear that timeout too.. damn this is tough

juhofriman10:10:10

What do you mean by timeout?

Bravi10:10:29

basically I’m trying to re-create this little game here: https://broken-hose.surge.sh/ but using clojurescript this time. There, I have a timeout that ends the game. And the user has to be fast enough to click the correct answer. Clicking the correct answer resets the timeout

henrik10:10:49

@bravilogy Wrap it in a go block and use timeout

henrik11:10:34

Something like this:

(<! (go
      (<! (timeout 2000))
      {:dispatch [:end-game]}))

Bravi11:10:33

but I won’t be able to reset that timeout, will I?

Bravi11:10:07

so basically it shouldn’t get fired if the user clicks the correct answer, but rather it should start over

Bravi11:10:49

I was thinking to write an :after interceptor, that would handle the timeout

henrik11:10:19

@bravilogy Most likely a better idea, disregard my previous input

juhofriman11:10:04

I think the more “re-framish” architecture would be to trigger sort of :tick event every 500 ms or so, which checks from the app-db if the time has run out and then updates the app db accordingly.

Bravi11:10:04

and how would I determine if the time has run out?

Bravi11:10:36

I like that thinking @juhofriman but I can’t wrap my head around, how would I actually do it 😄

Bravi11:10:04

would I actually set a date of when the time will run out?

juhofriman11:10:15

I would personally try to add something like :time-left 1000 to app-db, and decrement it on each :tick fx. When it comes to zero or less, I would dispatch :end-game. So time ticking and user input are two completely separate things which just happen to operate on same data 🙂

juhofriman11:10:22

I have never done such an app with re-frame though 😛

Bravi11:10:04

but for the :tick, would you use an interval?

juhofriman12:10:56

Hmm, I would propably try to wrap timeout or interval inside reg-fx, which is sorta effect handler for ungly side effects. Check out this one https://github.com/Day8/re-frame/blob/master/docs/FAQs/PollADatabaseEvery60.md

Bravi12:10:37

thank you!

ajs13:10:50

I’m having an unusual problem with lein cljsbuild auto that I’ve not had before. It will automatically compile upon save and show that is Successfully compiled in around 1.X seconds. But this message doesn’t actually appear for about 10 seconds. Anyone else seen this recently with recent versions of the compiler?

ajs13:10:57

I wonder what it is doing in the many seconds after the apparently successful compile?

Bravi13:10:51

I followed this example: https://github.com/Day8/re-frame/blob/master/docs/FAQs/PollADatabaseEvery60.md and how can I dispatch this :interval from let’s say this bit:

(re-frame/reg-event-db
  :start-playing
  (fn [db _]
    (assoc db :is-playing? true
           :fake (random-active-color db)
           :real (random-active-color db))))

Bravi13:10:05

so basically I’d like to initiate the interval right when the game starts, in this case when :start-playing is finished updating db

lxsameer14:10:14

hey folks, I have a huge static configuration file in edn format, is there any way to use the file in compile time and use the data with goog-define ?

lxsameer14:10:23

or do you know any better solution to have a configuration file for cljsbuild ?

manutter5116:10:09

There's also a #re-frame channel you could post this in.

mfikes17:10:29

@lxsameer If you are using Leiningen, unquoted forms inside defproject in your project.clj will be evaluated.. Leveraging that capability, you could read the EDN, extract the config of interest, and inject it into :closure-defines as desired.

lxsameer18:10:03

Cool. Good to know that thanks

jeaye18:10:23

@bravilogy You don't use dispatch for fx.

jeaye18:10:18

@bravilogy Instead, you'll use reg-event-fx for :start-playing and you'll return a map of the effects. In this case, {:interval [{...}]}

jeaye18:10:32

Oh, damnit, it's already been answered.

Bravi18:10:33

thank you. is reg-fx different from reg-event-fx?

jeaye19:10:19

Yep, it is.

jeaye19:10:58

@bravilogy reg-fx doesn't return anything of consequence. reg-event-fx returns the effects to apply (with built-in ones like :db and :dispatch).

jeaye19:10:32

re-frame takes a good amount of reading to grasp all of this; I'd recommend going through the official docs a few more times.

danielcompton20:10:06

The value that doesn’t support name is nil

lilactown23:10:11

I have a dependency that is requiring a CSS file, and I'm getting this error: Error: Parsing file /Users/<snip>/Code/clojure/presentation/node_modules/spectacle/lib/themes/default/codemirror.css

lilactown23:10:33

I'm using the lein figwheel template

lilactown23:10:12

what's the best way to solve that? obviously i'm not using webpack, which I assume the developers of spectacle assume I'm using 😕