Fork me on GitHub
#om
<
2017-04-27
>
danburton01:04:53

Suppose I have an om.next SPA. The send function forwards queries to the server, and the server interprets the om.next query as appropriate. This works just great for reads. But now what we want to do is server-side mutations. Is using (om.next/transact! c '[(server-mutation!)]) an appropriate way to initiate something like this? We can't figure out how to write a (client-side) mutate parser function in the same way that we write our read parser function: in such a way that it will instruct the reconciler to send the mutation to the server for interpretation server-side.

danburton01:04:45

Come to think of it, are there any simple examples of using om.next for a plain old CRUD app?

matthavener03:04:32

@danburton: yup, that transact! call looks correct

matthavener03:04:54

as for sending, you just return {:remote true} from your mutate parser function

twashing17:04:15

Hey @matthavener , thanks for the response. We’re doing exactly that.

twashing17:04:20

(defmethod mutate 'my/key
  [{:keys [state ast]} k param]
  {:action (fn [] (swap! state (fn [v] (assoc v k param))))
   :remote true})

twashing17:04:28

But the send function isn’t being fired when we make a call like.

twashing17:04:17

(om/transact! reconciler ['(my/key {:foo :bar})])

petterik17:04:52

@twashing Are you passing anything to the :remotes key of the reconciler?

petterik17:04:17

when calling (om/reconciler)

macrobartfast18:04:05

are there any om next oriented tutorials like those in the book Learning Clojurescript?

macrobartfast18:04:58

seems like most of the tutorials are oriented to the old version of Om, and as noob really can't figure it out.

macrobartfast18:04:44

it's so different it seems like it should really gotten a new name (at least that would have allowed for me to figure out which documentation/tutorials are current).

claudiu20:04:29

@macrobartfast noob here also just starting to get the hang of it.

anmonteiro20:04:09

I feel like people don’t find these too easily, but the devcards examples in the Om repo are also a nice example of how to write simple Om Next applications: https://github.com/omcljs/om/tree/master/src/devcards/om/devcards

claudiu20:04:23

@anmonteiro thank you. totally missed the devcards 🙂

macrobartfast20:04:39

@anmonteiro thank you for suggesting devcards.

macrobartfast20:04:19

@anmonteiro looking through the code at https://github.com/omcljs/om/blob/master/src/devcards/om/devcards/tutorials.cljs is helpful... is there a companion post or are there instructions for getting this running?

anmonteiro20:04:13

@macrobartfast that’s the code for the tutorials in the Wiki https://github.com/omcljs/om/wiki#om-next

macrobartfast20:04:28

ah, right... doh!

currentoor20:04:38

Anyone ever run into a situation where follow on reads (keywords at the end of a mutation literal) don’t cause the appropriate re-render?

macrobartfast21:04:11

I really need some help here. I just want to get a basic CRUD app up in Om or Om Next. The tutorials are fantastic (thank you for everyone who worked on them) but the introductory ones seem to stop before a CRUD implementation, and the more advanced ones seem designed to skip over a basic CRUD implementation to focus on the cool features of ClojureScript or Om. I'd really like to see a DB backed CRUD as opposed to an atom. A lot of tutorials seem to just use an atom as opposed to a database in the interest of brevity. At least one uses Datomic, which is cool, but a bit of a step for a beginner. There are of course implemented ToDo apps, but they don't come with tutorials, and it's hard to tell if they are current. I'll hopefully be able to contribute this once I learn it, but there's a catch 22 at this point. There are books, but they seem to be anywhere from a year to four years old and are broken by recent changes. I fully acknowledge my limitations, but it seems like you have to be proficient in clojurescript to get going in it.

macrobartfast21:04:21

So, can anyone suggest a DB backed CRUD tutorial/book/article that's current? Or can someone just give me a basic end-to-end idea of what I can piece together?

macrobartfast21:04:14

I think I need the equivalent of what a senior developer would tell an intern on their first project (i.e. use this for your front-end, use this for your database, tie them together with this...)

macrobartfast21:04:47

As you mentioned that I was just typing out that untangled is too advanced and complex for me right now...

wilkerlucio21:04:00

you will end up using the local atom anyway, this is your local representation, I guess what you are missing is how to integrate with remotes (server side), so the untangled tutorials have some coverage on it

wilkerlucio21:04:25

Untangled is just a layer on top of Om.next, it implements stuff you would have to do anyway (like a local parser)

macrobartfast21:04:48

which is the problem (and please forgive what may seem like a lack of gratitude for your suggestion)... Untangled just obfuscates what I don't understand to start with...

macrobartfast21:04:10

it seems like it will be awesome, when I understand it...

wilkerlucio21:04:18

had you gave the videos a try? the Untangled videos are targeted for people new to Om.next too

macrobartfast21:04:39

I'll take a look again. I started watching them a month ago, but I should revisit them.

macrobartfast21:04:20

thanks for your time and suggestions!

wilkerlucio21:04:48

no worries, please ask again if you can't figure it out, it just need some time to get in your head 😉

macrobartfast21:04:24

to be honest, I had forgotten about untangled (and had to go learn more of the basics)...

macrobartfast21:04:46

and when I was looking at it they were very friendly and helpful in their slack channel.

twashing21:04:36

@petterik I have something like the below. That send isn’t getting fired, and I don’t know why.

twashing21:04:45

(let [v-prime (assoc v :foo :bar)

      send (fn [{:keys [remote]} cb]
             (cb v-prime))

      parser (om/parser {:read read :mutate mutate})

      reconciler (om/reconciler
                  {:parser parser
                   :send    send
                   :remotes [:remote]
                   :state main-menu})

      state {:state (om/app-state reconciler)}

      r (parser state [:treasury.manual-money-movement/create])]

  (empty? r))

macrobartfast21:04:12

@wilkerlucio the untangled videos are actually great... I just didn't know enough when I tried to watch them last time.

twashing23:04:01

In an Om.next app, are we allowed to do :remote mutations?