DanielFGray – 20-58 Jan 8

im using a library with an api like foo.method(...args).run(pool) and i want to abstract it so i dont need to add .run(pool) to every call.. whats the best way to approach this, without having to change anything to the usage except for removing the .run(pool)? is a proxy useful here, or is there something else that doesnt require maintaining a list of methods on the original object?
UU
Unknown User466d ago
D
dfg466d ago
im not sure how currying would help here, can you give an example?
UU
Unknown User466d ago
D
dfg466d ago
that would work if i knew what method to use ahead of time, but there are many and i dont want to map them in my own object i want to allow all possible methods without having to code them in my own object
UU
Unknown User466d ago
D
dfg466d ago
Types are another matter, I want to replicate the same API foo[method](...args) without needing an object with every method
{
method1(...args) {
return foo.method1(...args).run(pool)
},
method2(...args) {
return foo.method2(...args).run(pool)
},
// yeah I don't wanna do this
}
{
method1(...args) {
return foo.method1(...args).run(pool)
},
method2(...args) {
return foo.method2(...args).run(pool)
},
// yeah I don't wanna do this
}
Pretty sure I need a proxy for this 🤔
UU
Unknown User465d ago