Skip to content

Commit

Permalink
optimistic in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
hazae41 committed Sep 3, 2022
1 parent 8de5f0e commit ea171e5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
8 changes: 4 additions & 4 deletions dist/index.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1423,10 +1423,10 @@ function useScroll(scroller, fetcher, params) {
}
});
}); }, [core, skey]);
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter;
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter, optimistic = _b.optimistic;
var ready = state !== null;
var loading = Boolean(aborter);
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, scroll: scroll, clear: clear };
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, optimistic: optimistic, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, scroll: scroll, clear: clear };
}

/**
Expand Down Expand Up @@ -1502,10 +1502,10 @@ function useSingle(key, poster, params) {
}
});
}); }, [core, skey]);
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter;
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter, optimistic = _b.optimistic;
var ready = state !== null;
var loading = Boolean(aborter);
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, update: update, clear: clear };
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, optimistic: optimistic, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, update: update, clear: clear };
}

function use(factory, deps) {
Expand Down
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1429,10 +1429,10 @@ function useScroll(scroller, fetcher, params) {
}
});
}); }, [core, skey]);
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter;
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter, optimistic = _b.optimistic;
var ready = state !== null;
var loading = Boolean(aborter);
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, scroll: scroll, clear: clear };
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, optimistic: optimistic, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, scroll: scroll, clear: clear };
}

/**
Expand Down Expand Up @@ -1508,10 +1508,10 @@ function useSingle(key, poster, params) {
}
});
}); }, [core, skey]);
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter;
var _b = state !== null && state !== void 0 ? state : {}, data = _b.data, error = _b.error, time = _b.time, cooldown = _b.cooldown, expiration = _b.expiration, aborter = _b.aborter, optimistic = _b.optimistic;
var ready = state !== null;
var loading = Boolean(aborter);
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, update: update, clear: clear };
return { key: key, skey: skey, data: data, error: error, time: time, cooldown: cooldown, expiration: expiration, aborter: aborter, optimistic: optimistic, loading: loading, ready: ready, mutate: mutate, fetch: fetch, refetch: refetch, update: update, clear: clear };
}

function use(factory, deps) {
Expand Down
5 changes: 5 additions & 0 deletions dist/mods/react/hooks/handles/handle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface Handle<D = any, E = any, K = any> {
* Abort controller, can be used to abort and check for abortion, present when a fetch is ongoing (except those from update())
*/
aborter?: AbortController;
/**
* - Whether the data is from an optimistic update
* - Whether the ongoing request is an optimistic update
*/
optimistic?: boolean;
/**
* Expiration time of this resource, if any, may be useful for fetching just before the resource becomes stale
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hazae41/xswr",
"version": "1.0.54",
"version": "1.0.55",
"author": "hazae41",
"license": "MIT",
"description": "The simplest React data (re)fetching library ever made",
Expand Down
6 changes: 6 additions & 0 deletions src/mods/react/hooks/handles/handle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export interface Handle<D = any, E = any, K = any> {
*/
aborter?: AbortController,

/**
* - Whether the data is from an optimistic update
* - Whether the ongoing request is an optimistic update
*/
optimistic?: boolean,

/**
* Expiration time of this resource, if any, may be useful for fetching just before the resource becomes stale
*/
Expand Down
4 changes: 2 additions & 2 deletions src/mods/react/hooks/handles/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ export function useScroll<D = any, E = any, K = any>(
await core.delete(skey, mparams)
}, [core, skey])

const { data, error, time, cooldown, expiration, aborter } = state ?? {}
const { data, error, time, cooldown, expiration, aborter, optimistic } = state ?? {}

const ready = state !== null
const loading = Boolean(aborter)

return { key, skey, data, error, time, cooldown, expiration, aborter, loading, ready, mutate, fetch, refetch, scroll, clear }
return { key, skey, data, error, time, cooldown, expiration, aborter, optimistic, loading, ready, mutate, fetch, refetch, scroll, clear }
}
4 changes: 2 additions & 2 deletions src/mods/react/hooks/handles/single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export function useSingle<D = any, E = any, K = any>(
await core.delete(skey, mparams)
}, [core, skey])

const { data, error, time, cooldown, expiration, aborter } = state ?? {}
const { data, error, time, cooldown, expiration, aborter, optimistic } = state ?? {}

const ready = state !== null
const loading = Boolean(aborter)

return { key, skey, data, error, time, cooldown, expiration, aborter, loading, ready, mutate, fetch, refetch, update, clear }
return { key, skey, data, error, time, cooldown, expiration, aborter, optimistic, loading, ready, mutate, fetch, refetch, update, clear }
}

0 comments on commit ea171e5

Please sign in to comment.