Created
October 22, 2017 15:41
-
-
Save wpcarro/07d75f283e817202abe87049e2a2a8f3 to your computer and use it in GitHub Desktop.
Debugging re-frame and reagent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; versions 1 & 2 -- structure remains the same | |
(defn render [{:keys [data]}] | |
(reagent/create-class | |
{:reagent-render (constantly [:svg.canvas]) | |
:component-did-mount #(-> data clj->js do-render-graph)})) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; version 1 -- canvas DOES NOT re-render | |
(defn render [] | |
[:div.main | |
[search/render {:active? @(rf/subscribe [:search/active?]) | |
:coordinates @(rf/subscribe [:search/coordinates])}] | |
[canvas/render {:data @(rf/subscribe [:main/payload])}]]) | |
;; version 2 -- canvas re-renders | |
(defn render [] | |
[:div.main | |
(when @(rf/subscribe [:search/active?]) | |
[search/render]) | |
[canvas/render {:data @(rf/subscribe [:main/payload])}]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; version 1 | |
(defn render [{:keys [active? coordinates]}] | |
(when active? | |
(let [[x y] coordinates] | |
[:div.search | |
{:style {:position "absolute" | |
:left (- x (/ vars/width 2)) | |
:top (-> y (- vars/height) (- vars/margin-bottom))}} | |
[:input.search__input | |
{:type "text" | |
:on-change #(rf/dispatch [:search/value-change (-> % .-target .-value)]) | |
:on-key-down handle-key-down-event | |
:value @(rf/subscribe [:search/value]) | |
:auto-focus true}]]))) | |
;; version 2 | |
(defn render [] | |
(let [[x y] @(rf/subscribe [:search/coordinates] | |
[:div.search | |
{:style {:position "absolute" | |
:left (- x (/ vars/width 2)) | |
:top (-> y (- vars/height) (- vars/margin-bottom))}} | |
[:input.search__input | |
{:type "text" | |
:on-change #(rf/dispatch [:search/value-change (-> % .-target .-value)]) | |
:on-key-down handle-key-down-event | |
:value @(rf/subscribe [:search/value]) | |
:auto-focus true}]])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment