mirror of
https://github.com/penpot/penpot.git
synced 2025-03-27 23:21:47 -05:00
✨ Deprecate uxbox.util.components.
This commit is contained in:
parent
a7ffbd8a27
commit
4c36bce5bd
5 changed files with 72 additions and 13 deletions
44
frontend/src/uxbox/main/ui/components/chunked_list.cljs
Normal file
44
frontend/src/uxbox/main/ui/components/chunked_list.cljs
Normal file
|
@ -0,0 +1,44 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs S.L
|
||||
|
||||
(ns uxbox.main.ui.components.chunked-list
|
||||
"A collection of general purpose utility components."
|
||||
(:require
|
||||
[beicon.core :as rx]
|
||||
[rumext.alpha :as mf]
|
||||
[uxbox.util.timers :refer [schedule-on-idle]]))
|
||||
|
||||
(mf/defc chunked-list
|
||||
[{:keys [items children initial-size chunk-size]
|
||||
:or {initial-size 30 chunk-size 5}
|
||||
:as props}]
|
||||
(letfn [(initial-state []
|
||||
(let [total (count items)
|
||||
size (if (> total initial-size) initial-size total)
|
||||
current (take size items)
|
||||
pending (drop size items)]
|
||||
{:current (vec current)
|
||||
:pending pending
|
||||
:pending-num (- total size)}))
|
||||
|
||||
(update-state [{:keys [current pending pending-num] :as state}]
|
||||
(let [chunk-size (if (> pending-num chunk-size) chunk-size pending-num)]
|
||||
{:current (into current (take chunk-size pending))
|
||||
:pending (drop chunk-size pending)
|
||||
:pending-num (- pending-num chunk-size)}))
|
||||
(after-render [state]
|
||||
(when (pos? (:pending-num @state))
|
||||
(let [sem (schedule-on-idle (fn [] (swap! state update-state)))]
|
||||
#(rx/cancel! sem))))]
|
||||
|
||||
(let [initial (mf/use-memo initial-state)
|
||||
state (mf/use-state initial)]
|
||||
(mf/use-effect {:deps true :fn #(after-render state)})
|
||||
(for [item (:current @state)]
|
||||
(children item)))))
|
25
frontend/src/uxbox/main/ui/react_hooks.cljs
Normal file
25
frontend/src/uxbox/main/ui/react_hooks.cljs
Normal file
|
@ -0,0 +1,25 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2020 UXBOX Labs S.L
|
||||
|
||||
(ns uxbox.main.ui.react-hooks
|
||||
"A collection of general purpose react hooks."
|
||||
(:require
|
||||
[beicon.core :as rx]
|
||||
[rumext.alpha :as mf]))
|
||||
|
||||
(defn use-rxsub
|
||||
[ob]
|
||||
(let [[state reset-state!] (mf/useState @ob)]
|
||||
(mf/useEffect
|
||||
(fn []
|
||||
(let [sub (rx/subscribe ob #(reset-state! %))]
|
||||
#(rx/cancel! sub)))
|
||||
#js [ob])
|
||||
state))
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
[uxbox.main.refs :as refs]
|
||||
[uxbox.main.store :as s]
|
||||
[uxbox.main.streams :as ms]
|
||||
[uxbox.util.components :refer [use-rxsub]]
|
||||
[uxbox.main.ui.react-hooks :refer [use-rxsub]]
|
||||
[uxbox.util.dom :as dom]))
|
||||
|
||||
;; --- Constants & Helpers
|
||||
|
|
|
@ -27,9 +27,8 @@
|
|||
[uxbox.main.ui.shapes :refer [shape-wrapper frame-wrapper]]
|
||||
[uxbox.main.ui.workspace.drawarea :refer [draw-area]]
|
||||
[uxbox.main.ui.workspace.selection :refer [selection-handlers]]
|
||||
[uxbox.util.data :refer [parse-int]]
|
||||
[uxbox.main.ui.react-hooks :refer [use-rxsub]]
|
||||
[uxbox.util.perf :as perf]
|
||||
[uxbox.util.components :refer [use-rxsub]]
|
||||
[uxbox.util.uuid :as uuid]
|
||||
[uxbox.util.dom :as dom]
|
||||
[uxbox.util.geom.point :as gpt])
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
[rumext.alpha :as mf]
|
||||
[uxbox.util.timers :refer [schedule-on-idle]]))
|
||||
|
||||
;; TODO: this file is DEPRECATED (pending deletion)
|
||||
|
||||
(mf/defc chunked-list
|
||||
[{:keys [items children initial-size chunk-size]
|
||||
|
@ -41,16 +42,6 @@
|
|||
(for [item (:current @state)]
|
||||
(children item)))))
|
||||
|
||||
(defn use-rxsub
|
||||
[ob]
|
||||
(let [[state reset-state!] (mf/useState @ob)]
|
||||
(mf/useEffect
|
||||
(fn []
|
||||
(let [sub (rx/subscribe ob #(reset-state! %))]
|
||||
#(rx/cancel! sub)))
|
||||
#js [ob])
|
||||
state))
|
||||
|
||||
(defn wrap-catch
|
||||
([component error-component] (wrap-catch component error-component (constantly nil)))
|
||||
([component error-component on-error]
|
||||
|
|
Loading…
Add table
Reference in a new issue