Last active
April 7, 2016 13:04
-
-
Save chrisui/fc2e1b20c54c4c5befb7abad9c6a577f to your computer and use it in GitHub Desktop.
Arrow function binding
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
// 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)} /> | |
} |
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
// immutableValue could be any scalar or an immutable (guaranteed not to change) object | |
function Component({immutableValue, onClick}) { | |
return <button onClick={event => onClick(immutableValue, event)} /> | |
} |
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 _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