Skip to content

Commit

Permalink
fix default loader
Browse files Browse the repository at this point in the history
  • Loading branch information
salvoravida committed Jan 18, 2021
1 parent 4ee7e87 commit dc3a0f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 10 additions & 3 deletions packages/recoil-toolkit/src/hooks/useRecoilTask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { useRecoilCallback, useRecoilValue } from 'recoil';
import { useRef } from 'react';
import { uniqueId, hide, show } from '../_core';
import { lastTaskByKey, taskById, tasks, errorStack as errorStackAtom, loader } from '../atoms';
import {
lastTaskByKey,
taskById,
tasks,
errorStack as errorStackAtom,
loader,
DEFAULT_LOADER,
} from '../atoms';
import { pushTask, updateTaskDone, updateTaskError, pushError } from '../updaters';
import { TaskOptions, TaskStatus, RecoilTaskInterface } from '../types';

Expand Down Expand Up @@ -31,7 +38,7 @@ export function useRecoilTask<Args extends ReadonlyArray<unknown>, Return, T>(
const id = uniqueId();
taskId.current = id;
try {
if (loaderStack) set(loader(loaderStack), show);
if (loaderStack) set(loader(loaderStack === true ? DEFAULT_LOADER : loaderStack), show);
set(tasks, pushTask({ id, options, args }));
const data = await taskCreator({ set, snapshot, ...rest })(...args);
set(tasks, updateTaskDone({ data, id }));
Expand All @@ -41,7 +48,7 @@ export function useRecoilTask<Args extends ReadonlyArray<unknown>, Return, T>(
set(errorStackAtom, pushError({ key, error, taskId: id }));
}
} finally {
if (loaderStack) set(loader(loaderStack), hide);
if (loaderStack) set(loader(loaderStack === true ? DEFAULT_LOADER : loaderStack), hide);
}
},
deps,
Expand Down
5 changes: 2 additions & 3 deletions packages/recoil-toolkit/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type RecoilStore = {
gotoSnapshot: RecoilGotoSnapshot;
};

// eslint-disable-next-line no-shadow
export enum TaskStatus {
Running,
Error,
Expand All @@ -30,10 +31,8 @@ export enum TaskStatus {
export type TaskOptions<T = unknown> = {
key?: string;
errorStack?: boolean;
loaderStack?: string;
loaderStack?: string | boolean;
exclusive?: boolean;
startAuto?: boolean;
startAutoArgs?: ReadonlyArray<unknown>;
dataSelector?: RecoilValue<T>;
};

Expand Down

0 comments on commit dc3a0f2

Please sign in to comment.