This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-09
Channels
- # admin-announcements (1)
- # beginners (78)
- # boot (36)
- # cider (13)
- # cljs-dev (15)
- # cljsjs (3)
- # cljsrn (10)
- # clojure (99)
- # clojure-austin (1)
- # clojure-australia (1)
- # clojure-italy (14)
- # clojure-korea (17)
- # clojure-norway (1)
- # clojure-russia (42)
- # clojure-sg (1)
- # clojure-spec (50)
- # clojure-uk (80)
- # clojurebridge (24)
- # clojurescript (83)
- # community-development (10)
- # conf-proposals (36)
- # core-async (12)
- # cursive (20)
- # datomic (38)
- # hoplon (63)
- # lambdaisland (2)
- # leiningen (6)
- # nyc (2)
- # om (54)
- # om-next (52)
- # onyx (129)
- # planck (15)
- # re-frame (38)
- # reagent (2)
- # rethinkdb (8)
- # specter (1)
- # untangled (2)
i understand why the way i have sym
in its present form isn't correct, i just can't figure out how to change it
@machty - did you solve your problem?
I wouldn't name the mutation after a function, but rather a key in a state. For your case, incrementing and decrementing, just use a mutation like 'update-click-value! and give it a parameter with the value. :onClick (fn [] (om/transact! this [(list 'update-click-value! {:count (inc count)})]) and in the mutate method swap! the global state with the value from the parameter :count. By using parameters you save yourself from writing 2 transactors for increment and decrement, and you could do anything with the value in the global state as you please.
@hlolli that sounds good to me, but for now i'm just exploring all the different ways i can express things and, in short, i can't figure out what format of data/payload transact!
is expecting. The example code provides a quoted vector of a list of a symbol (om/transact! this '[(increment)])
so given that i have an already-quoted symbol stashed in sym
, how do i pass that through in a way that'll work?
@machty - examples:
(om/transact! this `[(foo/bar ~{:value true})])
(defmulti mutate om/dispatch)
(defmethod mutate 'foo/bar
[{:keys [state] :as env} key {:keys [value]}]
{:action #(swap! state assoc :foo-bar value)})
or something
@am-a_metail can you provide an example using only sym
, where sym is already bound to a Symbol?
(i'm sorry if i'm being difficult, some of this probably has to do w the fact that i don't understand how to talk about clojure just yet... not sure if sym
is a variable/binding/something else)
So you want to define in terms of sym
or what sym
is bound to?
the symbol is never resolved, its just functions as key, visually better than actually a key, given that you are using defmulti.
i use a let statement to destructure a quoted symbol ('increment, 'decrement, 'double) into the sym
binding
ah ok, in that case this is just unquoring. But these symbols in your example dont seem to be bounded to anything. If 'increment is a dispatch on multimethod, than there's nothing to deref.
just a fun fact still
(def a 666)
(let [b `a]
(eval b))
=> 666
or
(defn c [] (+ 2 2))
(let [e `c]
~(c))
ahh dont have repl open and cant confirm this....and the mutate
fn provided to the reconciler teases apart that data and decides how to change app state
Yes, you should understand the parser, everything in transact! is sent to the parser, same for reads. And within the parser you have :read and :mutate, they expect two functions, so to break each function down we use multimethod, otherwise you could have long (case dispatch-key ....blabla...). But as style om.next users tend to use quoted symbols for mutate and keys for read (makes it look as its a function and keywords makes it looks as if you are reading from a hash-map).
for now i am actually just trying to get the naive redux-y giant case statement approach working
which i think does a hash lookup but it wasn't being passed anything so it was getting an arity error
ok, I think you weren't doing anything wrong, I see now what you ment, just confused me that you are using sym (for symbol name) for this. But backtick ` with ~ is another way like am-a-metall suggested. If you need to dereference then dont use '
> But as style om.next users tend to use quoted symbols for mutate and keys for read (makes it look as its a function and keywords makes it looks as if you are reading from a hash-map)
actually i think i just need to see a more involved example of mutation than what's on https://github.com/omcljs/om/wiki/Quick-Start-(om.next)
Well, you could do (om/transact! this `[(:update-bla)]) but doesn't look right. A key rarely acts as function, but can. Its up to you if you want to use quoted symbols or not.
ok, so the point of `[(do-stuff)] is to make it kinda look like do-stuff is a fn with side effects?
yes, the multimethod its a member of, not the dispatch symbol/key itself. You can dispatch on many different things.
in the end, they're both just keys that the reconciler fns have to parse, whether via a giant (case) or multimethods