Fork me on GitHub
#fulcro
<
2017-10-10
>
tony.kay07:10:56

@roklenarcic I went ahead and took a first pass at filtering. It is on clojars at 0.2.0-SNAPSHOT of fulcro-sql. I added an argument to run-query, after id-set, called filtering. Filtering is a map of the form : {:table/column {:op value}}, where :op can be one of :eq, :gt, :ne, or :lt. E.g. {:account/deleted {:eq false}}. I did not yet add the join table data support, but I did add tests for this basic filtering. Have not added depth ranging yet. Something to play with. I pushed the changes on the feature/filtering branch for now.

tony.kay07:10:40

Thought maybe you could play with it and give initial feedback

Alister Lee08:10:55

@tony.kay roger that - no REST on the wire. But i do want to simulate REST routing, enabling normal bookmarking, at a minimum - bidi and pushy are my friends. I'm starting from the fulcro-template (not lein-template) and so far I've added a <base /> tag so that the <script> includes work. I think the secret sauce is here:

(ssr/build-initial-state (fc/get-initial-state root/Root nil) root/Root)
becomes:
(ssr/build-initial-state (fc/get-initial-state root/Root bidi-match) root/Root)
. Stand by.

Alister Lee11:10:58

Ah! so I think I need to call something like

(core/server-read env :query/posts bidi-match)
rather than
(fc/get-initial-state root/Root bidi-match)

tony.kay16:10:33

@clojure388 So, the template already has SSR and restful support…I mean, it doesn’t have any persisted objects to display, but I see where you’re struggling now.

tony.kay16:10:57

I don’t recommend making initial state dependent on the bidi match. Treat the initial state as just that: initial state of a shiny new app with no interactions yet. Treat a bidi match as a transform on the state. This is a transform you’re going to need to write either way…set routers to the right screen, and update app state. In the client, the transform is invoked from a mutation that is based on the match, and possibly includes triggering some reads. On the server you have the data, so it is more of a merge of that data, followed by running the same transform steps.

tony.kay16:10:23

init-state -> merge "loaded" data -> xform

tony.kay16:10:01

Otherwise you’re going to end up with a crap-ton of conditional logic in your initial state that is impossible for anyone to navigate or understand over time

tony.kay16:10:02

You xforms should be much easier to deal with, because the can be easily written to go from any legal app state to the one you desire. Thus, links in your UI can leverage them just as well as bidi matches and server renders

roklenarcic21:10:48

Hm I don't understand this error: Cannot dispatch to form-field renderer on form {:person/id 36, :person/name "Rok", :person/total -43} for field :person/name

roklenarcic21:10:25

oh wait I'm missing form support initial state

tony.kay21:10:18

So, I just pushed an update to fulcro-sql 0.2.0-SNAPSHOT. Improved filtering. See the specs and run-query docstrings for more info (on branch feature/filtering.

roklenarcic21:10:34

yeah I'll look into it after I get my modal+form working

roklenarcic21:10:56

first issue is that of course the :person-edit spot is nil initially when the application loads so ident is [person/by-id nil] and om.next complains, not sure how to handle spots in my app that use idents but the initial state is missing

tony.kay21:10:54

don’t include the :person-edit key in your initial state

tony.kay21:10:04

it is trying to normalize it, but you’ve given a value of nil

roklenarcic21:10:22

yeah but the parent component has nil in that spot already

roklenarcic21:10:32

so I don't know why it's called at all

tony.kay21:10:53

I’m saying not to use nil…don’t even put the key in state yet. Wait until something is selected

tony.kay21:10:33

If your initial state has no one to edit, then you should not compose in state for it that will just be nil 🙂

roklenarcic21:10:05

still no dice

tony.kay21:10:12

reloaded the page?

tony.kay21:10:22

you may have other spots in state that have a similar problem

tony.kay21:10:19

I gotta go…I have a scheduled thing I have to leave for. I’ll check in later

roklenarcic21:10:20

I did. Here's the state: :person-edit {:singleton {:modal [:fulcro.ui.boostrap3.modal/by-id :person-edit]}}, and the query for PersonEditModal is [{:modal (om/get-query b/Modal)} {:person (om/get-query PersonEdit)}], and PersonEdit has defsc definition :query [:person/id :person/name :person/total :person/avatar :person/active f/form-key] :ident [:person/by-id :person/id]

roklenarcic21:10:40

And then error

roklenarcic21:10:41

Invariant Violation: component ledger.ui.root/PersonEdit's ident ([:person/by-id nil]) has a nil second element. This warning can be safely ignored if that is intended.

roklenarcic21:10:05

So I don't get it, I don't have :person key at all in modal state

roklenarcic21:10:24

so why does it care what PersonEdit's ident is

roklenarcic21:10:09

This is the only usage of PersonEdit

tony.kay21:10:13

Use get-initial-state on your root component from the REPL

roklenarcic21:10:48

The state I listed was after reload.

tony.kay21:10:13

You’ve told it that PersonEdit is going to be a person, with an ident. You’ve then composed in the state of a person edit that has non…which is nil

tony.kay21:10:28

or did you?

tony.kay21:10:41

dumping the initial tree should make it a bit more clear

roklenarcic21:10:05

hm nothing about that at all in initial state

roklenarcic21:10:10

I can't make heads or tails from this

roklenarcic21:10:23

after normalization there's no :person key in that state, so that join shouldn-t be a factor

roklenarcic21:10:30

fixed it by making render conditional on the modal level

roklenarcic21:10:38

Changed render to (b/ui-modal-body nil (if person (ui-person-edit person) "PLACEHOLDER"))

roklenarcic21:10:11

Seems weird that I need to guard in render against modal rendering while it is not shown

roklenarcic22:10:36

If I want to swap an entity into the edit slot in a mutation, I also need to look up that ident in the database and use build-form to equip it with the right properties, right?