0

I would like to create a generic call using api-client.

I want simplify my functions:

client.hello(params).then(
    (response) => {
         console.log(response)
    },
    (error) => {
         console.log(error)
    }
)
client.bye(params).then(
    (response) => {
         console.log(response)
    },
    (error) => {
         console.log(error)
    }
)

Using a unique function, something like:

generic=window['hello']

client.generic(params).then(
    (response) => {
         console.log(response)
    },
    (error) => {
         console.log(error)
    }
)

With window['hello'] do not work.

sarnei
  • 267
  • 1
  • 4
  • 11
  • 2
    `let say = (what) => client[what].path(params).then(...); say('hello'); say('bye');`? – Heretic Monkey Jan 31 '19 at 21:17
  • 1
    well, the `then` part seems to be completely duplicate code, you could extract those alreadyfor the rest, if it's alsways `client[name].path`, then also that can be parametrized – Icepickle Jan 31 '19 at 21:17

0 Answers0