Skip to content

Instantly share code, notes, and snippets.

@chrisui
Last active April 7, 2016 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisui/fc2e1b20c54c4c5befb7abad9c6a577f to your computer and use it in GitHub Desktop.
Save chrisui/fc2e1b20c54c4c5befb7abad9c6a577f to your computer and use it in GitHub Desktop.
Arrow function binding
// given a reference to mutableData we can't guarantee that .mutableProperty would
// still be the same reference *after* binding.
function Component({mutableData, onClick}) {
return <button onClick={event => onClick(mutableData.mutableProperty, event)} />
}
// immutableValue could be any scalar or an immutable (guaranteed not to change) object
function Component({immutableValue, onClick}) {
return <button onClick={event => onClick(immutableValue, event)} />
}
const _bindRenderHandler = memoize(500)(function(func, context, ...args) {
return func.bind(context, ...args);
});
function _onClickHandler(onClick, immutableValue, event) {
return onClick(immutableValue, event);
}
function Component({immutableValue, onClick}) {
return <button onClick={_bindRenderHandler(_onClickHandler, this, onClick, immutableValue)} />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment