Fork me on GitHub
#re-frame
<
2018-05-23
>
pablore00:05:52

Having trouble using leiningen re-frame template. Getting an cljs.core.init is not a function upon starting figwheel

gadfly36101:05:47

@pablore did you call your project cljs? I.e. did you do lein new re-frame cljs? If so, you should try naming your project something else, like lein new re-frame foobar

pablore01:05:18

oh I named it “name.cljs”

pablore01:05:37

because it is a port of some other project

gadfly36102:05:12

@pablore I'd try a name without dots .. that may cause some wonky behavior and isn't idiomatic. Given the error message, it looks like it lopped off name from name.cljs

mikethompson02:05:40

I've added the following to the README > *Troubleshooting note:* for <project-name> don't use cljs. That name will confuse the compiler and you will (later) see errors like cljs.core.init is not a function

👍 8
jco10:05:21

I'm making a simple game using re-frame. When the game has finished I want to trigger an event (to save the score). Currently, I have a reg-sub that returns whether the game is finished. Is it good style to create a dummy (non-visual) component ("view") that subscribes to this "game-over" value, and if it is true dispatches an event to save the score? Or is there some better way of doing this?

hkjels10:05:19

How do you determine that the game is over?

troglotit10:05:06

I’d go with event :game-state-changed and check the winning move here.

👍 4
gklijs10:05:17

@jco I had a small pokemon game, where after enough good answers the game ends, and allows you to play again. You could have an event handler witch as co-effect saves the score?

jco10:05:19

@hkjels I determine that the game is over via a subscription that checks whether all blocks have reached their final positions (sokoban).

jco11:05:08

@troglotit OK, that could be nice, thanks.

jco11:05:33

@gklijs I'll probably do something like it. The question was mainly how to call this event handler, but I'll probably have to check if the game is over from my make-a-move event handler (by directly accessing the app db), instead of relying on the game-over subscription.

gklijs11:05:47

(defn successful-try
  [db]
  (let [new-db (-> db
                   (update :score inc)
                   (update :total-tries inc)
                   (assoc :tries-left nil))]
    (cond (= 10 (:score new-db)) (-> new-db
                                     (assoc :re-start-enabled true)
                                     (assoc :question {:finished true}))
          (:next db) (assoc new-db :next-enabled true)
          :else (assoc new-db :show-next-when-ready true))))
this was mine solution

gklijs11:05:51

(re-frame/reg-event-db
  :select
  (fn [db [_ id]]
    (if (:tries-left db)
      (let [new-db (update-in db [:options id :selected] not)
            selection (get-selected (:options new-db))
            answer (get-in db [:question :answer])]
        (if (= (count selection) (count answer))
          (if (= selection answer)
            (successful-try new-db)
            (failed-try new-db))
          new-db))
      db)))
to be called when the correct answer was given.

jco11:05:38

Nice, do you have your game up and running somewhere?

gklijs12:05:34

No, but the source is on github, https://github.com/gklijs/pokequiz it uses the open pokeapi.

gklijs12:05:16

It was quickly setup in a week during train and some evenings, nothing that fancy. But was quite fun last Christmas.

jayeldoubleu21:05:46

is there a visualization or charting library that integrates well with re-frame that is simpler than d3? I am reading sensor data from a firebase realtime database and want a live graph of readings over the past 24 hours.

shaun-mahood21:05:05

I've heard great things about vega and vega-lite https://github.com/metosin/vega-tools and https://github.com/metasoarous/oz look like good places to start

☝️ 4
jayeldoubleu21:05:48

thanks, I will look into it

mikethompson21:05:33

If you want simpler then look at vega-lite

mikethompson21:05:49

vega and vega-lite are layers over the top of D3

mikethompson21:05:06

vega is very powerful, but also quite a bit to learn

mikethompson21:05:19

vega-lite is much simpler and probably powerful enough

mikethompson21:05:33

Just to be clear, oz and vega-tools (links above) let you embed vega (and vega-lite) into reagent.

jayeldoubleu22:05:46

thanks. I have read the Using Stateful JS Components doc. Just with not being very familiar with react/reagent or d3 makes it seem like a pretty daunting task