om-next

alberto.portilla 2016-06-16T09:39:29.000014Z

Is there a way to force a remote read even if there's already a value for that query in the local state? can't find a way to do it

2016-06-16T10:40:24.000015Z

You could probably set up your read method to choose from remote or local state depending on some conditions. The behaviour I've noticed so far is that for read with remote, the value fetched from remote will overwrite the app-state for that key. But om.next keeps surprising me, and I do have from time to time similar diffuculties.

alberto.portilla 2016-06-16T10:42:00.000016Z

Yes, om.next merges the state on a successful read. The issue here is picking the right condition to force a remote and the return value when using the remote

alberto.portilla 2016-06-16T10:43:16.000017Z

I mean, usually a remote call looks like

(defmethod read :query
  [{:keys [state]} k _]
  {:remote true :value (get @state k)})

alberto.portilla 2016-06-16T10:43:37.000018Z

but if i already have the key on my state, it will be returned while the remote call is being fetched

alberto.portilla 2016-06-16T10:44:21.000019Z

and after that, of course, the state gets updated, meaning that while the result is fetched, the app is being rendered with an old state

2016-06-16T10:45:56.000020Z

Just thinking out loud, wouldn't this be possible

(defmethod read :query
  [{:keys [state]} k params]
  {:remote (:remote? params) :value (get @state k)})
and in the defui you would query with parameters '[(:query {:remote? ?some-query})]

2016-06-16T10:47:28.000021Z

where ?some-query is a boolean.

alberto.portilla 2016-06-16T10:48:11.000022Z

Wouldnt that cause the effect that ive mentioned before?

alberto.portilla 2016-06-16T10:48:33.000023Z

the :value key is always returned when the read occurs, meaning that in first instance it will return the current state

alberto.portilla 2016-06-16T10:48:48.000024Z

and after the remote merge, itll return the new state, with the remote values fetched

2016-06-16T10:50:09.000025Z

yes that is right. But if remote is true, I would assume it would first try getting data over the wire before looking at local state. But I may be wrong, curious to know if that is the case.

alberto.portilla 2016-06-16T10:51:20.000026Z

Actually it doesnt, the first render shows the current state data, maybe im doing something wrong with it, but thats whats happening

2016-06-16T10:53:23.000027Z

ah ok I see. I am also these days having diffuculties with remote read. Your problem could be connected to the problems I am having, well I think it's quite likely when I think about it.

alberto.portilla 2016-06-16T10:54:16.000028Z

My first guess was clearing the query value on componentWillMount, but sometimes a race condition is produced

alberto.portilla 2016-06-16T10:54:30.000029Z

ill try to get a better approach

alberto.portilla 2016-06-16T10:55:19.000030Z

best way to check this is delay the remote response like x seconds, and you will see the old state rendering, and after x sec the remote state

2016-06-16T10:58:11.000031Z

ok, there must be a good way to handle these cases. So I hope to see someone else here commenting on this. If I find out a solution I let you know, and vice versa in that case.

alberto.portilla 2016-06-16T10:58:20.000032Z

sure