Skip to content

Instantly share code, notes, and snippets.

@rohozhnikoff
Created June 14, 2017 21:49
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 rohozhnikoff/8e73e6103bc2715aaa5002528436cf27 to your computer and use it in GitHub Desktop.
Save rohozhnikoff/8e73e6103bc2715aaa5002528436cf27 to your computer and use it in GitHub Desktop.
// мне не нравится как 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