Last active
March 18, 2018 00:48
-
-
Save lwhorton/8ee53a855ce23b161b41185665569c36 to your computer and use it in GitHub Desktop.
Why Clojure(script)?
This file contains hidden or 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
| ;; when not every value in transient-states is saved, return a string" | |
| (defn confirm-leave? [db] | |
| (when-not (->> (:transient-states db) | |
| (vals) | |
| (every? :saved?)) | |
| "There is unsaved data, do you want to continue?")) |
This file contains hidden or 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
| // assign to an isSaved variable (hm, conventionally that means it's a boolean) | |
| // the result of getting Object.values from result of mapping a boolean check... | |
| // oh wait, this is the builder pattern so the operators go the other way. | |
| // assign to a maybe boolean variable the values of the transientStates, then | |
| // look at the saved property (wait, wouldn't the boolean convention be isSaved? | |
| // should I check against non-booleans?) for each. then, if not isSaved... by | |
| // which i mean if not every saved value in the states is true... by which i | |
| // mean if one of the saved values in the states is false, return a string. | |
| function confirmLeave(db) { | |
| const isSaved = Object.values(db.transientStates).every(s => s.saved); | |
| if (!isSaved) { | |
| return 'There is unsaved data, do you want to continue?'; | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment