om

Please ask the channel first, not @dnolen directly!
2017-08-08T15:59:15.179327Z

Is there a solution to calling transact! inside a merge function? The problem is the state immediately gets reset to what it was before the mutation, because the merge was passed that state.

alpox 2017-08-08T17:26:40.417566Z

Is there a special reason for that mutations in om/next are always called twice? (It is most likely my mistake, yet i don't see it :D) As example in:

(defui Counter
  static om/IQuery
  (query [this]
         [:board])
  Object
  (componentDidMount [this]
                     (go-loop []
                       (<! (timeout speed))
                       (om/transact! this '[(board/evolve)])
                       (recur)))
  (render [this]
          (let [{:keys [board]} (om/props this)]
            (apply dom/div #js {:style board-style}
                   (map-indexed (partial Cell this) board)))
          ))
i call the board/evolve mutation every timeslot, but each timeslot the mutation function is called twice

sundarj 2017-08-08T17:31:53.612209Z

once for remote, once for local

sundarj 2017-08-08T17:32:53.650467Z

if you aren't returning an {:action (fn [])} from the mutation then it'll be run twice on local

alpox 2017-08-08T17:34:46.721914Z

Hmm must be once remote and once local then since i do return that

sundarj 2017-08-08T17:35:12.737950Z

ah, right

alpox 2017-08-08T17:36:25.782437Z

My gui seems to show only each 2. state it should have though

alpox 2017-08-08T17:36:32.786750Z

As if it would do both in the browser

sundarj 2017-08-08T17:36:54.799892Z

is the :action thunk run twice? or just the mutation?

sundarj 2017-08-08T17:37:06.806956Z

i think it should only do the latter

alpox 2017-08-08T17:37:35.824286Z

let me take a look

alpox 2017-08-08T17:39:52.906982Z

Seems to be the action too

sundarj 2017-08-08T17:40:03.913321Z

have you set remote: true?

alpox 2017-08-08T17:40:06.915460Z

[  7.045s] [om.next] transacted '[(board/evolve)], #uuid "f7fdc5ce-df82-4349-a19c-661eb9c46a7b"
client.cljs?rel=1502190513674:34 i was here
client.cljs?rel=1502190513674:34 i was here
(defmethod mutate 'board/evolve
  [{:keys [state] :as env} _ _]
  (let [st @state
        temp-board (:temp-board st)
        new-board (evolve (:board st) temp-board)]
    {:action
     (let []
       (print "i was here")
       (swap! state assoc :board new-board
            assoc :temp-board (generate-temp-board new-board)))}))

alpox 2017-08-08T17:40:32.931077Z

Hmm where would is set that? 😄

alpox 2017-08-08T17:40:47.940381Z

(Sorry - i'm new to the environment)

sundarj 2017-08-08T17:41:55.981347Z

afaik, that should only be printing once, maybe i'm wrong

alpox 2017-08-08T17:42:36.006050Z

Hmm well thats what i would have said too, but the console tells me wrong xD

alpox 2017-08-08T17:42:44.010800Z

And my GUI :x

sundarj 2017-08-08T17:46:58.165294Z

ah, by default there's a single remote database, so it will be run twice

alpox 2017-08-08T17:48:23.216815Z

Hmm but why would i get only each 2. state if one of them runs in the remote

sundarj 2017-08-08T17:50:44.304290Z

sorry?

sundarj 2017-08-08T17:53:05.393369Z

if you mean the state is what it should be, i think that's because om makes sure the state is only mutated once

alpox 2017-08-08T17:53:59.427982Z

Hmm no the state is not as it should be. The problem is that of a series of states 1, 2, 3, 4..... i get only states 1, 3, 5...

sundarj 2017-08-08T17:54:17.439952Z

oh

sundarj 2017-08-08T17:58:00.586885Z

try putting your (let [st @state... inside the thunk

alpox 2017-08-08T18:01:21.719849Z

d'oh... i put everything except the st @state already in the thunk (the other 2 bindings) and it didn't work... Now i put that one there too because you say so... and it works!

sundarj 2017-08-08T18:01:43.734119Z

hurrah

alpox 2017-08-08T18:01:45.735030Z

@sundarj thank you! 😄 I would like to know why this is though - its not mentioned in the docs as far as i know

sundarj 2017-08-08T18:01:56.742535Z

i am also curious

alpox 2017-08-08T18:02:25.761623Z

Hmm

alpox 2017-08-08T18:03:56.819382Z

Aand was happy too early... seems its still broken there 😕 i'm starting to think there is some weird logic mistake on my side

sundarj 2017-08-08T18:05:14.868085Z

dang

sundarj 2017-08-08T18:09:00.009638Z

oh wait, your swap! is wrong

sundarj 2017-08-08T18:09:07.013728Z

swap! can only take a single function

alpox 2017-08-08T18:09:37.032581Z

yea i changed that already 😄

alpox 2017-08-08T18:09:44.036594Z

I noticed it right after posting - sry

sundarj 2017-08-08T18:10:02.048092Z

np 😛

alpox 2017-08-08T18:10:12.053665Z

I did a bit of refactoring and it looks now like this:

(defmethod mutate 'board/evolve
  [{:keys [state] :as env} _ _]
    {:action
     (let [st @state
           new-board (evolve (:board st))]
       (swap! state assoc :board new-board))})

sundarj 2017-08-08T18:11:29.100725Z

looks ok to me

alpox 2017-08-08T18:12:24.134679Z

I'd like it more if it wouldn't 😄

sundarj 2017-08-08T18:13:02.158011Z

haha sorry 😅

alpox 2017-08-08T18:14:40.217453Z

No problem 😄 thanks for your time though!

sundarj 2017-08-08T18:16:22.280314Z

no worries

alpox 2017-08-08T18:27:57.709742Z

@sundarj fixed it 😄

alpox 2017-08-08T18:28:18.722651Z

It was my dumbess of ignoring some facts from the tutorial

alpox 2017-08-08T18:28:43.738059Z

In the mutate function i just had to put a # before (let --> the action has to be a function 😄

alpox 2017-08-08T18:28:51.743151Z

I don't know how i missed that

sundarj 2017-08-08T18:30:08.791527Z

you and me both

sundarj 2017-08-08T18:30:29.805287Z

glad you figured it out 😄

sundarj 2017-08-08T18:31:12.832423Z

we kept saying 'thunk' too hahahaha

alpox 2017-08-08T18:31:54.858691Z

Uhm i just took that from you, my english is not so good so i went with it 😄

sundarj 2017-08-08T18:32:18.874076Z

a thunk is a term for a function with no arguments 😛

alpox 2017-08-08T18:32:28.880117Z

Aha 😄 learnt something more ^^

sundarj 2017-08-08T18:33:35.922059Z

😁

samcf 2017-08-08T18:54:50.701846Z

that's not true, is it?

samcf 2017-08-08T18:57:30.799813Z

as i understand it, a thunk returns a closure that serves to be called at some other time

2017-08-08T19:57:18.845790Z

So, it appears that when a component of a union query (branch for routing) gets updated on its own, without its parent, the :query of the read isn't the normal union, but the result of the union. Is that normal?

2017-08-08T20:03:15.057693Z

It shows up in the :ast as a join, but its :query is a vector.

rads 2017-08-08T20:10:42.310122Z

I wouldn't consider a function like println a thunk, though, even though you can call it as (println)

sundarj 2017-08-08T21:36:53.077876Z

right, yeah. it's a little more nuanced than 'function with no args', but thats close enough imo

alpox 2017-08-08T22:06:19.842583Z

Fair enough 😄