Is there a good way to get the reconciler to queue a send of the entire root query to a particular remote every time the state changes?
(I'm still trying to work out a good way to implement live queries.)
@peeja Everytime the state changes on the client or on the server?
On the client, could you use TxListen?
On the server, I push some change notifications of a read that's changed along with datomic's basis-t. Using basis-t (or something similiar) I can avoid sending requests I've already read data for when there are frequent updates. I use (om/transform-reads reconciler [:key-to-read])
to queue the reads locally and remotely.
Lastly, to find all reads for a specific remote, could you maybe call (and memoize) (keys (parser env (om/query (om/app-root reconciler)) remote))
?
On the client. :tx-listen
might do itβ¦
Maybe the parser already runs as I need it?
I tried swap!
ing the state and didn't see it, but perhaps transact!
will always do what I need
and that's what I'd be using in real life anyhow
Oh, no, transact!
will only read what I tell it to readβ¦
Yeah. Firing off another transact!
in :tx-listen
depending on what was transacted or what's being transacted maybe?
Doesn't that recurse infinitely?
I guess it feels like I'm doing extra work to undo things that Om's doing "for me".
Depends on how you examine what is being and what was transacted
hmm
I don't want to transform-reads
a specific set of keys, I want the whole query
(as processed by the parser for the given remote)
My plan is to have something stateful stay informed of changes to the query, and adjust the live data it listens for appropriately
which means it always needs a new copy of entire root query any time it (may) change, to run a diff
What if you put this stateful thing in :shared
and call it either from your root component everytime it updates, or via :tx-listen
depending on what you need
I feel like the components shouldn't know this thing exists
:tx-listen
may work
How do I transact!
to read the entire root query from a remote?
I don't think you can do it out of the box, but I can think of two ways of doing it
1. call the parser, then call transact!
with some result
How would I "call the parser" other than through transact!
?
2 (the way I'm doing it), wrap your parser in a function which looks for a dynamic var, for example *allowed-remotes*
, and returns nil
if the env's :target
is not in *allowed-remotes*
. Binding it using binding
You'd get the parser from (:parser (:config reconciler))
and call (#'om/to-env reconciler)
to get env
Ewβ¦ π
π
Solution to all om.next problems is another parser middleware
I've got middleware out the wazoo as it is, but it's not fixing this one yet π
How does *allowed-remotes*
help?
I believe I'm not getting the parser call I want in the first place
(binding [*allowed-remotes* #{:the-remote-you-want}] (om/transact! reconciler (om/get-query (om/app-root reconciler))))
would get the full query with only the remote you want
no?
Oh, I see. Sure, that'll work.
Oh sorry, I apparently left that bit out
Can I accomplish the same thing by force
ing the remote? I'm not entirely clear on what that does.
I don't know. Maybe. I'm not clear either of how to use it
I've never used it
Yeah, I can't get that to do anything useful. Oh well. *allowed-remotes*
may be what I'm stuck with, as hacky as it is. π
Thanks for the help!