Skip to content

Instantly share code, notes, and snippets.

@Debdut
Created June 21, 2020 15:50
Show Gist options
  • Save Debdut/bdebd879151d588468ca5c7ca81bdce5 to your computer and use it in GitHub Desktop.
Save Debdut/bdebd879151d588468ca5c7ca81bdce5 to your computer and use it in GitHub Desktop.
const update = (obj) => {
const next = (...args) => {
return x => {
if (
typeof x === 'object'
// && x.constructor.name.includes('Event')
) {
let node = obj
for (let i = 0; i < args.length - 1 ; i++) {
node = node[args[i]]
}
node[args[args.length - 1]] = x.target.value
}
return next(...args, x)
}
}
return next
}
const Obj = {
reward: {
xp: 12
}
}
const event = {
target: {
value: 13
}
}
const updater = update(Obj)
updater('reward')('xp')(event)
console.log(Obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment