untangled

NEW CHANNEL: #fulcro
tony.kay 2016-11-16T00:06:32.004434Z

the new snapshot has support for dealing with return values from server mutations

tony.kay 2016-11-16T00:07:55.004435Z

but I think we found a bug in it...

tony.kay 2016-11-16T00:07:58.004436Z

@wilkerlucio

tony.kay 2016-11-16T00:08:57.004437Z

In general, the recommended approach is to do a mutation with a follow-on remote read and a post-mutation. The new return value support makes that better, but unfortunately there was something amiss. Um...who was using that? Did we fix it? Sorry, lot's going on

wilkerlucio 2016-11-16T00:10:04.004438Z

@tony.kay I remember that I read you talking about it, the new return value support, but I can't remember how it was supposed to be used

tony.kay 2016-11-16T00:10:12.004439Z

The basic API is to install a return-handler method at app start time, which hacks into the merge

tony.kay 2016-11-16T00:10:43.004440Z

See the parameter of that name in the client construction function

tony.kay 2016-11-16T00:11:10.004441Z

generally you'd make a multimethod on the symbol that has a RV, and co-locate the defmethod for the return next to the mutation

tony.kay 2016-11-16T00:11:38.004442Z

I think @jasonjckn was trying it out

wilkerlucio 2016-11-16T00:11:38.004443Z

cool, I'll check it out

tony.kay 2016-11-16T00:11:48.004444Z

the bug has to do with where in the process it runs

wilkerlucio 2016-11-16T00:11:49.004445Z

curiosity: how does the tx/fallback captures an error above?

tony.kay 2016-11-16T00:12:02.004446Z

fallback runs if there is a real server hard error

tony.kay 2016-11-16T00:12:12.004447Z

e.g. throw an exception on server and generate a status code of 500

tony.kay 2016-11-16T00:12:31.004449Z

I think you have to throw an ex-info

tony.kay 2016-11-16T00:12:54.004450Z

fallbacks are about reallllly unhappy path

tony.kay 2016-11-16T00:14:03.004451Z

the behavioral tests on it pass, but the subtle problem is that the atom is hit twice and ends up undoing the return value's change

tony.kay 2016-11-16T00:14:47.004452Z

so someone needs to tinker with the plumbing to move that up. Haven't had time to look at it.

wilkerlucio 2016-11-16T00:16:06.004453Z

ha, now that you pointed out, my template actually had an example with it :picard-facepalm:

tony.kay 2016-11-16T00:16:23.004454Z

oh right...I knew I coded an example somewhere

wilkerlucio 2016-11-16T00:17:58.004455Z

it seems to be working

wilkerlucio 2016-11-16T00:18:16.004456Z

but I wish it provided the full enviroment, not just state

tony.kay 2016-11-16T00:18:55.004457Z

you're not in a parser at that stage, you're in a merge

tony.kay 2016-11-16T00:19:14.004458Z

which just means you should include context in the return value to reconstruct what you need

tony.kay 2016-11-16T00:20:12.004459Z

the bug is going to force a breaking change.

wilkerlucio 2016-11-16T00:20:13.004460Z

I remember the idea about colocating the response, do you think in our return-handler we could just call the parser again and use a different target function to dispatch the response?

tony.kay 2016-11-16T00:20:56.004462Z

I don't have the query at that stage. It isn't passed through by Om

tony.kay 2016-11-16T00:21:19.004463Z

so, you'll have to put all needed info into your response.

tony.kay 2016-11-16T00:21:30.004464Z

which means you might have to pass extra info in the mutation itself

tony.kay 2016-11-16T00:22:03.004465Z

I'm not sure the rv handling really helps much. I think follow-on remote reads make more sense in most cases

tony.kay 2016-11-16T00:23:23.004466Z

validation, for example, is solved better by having a cljc file that makes validation possible on both sides without needing to worry about a response. Other responses would be better served (due to normalization needs) by asking a question of the server with a proper query as part of the overall transaction

tony.kay 2016-11-16T00:23:52.004467Z

which is the main reason I had never added it...I think in general most cases don't need it, or there is a better "Om" way of doing it.

wilkerlucio 2016-11-16T00:24:37.004468Z

what about validations that can't be handled on the client, for example to check if a user name is taken, what you think should be the common way to handle?

tony.kay 2016-11-16T00:24:55.004469Z

The double-swap problem in the current implementation just points out the additional incidental complexity of the overall solution required for return values to function properly in the context of Om

tony.kay 2016-11-16T00:26:03.004470Z

(load-data :name-taken :params { :desired-name "boo" }) with a UI query on [:name-taken '_]

👍 1
tony.kay 2016-11-16T00:26:25.004471Z

in other words: ask 🙂

wilkerlucio 2016-11-16T00:26:31.004472Z

in my case, I'm currently trying to implement some authentication mechanisms. when you detect unauthorized access, you fail with some HTTP status or do something else?

tony.kay 2016-11-16T00:27:00.004473Z

there is a gamut of possibilities. Choose one in specific

tony.kay 2016-11-16T00:27:12.004474Z

password failure on login?

wilkerlucio 2016-11-16T00:27:42.004475Z

session expired, or user trying to access resources he doesn't own

tony.kay 2016-11-16T00:28:22.004476Z

probably a combo of throwing exceptions on the server and a global error handler in the client

tony.kay 2016-11-16T00:28:40.004477Z

those are global concerns

tony.kay 2016-11-16T00:29:16.004478Z

the first should go t a login screen. The second is someone trying to break in and should be considered less friendly (and common)...who cares how badly you treat an attacker?

tony.kay 2016-11-16T00:29:32.004479Z

easy enough to do the former via a js redirect

tony.kay 2016-11-16T00:29:57.004480Z

:network-error-callback is a function of two arguments, the app state atom and the error, which will be invoked for every network error (status code >= 400, or no network found), should you choose to use the built-in networking record.

tony.kay 2016-11-16T00:30:04.004481Z

from the client constructor

tony.kay 2016-11-16T00:30:08.004482Z

global network error handler

wilkerlucio 2016-11-16T00:30:10.004483Z

right, makes sense

tony.kay 2016-11-16T00:30:28.004484Z

I think the template demos login, right?

wilkerlucio 2016-11-16T00:30:41.004485Z

it does, I saw the tx/fallback example there

tony.kay 2016-11-16T00:30:45.004486Z

so, a mutation followed by a "who am I"

wilkerlucio 2016-11-16T00:30:49.004487Z

it uses local, not global handling

wilkerlucio 2016-11-16T00:31:17.004488Z

no big deal 🙂

tony.kay 2016-11-16T00:31:21.004489Z

that's fine too. Login is a localized concern. The ones you named are more global

tony.kay 2016-11-16T00:31:36.004490Z

expire and illegal can come from anywhere at any time

tony.kay 2016-11-16T00:31:42.004491Z

don't want to code fallback into everything

wilkerlucio 2016-11-16T00:31:51.004492Z

yeah, agreed

wilkerlucio 2016-11-16T00:33:16.004493Z

thanks @tony.kay! I'll go back to coding now 🙂

tony.kay 2016-11-16T00:33:29.004494Z

cool

tony.kay 2016-11-16T00:33:31.004495Z

welcome

mitchelkuijpers 2016-11-16T08:27:49.004502Z

Btw @tony.kay I tried the return-handler and had lot’s of problems, the first one is that you get an app-state atom which will be overwritten by the merge. After that we tried to trigger a mutation from the return-handlerthat somehow get’s run in the between the merge and also get overwritten.. :lol: Now we fixed it by wrapping our return handler in a setTimeout, which works but feels dirty.

mitchelkuijpers 2016-11-16T08:29:49.004503Z

I think https://github.com/untangled-web/untangled-client/pull/53 this fixes it already ^^

tony.kay 2016-11-16T15:27:10.004509Z

@mitchelkuijpers: yes, but untested

tony.kay 2016-11-16T15:27:46.004510Z

Did it last minute yesterday

tony.kay 2016-11-16T15:31:00.004511Z

I am considering changing the api and putting it back in merge but making return handler be f state -> state instead of giving the atom.

tony.kay 2016-11-16T15:32:15.004512Z

Torn. The new way is probably better because it can be placed after post mutations

tony.kay 2016-11-16T15:32:41.004513Z

Ie using the atom but fixed

mitchelkuijpers 2016-11-16T15:35:10.004514Z

@tony.kay Or you could make an atom in the merge en then run them all and then dereference the atom and use that to merge on (that was the solution we thought of)

mitchelkuijpers 2016-11-16T15:36:37.004515Z

But running it after the merge also makes it possible to trigger transactions from the return handlers (although I am not sure you should do this)

tony.kay 2016-11-16T15:41:19.004516Z

Ah that's true, but seems silly to add an atom in fp for that

mitchelkuijpers 2016-11-16T15:41:58.004517Z

That’s true but then it feels like the same api as mutations..

mitchelkuijpers 2016-11-16T15:42:25.004518Z

When you put it that way the maybe pull request #53 is the right solutino

tony.kay 2016-11-16T15:43:04.004519Z

I'm headed to work now, I'll give it more thought on the wat

tony.kay 2016-11-16T15:43:12.004520Z

Way

mitchelkuijpers 2016-11-16T15:43:27.004521Z

I’ll wait it out, we have a hack for now 🙂

mitchelkuijpers 2016-11-16T15:43:36.004522Z

Always a good idea to let it simmer

tony.kay 2016-11-16T16:17:48.004523Z

So, my proposed fix doesn't work. That section only runs for queries

tony.kay 2016-11-16T16:17:52.004524Z

@mitchelkuijpers

mitchelkuijpers 2016-11-16T16:25:21.004525Z

Thnx for the heads up @tony.kay So then it will probably become the f state -> state. I’m off now if I think of a elegant solution I’ll let you know

tony.kay 2016-11-16T16:25:34.004526Z

Yeah, that's what I'm going to try next

afhammad 2016-11-16T17:01:45.004527Z

Trying out untangled for first time using https://github.com/untangled-web/untangled-template-workspace. Doesn’t seem to be working out of the box. Client can’t reach server on localhost:3449/api when running (start-figwheel). Also /cards.html can’t find cards.js. Am I missing something or is it still WIP?

tony.kay 2016-11-16T17:02:11.004529Z

you have to run the server

tony.kay 2016-11-16T17:02:41.004530Z

the instructions are pretty clear about how to use it, I thought. If you find an error let me know

afhammad 2016-11-16T17:04:29.004531Z

ah, i had the server running but i was using 3449 instead of 3000 in browser

tony.kay 2016-11-16T17:08:01.004532Z

right....that too 😄

afhammad 2016-11-16T17:14:58.004536Z

Do I need to run anything else for cards to build?

afhammad 2016-11-16T17:23:10.004537Z

This did the trick (start-figwheel [:dev :cards])

tony.kay 2016-11-16T17:25:56.004538Z

FYI: I'm releasing an update to U.C. 0.6.0-SNAPSHOT which has a breaking change on the new return handler API. Details coming as soon as I've tested in against all of the cookbooks to make sure I've not broken anything.

gardnervickers 2016-11-16T17:28:44.004539Z

Thanks for the heads up

tony.kay 2016-11-16T17:50:26.004540Z

ok, I just released 0.6.0 of Untangled Client to clojars

tony.kay 2016-11-16T17:54:33.004541Z

untangled-template-workspace and cookbook pushed with updated versions

👍 1
tony.kay 2016-11-16T18:52:35.004544Z

I just pushed an updated devguide. I added documentation on the new load function, as well as the mutation merge support. Both are in section H.

tony.kay 2016-11-16T18:54:09.004546Z

The new load should be considered of alpha quality, as we have not used it much yet. I'll be using it more heavily in the coming days and will bug fix things as I find them.

👍 1
tony.kay 2016-11-16T19:53:35.004547Z

NOTE: cookbook now has a recipe showing a couple of working examples of the new load API: https://github.com/untangled-web/untangled-cookbook/tree/master/recipes/load-samples

2016-11-16T22:40:47.004552Z

does untangled have a built in helper for the pattern of conditionally doing a server read on df/load [x/by-id "123"] only if the data is not present in the app-state?