Last active
October 4, 2015 15:40
-
-
Save clohr/263368c6494d63296d79 to your computer and use it in GitHub Desktop.
safeDOM
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
const logger = R.compose( | |
R.bind(console.log, console), | |
R.concat('Missing selector '), | |
R.flip(R.identity) | |
); | |
const mapCb = (x) => console.log(x.textContent); | |
const mapper = R.map(mapCb); | |
const validate = R.ifElse( | |
R.equals(S.Nothing()), | |
logger, | |
mapper | |
); | |
const queryDOM = R.compose( | |
S.toMaybe, | |
R.bind(document.querySelector, document) | |
); | |
const safeQuery = R.converge( | |
validate, | |
queryDOM, | |
R.identity | |
); | |
safeQuery('.modal'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah probably could be cleaned up, the 1st thought was to create reusable functions where possible for example some may not need to signify to the implementors that the specific selector is missing... etc