瀏覽代碼

refactor: move component state to state

Weihua Lu 4 年之前
父節點
當前提交
9d044f5834
共有 2 個文件被更改,包括 9 次插入6 次删除
  1. 4 6
      src/main/frontend/modules/shortcut/mixin.cljs
  2. 5 0
      src/main/frontend/state.cljs

+ 4 - 6
src/main/frontend/modules/shortcut/mixin.cljs

@@ -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]

+ 5 - 0
src/main/frontend/state.cljs

@@ -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)))