Change resize to use DOM transformations

This commit is contained in:
alonso.torres 2021-12-21 12:32:04 +01:00
parent fa09fff2b5
commit b2211aec59
38 changed files with 839 additions and 717 deletions

View file

@ -162,16 +162,30 @@
(->> (rx/take 1 observable)
(rx/subs resolve reject)))))
(defn fetch-data-uri [uri]
(c/with-cache {:key uri :max-age (dt/duration {:hours 4})}
(->> (send! {:method :get
:uri uri
:response-type :blob
:omit-default-headers true})
(rx/filter #(= 200 (:status %)))
(rx/map :body)
(rx/mapcat wapi/read-file-as-data-url)
(rx/map #(hash-map uri %)))))
(defn fetch-data-uri
([uri]
(fetch-data-uri uri false))
([uri throw-err?]
(c/with-cache {:key uri :max-age (dt/duration {:hours 4})}
(let [request-stream
(send! {:method :get
:uri uri
:response-type :blob
:omit-default-headers true})
request-stream
(if throw-err?
(rx/tap #(when-not (and (>= (:status %) 200) (< (:status %) 300))
;; HTTP ERRROR
(throw (js/Error. "Error fetching data uri" #js {:cause (clj->js %)})))
request-stream)
(rx/filter #(= 200 (:status %))
request-stream))]
(->> request-stream
(rx/map :body)
(rx/mapcat wapi/read-file-as-data-url)
(rx/map #(hash-map uri %)))))))
(defn fetch-text [url]
(c/with-cache {:key url :max-age (dt/duration {:hours 4})}

View file

@ -105,3 +105,29 @@
:onRender on-render}
children]
children)))
(defn benchmark
[& {:keys [f warmup iterations name]
:or {iterations 10000}}]
(let [end-mark (str name ":end")]
(println "=> benchmarking:" name)
(println "--> warming up:" iterations)
(loop [i iterations]
(when (pos? i)
(f)
(recur (dec i))))
(println "--> benchmarking:" iterations)
(js/performance.mark name)
(loop [i iterations]
(when (pos? i)
(f)
(recur (dec i))))
(js/performance.measure end-mark name)
(let [[result] (js/performance.getEntriesByName end-mark)
duration (mth/precision (.-duration ^js result) 4)
avg (mth/precision (/ duration iterations) 4)]
(println "--> TOTAL:" (str duration "ms") "AVG:" (str avg "ms"))
(js/performance.clearMarks name)
(js/performance.clearMeasures end-mark)
#js {:duration duration
:avg avg})))