update createApi
This commit is contained in:
parent
af068a945e
commit
8652f81ade
445
dist/core.js
vendored
445
dist/core.js
vendored
File diff suppressed because one or more lines are too long
@ -46,6 +46,10 @@ function joinUrl(baseUrl, id) {
|
|||||||
return `${baseUrl.replace(/\/$/, "")}/${id}`;
|
return `${baseUrl.replace(/\/$/, "")}/${id}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toHookName(actionName) {
|
||||||
|
return `use${actionName.charAt(0).toUpperCase()}${actionName.slice(1)}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function createApi({
|
export function createApi({
|
||||||
key,
|
key,
|
||||||
url,
|
url,
|
||||||
@ -138,6 +142,13 @@ export function createApi({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const actionHooks = Object.keys(actions).reduce((acc, actionName) => {
|
||||||
|
acc[toHookName(actionName)] = (options = {}) =>
|
||||||
|
useAction(actionName, options);
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
key: baseKey,
|
key: baseKey,
|
||||||
listKey,
|
listKey,
|
||||||
@ -145,5 +156,7 @@ export function createApi({
|
|||||||
useGet,
|
useGet,
|
||||||
useItem,
|
useItem,
|
||||||
useAction,
|
useAction,
|
||||||
|
|
||||||
|
...actionHooks,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user