Skip to content

Instantly share code, notes, and snippets.

@jrsinclair
Last active September 4, 2019 12:22
Show Gist options
  • Save jrsinclair/ea5ee31deb2318d41b53607a3bda8e32 to your computer and use it in GitHub Desktop.
Save jrsinclair/ea5ee31deb2318d41b53607a3bda8e32 to your computer and use it in GitHub Desktop.
Fun with binding event handlers
const setAttr = _.curry((attrName, el, val) => { el.setAttribute(val)); return el; });
const listen = _.curry((evtName, el, f) => { el.addEventListener(evtName, f); return el; })
const bindCreateResultButton = (createResultButton, postTextarea, getPostData, preTextarea) =>
_.compose(
listen('click', createResultButton),
_.compose(x => () => setAttr('value', postTextArea, x), getPostData),
)(preTextArea);
@Rosefalk
Copy link

Rosefalk commented Sep 4, 2019

For posterity, here's a link to the pen: https://codepen.io/rosefalk/pen/QWLpZEY?editors=0011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment