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.
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 twiceonce for remote, once for local
if you aren't returning an {:action (fn [])}
from the mutation then it'll be run twice on local
Hmm must be once remote and once local then since i do return that
ah, right
My gui seems to show only each 2. state it should have though
As if it would do both in the browser
is the :action
thunk run twice? or just the mutation?
i think it should only do the latter
let me take a look
Seems to be the action too
have you set remote: true
?
[ 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)))}))
Hmm where would is set that? 😄
(Sorry - i'm new to the environment)
afaik, that should only be printing once, maybe i'm wrong
Hmm well thats what i would have said too, but the console tells me wrong xD
And my GUI :x
ah, by default there's a single remote database, so it will be run twice
Hmm but why would i get only each 2. state if one of them runs in the remote
sorry?
if you mean the state is what it should be, i think that's because om makes sure the state is only mutated once
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...
oh
try putting your (let [st @state...
inside the thunk
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!
hurrah
@sundarj thank you! 😄 I would like to know why this is though - its not mentioned in the docs as far as i know
i am also curious
Hmm
Aand was happy too early... seems its still broken there 😕 i'm starting to think there is some weird logic mistake on my side
dang
oh wait, your swap!
is wrong
swap! can only take a single function
yea i changed that already 😄
I noticed it right after posting - sry
np 😛
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))})
looks ok to me
I'd like it more if it wouldn't 😄
haha sorry 😅
No problem 😄 thanks for your time though!
no worries
@sundarj fixed it 😄
It was my dumbess of ignoring some facts from the tutorial
In the mutate function i just had to put a #
before (let
--> the action has to be a function 😄
I don't know how i missed that
you and me both
glad you figured it out 😄
we kept saying 'thunk' too hahahaha
Uhm i just took that from you, my english is not so good so i went with it 😄
a thunk is a term for a function with no arguments 😛
Aha 😄 learnt something more ^^
😁
that's not true, is it?
as i understand it, a thunk returns a closure that serves to be called at some other time
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?
It shows up in the :ast as a join, but its :query is a vector.
I wouldn't consider a function like println
a thunk, though, even though you can call it as (println)
right, yeah. it's a little more nuanced than 'function with no args', but thats close enough imo
Fair enough 😄