Created
June 14, 2017 21:49
-
-
Save rohozhnikoff/8e73e6103bc2715aaa5002528436cf27 to your computer and use it in GitHub Desktop.
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
// мне не нравится как this передается | |
function onSimpleHashChange(handlers) { | |
const keys = _.keys(handlers); | |
return function (left, right) { | |
if (_.isEqual(left, right)) {return} | |
const _this = this; | |
keys.forEach((key) => { | |
if (left[key] !== right[key]) { | |
handlers[key].call(_this, left, right) | |
} | |
}) | |
} | |
} | |
class Component { | |
stateChangeHandlers = onSimpleHashChange({ | |
'fontSizeQuantity': () => { this.postMessageToBridge({fontSizeQuantity: nextState.fontSizeQuantity}) }, | |
}) | |
componentWillUpdate(nextProps, nextState) { | |
this.stateChangeHandlers.call(this, this.state, nextState) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment