refactor: move component state to state

pull/1671/head
Weihua Lu 2021-04-16 17:45:16 +08:00
parent d05c540c15
commit 9d044f5834
2 changed files with 9 additions and 6 deletions

View File

@ -3,28 +3,26 @@
[frontend.state :as state]
[frontend.util :as util]))
(def state-store (atom {}))
(defn state-f [k]
(fn [] (get @state-store k)))
(fn [] (get @state/components k)))
(defn bind-state [k]
{:after-render
(fn [state]
(js/setTimeout
(fn []
(swap! state-store assoc k state))
(swap! state/components assoc k state))
100)
state)
:did-remount
(fn [_ new-state]
(swap! state-store assoc k new-state)
(swap! state/components assoc k new-state)
new-state)
:will-unmount
(fn [state]
(swap! state-store dissoc k)
(swap! state/components dissoc k)
state)})
(defn before [f shortcut-map]

View File

@ -1168,3 +1168,8 @@
(defn set-copied-blocks
[content ids]
(set-state! :copy/blocks {:copy/content content :copy/block-tree ids}))
(defonce components (atom {}))
(defn auto-complete? []
(some? (get @components :component/auto-complete)))