Fork me on GitHub
#untangled
<
2017-03-14
>
codxse11:03:56

Hi, I just finished first-mutation video tutorial. I have a question. I still don't understand why on method m/mutate 'app/add-item, we have to manually integrate ident. For example calling (uc/integrate-ident! state iatem-ident :append list-path). But on MyList don't, for example only calling (uc/initial-state Item {:label "A"}) and ident already there.

urbank11:03:28

@codxse Take my explanation with a grain of salt. InitialAppState is meant to get an initial structure for the data, and establish the tables. So things declared in InitialState get normalized automatically at app start-up.

urbank11:03:42

this doesn't happen at every mutation (not automatically)

codxse11:03:33

@urbank do you mean when we call (om/factory MyItem) ?

urbank11:03:06

@codxse Hm... I don't think so. A component doesn't need to be rendered to participate in the initial normalization. It just needs to be in InitialAppState and IQuery, as well as have an Ident (I may be wrong, though, I'm quite new)

codxse11:03:54

Ok, no problem. I get it 😉

urbank11:03:15

@codxse Someone's probably going to come online who's better at explaining this. In the meantime, have you seen this video by Tony Kay?

codxse11:03:08

Ok, let me see.

urbank11:03:55

@codxse Also, merge-state! described here might be useful to you (though I haven't yet used it)

codxse11:03:08

great, it will be helping

wilkerlucio17:03:44

@codxse when you app starts the state, it uses the query (and it's metadata) to normalize your database, during the normalization process the indexes are going to be created and the previous initial data will be converted into idents, but that only happens on the initialization, where you data is denormalized, after that you are responsible to keep it normalized, that's why you need to do that on the mutation. makes sense?

tony.kay17:03:23

with one refinement: server responses (or any tree-based novelty with a query run through (om/merge! reconciler tree-of-data query-for-tree-of-data ) are auto-normalized.

tony.kay17:03:45

Untangled's merge-state! is similar (but it let's you give a component for the query)

tony.kay17:03:31

Mutations are the abstractions over generalized database (and their remote counterpart) operations...most commonly editing a few props on already normalized data, followed by optional tweaks to graph edges)

wilkerlucio17:03:49

interesting, I didn't knew the normalization also happened on merge, cool stuff 🙂

codxse17:03:30

cool! it make more clear to me. :))

gardnervickers23:03:34

@tony.kay When doing a df/load on a component with :ui/* keys in the query and in the entity, they should remain untouched right?

tony.kay23:03:09

So, @adambros found a bug when loading by ident that would mess that up

tony.kay23:03:23

but yes, that is how it should work

tony.kay23:03:33

I am guessing you're doing that 😕

tony.kay23:03:03

the merge story in Untangled is one of the most complicated bits of logic, actually, because of our desire to make that happen correctly in a number of cases

gardnervickers23:03:51

Yup, but it’s a problem we’ve been able to avoid. I was just wondering what it should be so if we do hit another issue with it I can investigate. Thanks!

tony.kay23:03:52

The "should" is: 1. If you asked for it and didn't get it, it gets removed 2. If you didn't ask for it, and you already had it, it is kept 3. Since :ui/??? are not part of what you "ask the server for", they should fall into (2)

gardnervickers23:03:15

Gotcha, makes sense!

tony.kay23:03:21

Added as issue #69 on U.C.