om-next

2016-09-09T04:44:23.000037Z

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

2016-09-09T04:44:43.000038Z

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

2016-09-09T04:45:00.000039Z

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

2016-09-09T04:45:21.000040Z

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

2016-09-09T04:47:14.000041Z

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

2016-09-09T04:50:41.000043Z

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_metail 2016-09-09T07:32:21.000044Z

@machty - did you solve your problem?

2016-09-09T08:44:29.000045Z

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.

2016-09-09T13:15:04.000047Z

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

2016-09-09T13:15:31.000048Z

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_metail 2016-09-09T13:17:00.000049Z

@machty - examples:

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

am-a_metail 2016-09-09T13:17:19.000051Z

(defmulti mutate om/dispatch)

am-a_metail 2016-09-09T13:17:50.000052Z

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

am-a_metail 2016-09-09T13:18:34.000056Z

or something

2016-09-09T13:19:52.000057Z

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

2016-09-09T13:20:26.000058Z

(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_metail 2016-09-09T13:21:32.000059Z

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

2016-09-09T13:22:01.000060Z

refer to my original example

2016-09-09T13:22:01.000061Z

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

2016-09-09T13:22:23.000062Z

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

2016-09-09T13:23:05.000064Z

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

2016-09-09T13:24:16.000065Z

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.

2016-09-09T13:30:00.000066Z

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

2016-09-09T13:33:28.000067Z

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

2016-09-09T13:33:47.000068Z

maybe i should take a step back

2016-09-09T13:34:10.000069Z

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

2016-09-09T13:34:29.000070Z

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

2016-09-09T13:37:13.000071Z

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

2016-09-09T13:38:08.000072Z

i believe i follow so far

2016-09-09T13:38:22.000073Z

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

2016-09-09T13:38:28.000074Z

and then i will try more things

2016-09-09T13:39:00.000075Z

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

2016-09-09T13:40:05.000076Z

ah just got it to work!

2016-09-09T13:40:37.000078Z

had to use list

2016-09-09T13:40:41.000079Z

i guess that makes sense

2016-09-09T13:41:00.000080Z

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

2016-09-09T13:41:26.000081Z

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

2016-09-09T13:41:42.000082Z

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

2016-09-09T13:41:48.000083Z

the world is slowly making sense

2016-09-09T13:42:21.000084Z

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 '

2016-09-09T15:07:51.000086Z

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

2016-09-09T15:07:59.000087Z

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

2016-09-09T15:09:25.000088Z

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)

2016-09-09T15:11:02.000091Z

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.

2016-09-09T15:14:46.000092Z

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

2016-09-09T15:14:51.000093Z

it does something

2016-09-09T15:15:08.000094Z

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

2016-09-09T15:15:43.000095Z

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

2016-09-09T15:15:50.000096Z

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

2016-09-09T15:16:16.000097Z

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

2016-09-09T15:18:30.000098Z

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

2016-09-09T15:57:32.000099Z

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