This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-08-08
Channels
- # aleph (4)
- # beginners (5)
- # cljs-dev (21)
- # clojure (155)
- # clojure-dev (3)
- # clojure-italy (10)
- # clojure-losangeles (3)
- # clojure-nl (2)
- # clojure-russia (5)
- # clojure-spec (42)
- # clojure-uk (11)
- # clojurescript (170)
- # code-art (1)
- # component (3)
- # core-async (28)
- # cursive (70)
- # data-science (3)
- # datascript (1)
- # datomic (28)
- # emacs (6)
- # gorilla (1)
- # graphql (2)
- # jobs (1)
- # lein-figwheel (4)
- # lumo (7)
- # off-topic (13)
- # om (63)
- # parinfer (66)
- # planck (1)
- # re-frame (22)
- # reagent (2)
- # ring-swagger (53)
- # rum (3)
- # sql (13)
- # test-check (2)
- # unrepl (48)
- # vim (8)
- # yada (33)
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 twiceif you aren't returning an {:action (fn [])}
from the mutation then it'll be run twice on local
[ 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)))}))
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...
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 thank you! 😄 I would like to know why this is though - its not mentioned in the docs as far as i know
Aand was happy too early... seems its still broken there 😕 i'm starting to think there is some weird logic mistake on my side
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))})
In the mutate function i just had to put a #
before (let
--> the action has to be a function 😄
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)