Created
June 21, 2020 15:50
-
-
Save Debdut/bdebd879151d588468ca5c7ca81bdce5 to your computer and use it in GitHub Desktop.
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 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