I have this array:
[
{service: "AssignmentService", method: "saveMillaje", params: [1, 'some param'], id: 1},
{service: "AssignmentService", method: "saveMillaje", params: [1, 'some param', { otherData: 'data' }], id: 2}
]
Where "service" is a wrapper file for axios like:
// AssignmentService.js
import Http from './Http';
const endpoint = 'assignment';
export default {
saveMillaje(param1, param2, param3) {
// do something
// this will return a PROMISE
},
};
I need in a certain point of my app, call and execute for example, the position 1 of the array with all params.
Transform this:
{service: "AssignmentService", method: "saveMillaje", params: [1, 'some param', { otherData: 'data' }], id: 2}
To:
import AssignmentService from 'services/AssignmentService';
...
someMethod(){
AssignmentService.saveMillaje(1, 'some param', {otherData: 'data'})
then((response)=> {
// So something
});
}
I have no idea to achieve this. Can you help me? Thanks a lot for any help about it.
import AssignmentService from 'services/AssignmentService';
import OtherService from 'services/OtherService';
var services = {AssignmentService, OtherService}
someMethod(obj){
services[obj.service][obj.method].apply(null, obj.params).
then((response)=> {
// So something
});
}
Then you can just pass in the objects from your array.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments