untangled

NEW CHANNEL: #fulcro
anmonteiro 2016-08-24T00:21:56.000829Z

https://twitter.com/anmonteiro90/status/768241791598465025

👍 2
grzm 2016-08-24T18:34:50.000831Z

I think I need a nap. I'm having a hard time even figuring out how to look this up. I've got a mutation that's creating an invitation. The mutation is returning the tempid map as it should, but I also want to return some extra data such as the invitation token in the response. I'm blanking on how to do this. Any pointers to an example or a reference?

2016-08-24T19:00:19.000832Z

@grzm we’ve found that 99% of the time, there is no need to return any data from the server because the client does an optimistic update

2016-08-24T19:00:40.000833Z

we only return non-tempid data from the server through reads

grzm 2016-08-24T19:00:47.000834Z

gotcha.

2016-08-24T19:00:54.000835Z

not sure if others have played with returning data through mutations

2016-08-24T19:02:08.000836Z

should work if you put a :value key in addition to a :tempids key I would think

grzm 2016-08-24T19:02:09.000837Z

Maybe some way of doing a post-mutation data fetch?

grzm 2016-08-24T19:02:36.000838Z

Right now I can't even find the basic docs on what a mutation can return.

2016-08-24T19:02:56.000839Z

yeah we readily admit that documentation needs a lot of work

2016-08-24T19:03:09.000840Z

I believe that it is the same format as Om's

grzm 2016-08-24T19:03:14.000841Z

Oh, I'm blaming my lack of a nap 🙂

2016-08-24T19:03:14.000842Z

as far as server mutations are concerned

2016-08-24T19:03:34.000843Z

so you should be able to return a :value on a server mutation

2016-08-24T19:03:50.000844Z

that value would end up in the client app state, keyed by the mutation symbol

grzm 2016-08-24T19:04:01.000845Z

I was skimming through the om stuff, but didn't find anything there either.

2016-08-24T19:04:22.000846Z

tried asking in #om?

grzm 2016-08-24T19:04:22.000847Z

Not that it's not there, just that I'm not finding it right now.

grzm 2016-08-24T19:04:35.000848Z

That's the next step 🙂

grzm 2016-08-24T19:05:18.000849Z

Thanks, @ethangracer

👍 1
2016-08-24T19:42:51.000850Z

@grzm: We have done something like post-mutation data fetches in a few places. We have something like this: (om/transact! this [(widget/new-data-stream {:widget-id ~id}) (widget/load-data-stream {:widget-id ~id})])

2016-08-24T19:43:59.000851Z

Where load-data-stream is:

;; Does a remote lazy load via untangled functions - note that the remote line
;; here is special.
(defmethod m/mutate 'widget/load-data-stream
  [{:keys [state component ref] :as env} _ {:keys [id] :as params}]
  {:remote (df/remote-load env)
   :action (fn []
             (let [query (om/focus-query (om/get-query widget/DefaultWidget) [:widget/data-source])]
               (df/load-data-action state query
                                    :ident (if id [:widget/by-id id] ref))))})

2016-08-24T19:44:56.000852Z

And df is untangled.client.data-fetch

tony.kay 2016-08-24T22:34:35.000853Z

FYI: Anyone wanting to use a newer version of Figwheel. Our script and setup in user.clj in various projects won't quite work due to recent sidecar changes. The new component-local-state recipe in the untangled cookbook has been updated to work properly. The changes of interest are in user.clj.

tony.kay 2016-08-24T22:35:50.000856Z

Demonstrates doing some graphical stuff with HTML5 canvas involving both props and component local state to accomplish quick updates for transient interactions, while maintaining important data in app state.

tony.kay 2016-08-24T22:38:05.000858Z

@grzm What @therabidbanana said, OR you can embed a (untangled/load-data) call directly in your top-level transaction as a post-read. The cookbook has such an example (demonstrating non-optimistic update).

tony.kay 2016-08-24T22:38:22.000859Z

let me see if I can find that...maybe it was in the getting started videos

tony.kay 2016-08-24T22:43:24.000860Z

https://youtu.be/t49JYB27fv8?t=24m56s

tony.kay 2016-08-24T22:44:03.000861Z

@grzm this section of the video shows how to do "non-optimistic" updates....which is essentially sending a mutation to the server, and following it with a fetch.

tony.kay 2016-08-24T22:45:01.000862Z

This is a question that is asked periodically: How do I return a value from a mutation? The answer is "you don't". Mutations are abstract, there is no query (which would be needed to merge such a response to app state). Instead, you do a mutation, and follow it with a read of the thing you want to know.

tony.kay 2016-08-24T22:46:40.000864Z

By doing it via a read, you include a query (and possibly a post-mutation). This combination allows you to integrate the data properly. Without the query (and possibly the post-mutation) Om/Untangled would have no idea of where to put your "return value", nor how to normalize it into the database.

tony.kay 2016-08-24T23:10:46.000865Z

The final result from that video is on the basic-server tag of the getting started files: https://github.com/untangled-web/getting-started-video.git (checkout the basic-server branch)

tony.kay 2016-08-24T23:18:31.000867Z

@ethangracer no return values from mutations. See above comments.

👍 1
tony.kay 2016-08-24T23:20:39.000868Z

I added these comments to the cookbook, so at least they're written down somewhere "official" now

👍 1