Skip to content

Commit

Permalink
fix: slight alteration of mockup
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Erslev Milfred committed Nov 7, 2023
1 parent a3e151e commit 52595dd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<FetchForm
:action="`https://pokeapi.co/api/v2/pokemon/${pokemon.toLowerCase()}`"
#default="{ isFetching, currentResponse, currentError }"
:mockup-response="(data) => ({ name: 'ditto', data })"
:mockup-response="(payload) => ({ name: 'ditto', payload })"
@response="onResponse"
@error="onError"
>
Expand Down
19 changes: 11 additions & 8 deletions components/FetchForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,17 @@ function onSubmit(e) {
// Get mockup response
if (props.mockupResponse) {
const data = typeof props.mockupResponse === 'function' ? props.mockupResponse?.(payload) : props.mockupResponse;
emit('fetch', null);
emit('response', data);
emit('response:full', { data });
emit('complete', true);
currentResponse.value = props.mockupResponse;
currentError.value = null;
isFetching.value = false;
emit('fetch', new Promise((resolve) => {
emit('response', data);
emit('response:full', { meta: { code: 200 }, data, error: null });
emit('complete', true);
resolve({ meta: { code: 200 }, data, error: null });
currentResponse.value = props.mockupResponse;
currentError.value = null;
isFetching.value = false;
}));
return;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@limbo-works/fetch-form",
"type": "module",
"version": "0.1.0",
"version": "0.1.1",
"main": "./nuxt.config.js",
"scripts": {
"dev": "nuxi dev .playground",
Expand Down

0 comments on commit 52595dd

Please sign in to comment.