0

Im sure I have read somwhere how it is possible to use the reconciler to test query expressions in Om Next directly but im not able to find the source again or figure out if this is possible based on the Om documentation. Is this possible to do so and if it is, how?

What I have right now to test is using the parser but I was hoping for a better way using the reconciler:

(parser {:state (atom state)} (om/get-query MyQuery))
user3139545
  • 6,882
  • 13
  • 44
  • 87

2 Answers2

0

This is how I currently find the value of top level keywords:

(defn query [kw]
  (let [res (my-parser {:state my-reconciler} `[[~kw _]])]
  (when (not-empty res) (apply val res))))

So in your case you could try:

(my-parser {:state my-reconciler} (om/get-query MyQuery))

It looks like the value for :state can either be a state you give it as in your example, or the reconciler itself as in my example.

Chris Murphy
  • 6,411
  • 1
  • 24
  • 42
  • There's nothing to stop you from putting the reconciler at the `:state` key in your environment, but there's very little reason you'd want to do that. The state key is meant to point to the `:state` contained within the reconciler, so that you can read/mutate on the state outside of your UI code. – egracer Feb 04 '16 at 05:54
  • I want to query on the state that is inside the reconciler from outside of the UI code (outside of a component). That is a useful thing to do, and why the `{:state my-reconciler}` option exists. The question asker wanted to 'use the reconciler', meaning query on the actual state as it is at any point in time - the real state that is inside the reconciler. So I was simply answering the question. – Chris Murphy Feb 04 '16 at 06:03
  • I feel like we're saying the same thing, my apologies if I misunderstood. I'm not as clear on what the asker meant, since he seems not to want to use the parser at all. In any case, the whole reconciler has much more information (parser, indexer, send function, etc.), so saying something like `{:state @my-reconciler}` gets what you need without all the additional stuff – egracer Feb 04 '16 at 06:34
0

It depends on what you mean by "test query expressions in Om Next directly"? The code you wrote above is the only way to check how the parser will interpret the query you give it.

If you're wanting to see how the app state will be normalized and denormalized using the queries you provide, maybe the documentation for idents and om/tree->db is closer to what you're looking for.

egracer
  • 362
  • 3
  • 10