Created
April 14, 2020 10:00
-
-
Save martinklepsch/18e1195e09365c54547e22e36481812a to your computer and use it in GitHub Desktop.
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
(defn log-lifecyle [component-name] | |
(into {} | |
(map (fn [lifecycle] | |
[lifecycle (fn [state] (js/console.log component-name lifecycle) state)])) | |
[:will-mount :will-unmount :did-mount :did-unmount])) | |
(rum/defc A < (log-lifecyle :A) | |
[] | |
[:span "A"]) | |
(rum/defc B < (log-lifecyle :B) | |
[] | |
[:span "B"]) | |
(rum/defcs LifecycleOrderTestApp | |
< (rum/local true :component) | |
[s] | |
[:div | |
(case @(:component s) | |
true (A) | |
false (B)) | |
[:div | |
[:button {:on-click #(swap! (:component s) not)} "swap components"]]]) | |
;; render A | |
:A :will-mount | |
:A :did-mount | |
;; replacing A with B | |
:B :will-mount | |
:A :will-unmount | |
:B :did-mount | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment