Created
November 26, 2021 10:33
-
-
Save alexanderjamesking/1d6e724ccab4d5d600e8baac3270781b to your computer and use it in GitHub Desktop.
Refactor of re-frame task-list example https://github.com/day8/re-frame/blob/master/examples/todomvc/src/todomvc/views.cljs#L53
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 task-list [] | |
(let [visible-todos @(subscribe [:visible-todos]) | |
all-complete? @(subscribe [:all-complete?])] | |
[:section#main | |
[:input#toggle-all | |
{:type "checkbox" | |
:checked all-complete? | |
:on-change #(dispatch [:complete-all-toggle])}] | |
[:label | |
{:for "toggle-all"} | |
"Mark all as complete"] | |
[:ul#todo-list | |
(for [todo visible-todos] | |
^{:key (:id todo)} [todo-item todo])]])) |
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 task-list | |
[{:keys [visible-todos all-complete? complete-all]}] | |
[:section#main | |
[:input#toggle-all | |
{:type "checkbox" | |
:checked all-complete? | |
:on-change complete-all}] | |
[:label | |
{:for "toggle-all"} | |
"Mark all as complete"] | |
[:ul#todo-list | |
(for [todo visible-todos] | |
^{:key (:id todo)} [todo-item todo])]]) | |
(defn rf-task-list [] | |
[task-list {:visible-todos @(subscribe [:visible-todos]) | |
:all-complete? @(subscribe [:all-complete?]) | |
:complete-all #(dispatch [:complete-all-toggle])}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment