lazy_editor.cljs 700 B

12345678910111213141516171819202122
  1. (ns frontend.components.lazy-editor
  2. (:require [rum.core :as rum]
  3. [shadow.lazy :as lazy]
  4. [frontend.ui :as ui]
  5. [frontend.state :as state]))
  6. (def lazy-editor (lazy/loadable frontend.extensions.code/editor))
  7. (defonce loaded? (atom false))
  8. (rum/defc editor < rum/reactive
  9. {:will-mount (fn [state]
  10. (lazy/load lazy-editor
  11. (fn []
  12. (reset! loaded? true)))
  13. state)}
  14. [config id attr code options]
  15. (let [loaded? (rum/react loaded?)
  16. theme (state/sub :ui/theme)]
  17. (if loaded?
  18. (@lazy-editor config id attr code theme options)
  19. (ui/loading "CodeMirror"))))