Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incremental Processing of Streaming Download? #27

Open
Folcon opened this issue Oct 25, 2018 · 3 comments
Open

Incremental Processing of Streaming Download? #27

Folcon opened this issue Oct 25, 2018 · 3 comments

Comments

@Folcon
Copy link

Folcon commented Oct 25, 2018

I've been working out how to get incremental results, not sure if you want to support it as cljs-http might be moving from xhrio (#21). I've got an issue open there, and it can be plugged in at either level.

It's based on me reading through kennethkalmer's PR (#18) and working backwards to figure out where the change should start.

The essence of it is here:

(defn request->xhrio-options
  [{:as   request
    :keys [on-success on-failure on-progress]
    :or   {on-success      [:http-no-on-success]
           on-failure      [:http-no-on-failure]}}]
  ; wrap events in cljs-ajax callback
  (let [api (new js/goog.net.XhrIo)
        _ (when (and on-progress (fn? on-progress))
            (doto api
              (.setProgressEventsEnabled true)
              (events/listen goog.net.EventType.PROGRESS on-progress)))
        ]
    (-> request
        (assoc
          :api     api
          :handler (partial ajax-xhrio-handler
                            #(dispatch (conj on-success %))
                            #(dispatch (conj on-failure %))
                            api))
        (dissoc :on-success :on-failure :on-progress))))

You can now define an on-progress fn that does something with the partial response:

:on-progress
(fn [e]
    (let [resp-text (.getResponseText (.-currentTarget e))]
        resp-text))

Not sure if you want to support it, or should I try upstream?

@danielcompton
Copy link
Contributor

danielcompton commented Oct 25, 2018

The goal of re-frame-http-fx has always been to be a very thin wrapper around cljs-ajax that introduces as few new concepts of features as possible, so I would suggest trying upstream first. Appreciate the feedback and research though!

@Folcon
Copy link
Author

Folcon commented Oct 25, 2018

@danielcompton No problem and totally understand that, I'll see what the response is there :)...
Do you mind if I leave this open here if someone's looking how they'd do it?

@danielcompton
Copy link
Contributor

Sure, that’s fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants