Domanda

I'm about 2 months into a clojure/pedestal project and am just now learning about continues and am attempting to use one to enable or disable a click event on a button. The idea is that my report has a previous and next button and I want to enable or disable those buttons based on some data. My continue in my app-model looks like this...

:continue #{[#{[:report-scope]} continue-report-scope]}

And then my continue function looks like this. (Forgive the sloppy code and the condition that always proves true - my clojure is weak and I've been hacking up this function trying to get it to work.

(defn continue-report-scope
  [data]
  (let [message (get-in data [:message])
        report-scope (get-in data [:new-model :report-scope])
        {:keys [start-date end-date]} report-scope
        updated (get-in data [:updated])
        added (get-in data [:added])
        msgs []]
    (when-not (or (nil? start-date) (nil? end-date))
      (when (and (= (msg/type message) :report-scope-change)
                 (or (contains? updated [:report-scope :start-date])
                     (contains? updated [:report-scope :end-date])
                     (contains? added [:report-scope])))
        (do
          (conj msgs {msg/type :transform-enable msg/topic [:report-scope] :pager-prev [{msg/type :report-scope-prev msg/topic [:report-scope]}]})
          (if (= 1 1)
            (conj msgs {msg/type :transform-enable msg/topic [:report-scope] :pager-next [{msg/type :report-scope-next msg/topic [:report-scope]}]})
            (conj msgs {msg/type :transform-disable msg/topic [:report-scope] :pager-prev []})))))))

The problem is, these messages never make it to the renderer. I've tried change the msg/type to something different and then putting that type/topic in my transform and those messages do make it through. My guess is I need to somehow place this message directly on the emit queue (if there is such a thing), but I can't figure out how to do that. I've tried looking at the msg metadata and have seen people use ^:input to place messages on the input queue directly, but I can't find good documentation on how all that works.

Any ideas?

È stato utile?

Soluzione

Messages from continue function are intended to be placed input queue, they are there to enable recursion in transformation flow of the data model.

You should then watch specified paths in data model for changes and generate output messages for renderer based on those changes (most of the times, built-in default-emitter function is sufficient).

Have a look at this picture, i hope it makes the things clearer:

App flow with continue

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top