Skip to content

Commit

Permalink
fix(react,vue,svelte): allow specifying other options (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathew98 committed Mar 6, 2024
1 parent 4ead1a3 commit 0bc807a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/react/src/use-monitored-fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React from "react";
import { makeMonitoredFetch } from "@b.s/incremental";
import {
makeMonitoredFetch,
type MakeMonitoredParameters,
} from "@b.s/incremental";

export const useMonitoredFetch = () => {
const [allFetchStatus, setAllFetchStatus] = React.useState(
Expand All @@ -10,10 +13,15 @@ export const useMonitoredFetch = () => {

const monitor = <F extends (...args: any[]) => Promise<any>>(
fetchFn: F,
options: Omit<
MakeMonitoredParameters<F>,
"onFetching" | "fetchFn"
> = Object.create(null),
) => {
const id = createId();

return makeMonitoredFetch({
...options,
fetchFn,
onFetching: isFetching =>
setAllFetchStatus(allFetchStatus => ({
Expand Down
10 changes: 9 additions & 1 deletion packages/svelte/src/use-monitored-fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { makeMonitoredFetch } from "@b.s/incremental";
import {
makeMonitoredFetch,
type MakeMonitoredParameters,
} from "@b.s/incremental";
import { derived, writable } from "svelte/store";

export const useMonitoredFetch = () => {
Expand All @@ -8,10 +11,15 @@ export const useMonitoredFetch = () => {

const monitor = <F extends (...args: any[]) => Promise<any>>(
fetchFn: F,
options: Omit<
MakeMonitoredParameters<F>,
"fetchFn" | "onFetching"
> = Object.create(null),
) => {
const id = createId();

return makeMonitoredFetch({
...options,
fetchFn,
onFetching: isFetching =>
allFetchStatus.update(allFetchStatus => ({
Expand Down
10 changes: 9 additions & 1 deletion packages/vue/src/use-monitored-fetch/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { makeMonitoredFetch } from "@b.s/incremental";
import {
makeMonitoredFetch,
type MakeMonitoredParameters,
} from "@b.s/incremental";
import { computed, ref } from "vue";

export const useMonitoredFetch = () => {
Expand All @@ -8,10 +11,15 @@ export const useMonitoredFetch = () => {

const monitor = <F extends (...args: any[]) => Promise<any>>(
fetchFn: F,
options: Omit<
MakeMonitoredParameters<F>,
"onFetching" | "fetchFn"
> = Object.create(null),
) => {
const id = createId();

return makeMonitoredFetch({
...options,
fetchFn,
onFetching: isFetching => {
allFetchStatus.value = {
Expand Down

0 comments on commit 0bc807a

Please sign in to comment.