Fork me on GitHub
#om
<
2016-12-27
>
hlolli08:12:12

I think figwheel reloads differently for a css change and js change. If removeing :^once from the app-state atom does not do the trick, then try asking @bhauman. This effect of not remounting is most of the time for me a feature of figwheel. Try using instead lein cljsbuild auto if that helps.

nha15:12:28

How do I get my :send function to be called? I have a read fn called that returns {:remote true} - what am I missing?

hlolli15:12:50

@nha querying the read from a component?

nha15:12:31

@hlolli this is my component:

(defui About
  static om/IQuery
  (query [this]
         [:page/about])
  Object
  (render [this]
          (html [:div "About page"]))) 
The :default reader function gets called when the component renders:
(defmethod read :default
  [{:keys [state] :as env} key params]
  (let [st @state]
    (debug "reading " key " " params)
    (js/console.log "State : " st)
    (if-let [[_ v] (find st key)]
      (do
        (debug "-> " {:value v})
        {:value v})
      (do
        (debug "-> " {:remote true})
        {;;:value :not-found ;; NOTE: :not-found has no special meaning
         :remote true}))))
And I can see reading :page/about nil in my console. I have a :send function in the reconciler that is not called. I don’t specify a :remotes keys in the reconciler though.

nha15:12:59

I was expecting that returning {:remote true} from the read to trigger a call to the :send

hlolli15:12:04

yes, looking at your logic, you want to request for the data if it doesnt exist in the app state otherwise read. That's fine, but does the later case from if-let ever get evaluated, destructuring there within if-let that I've never used.

nha15:12:22

Yes exactly. I can see -> {:remote true} in the logs. My reconciler:

(def reconciler
  (om/reconciler
   {:state app-state
    :parser (om/parser {:read read :mutate mutate})
    :normalize true
    :send frontend.lib.send/send}))
I was expecting frontend.lib.send/send to be called after these logs.

nha15:12:32

(Thanks for looking into this btw)

hlolli15:12:06

But somehow it's still kind of stuff that om takes care of, you can return a map with {:value (find @state :key) :remote true} and om wont re-read the remote as long as you dont update the query or remount the component (resulting in losing the data).

nha15:12:06

Hmm but it is not in the initial state and send is never called

hlolli15:12:32

your send function should run. Can't see otherwise.

nha15:12:19

Alright 🙂 thanks @hlolli I’ll restart my system just in case

hlolli15:12:04

do a more miniamel example, dont use :default, use defmethod read :page/about, you wouldn't want this to be default anyway if this expands.

hlolli15:12:55

and just return a map of :value and :remote and look at console logs if the send function is at least trying to run (or it is running and silently fails)

nha15:12:38

Yeah it is not trying to run, that was my concern 😕 thanks anyway I’ll try that

peeja21:12:18

I'm not clear: should I be tacking ^:once onto all of my defuis? How do I know when it's necessary?