Fork me on GitHub
#om-next
<
2016-09-09
>
machty04:09:23

i'm a clojure noob and am taking a look at the om next tutorial

machty04:09:43

trying some random refactors and writing things a different way, etc

machty04:09:00

i can't get the above to work because of the (om/transact! this '[(sym)]) line

machty04:09:21

i don't understand exactly what format of data i should be trying to send through

machty04:09:14

fwiw the source line is (om/transact! this '[(increment)])

machty04:09:41

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

am-a_metail07:09:21

@machty - did you solve your problem?

hlolli08:09:29

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.

machty13:09:04

@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)])

machty13:09:31

so given that i have an already-quoted symbol stashed in sym, how do i pass that through in a way that'll work?

am-a_metail13:09:00

@machty - examples:

(om/transact! this `[(foo/bar ~{:value true})])

am-a_metail13:09:19

(defmulti mutate om/dispatch)

am-a_metail13:09:50

(defmethod mutate 'foo/bar
  [{:keys [state] :as env} key {:keys [value]}]
  {:action #(swap! state assoc :foo-bar value)})

machty13:09:52

@am-a_metail can you provide an example using only sym, where sym is already bound to a Symbol?

machty13:09:26

(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)

am-a_metail13:09:32

So you want to define in terms of sym or what sym is bound to?

machty13:09:01

refer to my original example

hlolli13:09:01

the symbol is never resolved, its just functions as key, visually better than actually a key, given that you are using defmulti.

machty13:09:23

i use a let statement to destructure a quoted symbol ('increment, 'decrement, 'double) into the sym binding

machty13:09:05

and now i want to pass along whatever's in sym to transact

hlolli13:09:16

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.

hlolli13:09:00

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....

machty13:09:28

i don't see where i'm using a multimethod

machty13:09:47

maybe i should take a step back

machty13:09:10

it's my understand that you pass a "mutation query" to transact

machty13:09:29

and the mutate fn provided to the reconciler teases apart that data and decides how to change app state

hlolli13:09:13

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).

machty13:09:08

i believe i follow so far

machty13:09:22

for now i am actually just trying to get the naive redux-y giant case statement approach working

machty13:09:28

and then i will try more things

hlolli13:09:00

ok ok, dont hesitate to ask on this channel tough.

machty13:09:05

ah just got it to work!

machty13:09:37

had to use list

machty13:09:41

i guess that makes sense

machty13:09:00

it gives me the desired granularity that the quoting syntax didn't

machty13:09:26

i was trying something like [(sym)] and i believe it was trying to IFn call the sym

machty13:09:42

which i think does a hash lookup but it wasn't being passed anything so it was getting an arity error

machty13:09:48

the world is slowly making sense

hlolli13:09:21

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 '

machty15:09:51

> 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)

machty15:09:59

@hlolli i'm still trying to parse what this means

machty15:09:25

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)

hlolli15:09:02

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.

machty15:09:46

ok, so the point of `[(do-stuff)] is to make it kinda look like do-stuff is a fn with side effects?

machty15:09:51

it does something

machty15:09:08

whereas :symbol looks closer to, say, reading from a hash

hlolli15:09:43

yes, the multimethod its a member of, not the dispatch symbol/key itself. You can dispatch on many different things.

machty15:09:50

in the end, they're both just keys that the reconciler fns have to parse, whether via a giant (case) or multimethods

machty15:09:16

do you pretty much always use (defmulti mutate om/dispatch) ?

hlolli15:09:30

yes, I never know how much the app will grow, and switching from projects without changing habits.

machty15:09:32

has anyone tried porting the om.next model to a javascript lib (similar to how redux is pretty much a js port of elm's)?