Skip to content

Commit c94e838

Browse files
committed
fix: simplify/change "revalidating" state removing action using entry
1 parent 772d984 commit c94e838

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/lib/swr.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,28 @@ const defaultSWRParams = {
4242
const swrMachine: FSMMachineConfig = {
4343
initial: "init",
4444
on: {
45-
revalidate: {
46-
target: "revalidating",
47-
action: (ctx, event) => {
45+
revalidate: "revalidating",
46+
},
47+
states: {
48+
init: {},
49+
revalidating: {
50+
entry: (ctx, event) => {
4851
if (cache.has(event.data.key)) {
49-
return { ...ctx, isLoading: false, data: cache.get(event.data.key) };
52+
ctx = { ...ctx, isLoading: false, data: cache.get(event.data.key) };
5053
} else if (event.data.options.initialData) {
5154
const data = event.data.options.initialData();
5255
if (data) {
53-
return { ...ctx, isLoading: false, data };
56+
ctx = { ...ctx, isLoading: false, data };
5457
}
5558
}
56-
},
57-
},
58-
},
59-
states: {
60-
init: {},
61-
revalidating: {
62-
entry: (ctx) => {
6359
increaseFetching();
6460
return { ...ctx, isFetching: true };
6561
},
6662
on: {
6763
revalidate: null,
6864
},
6965
invoke: {
70-
src: (_, event) => {
71-
return event.data.fn();
72-
},
66+
src: (_, event) => event.data.fn(),
7367
onDone: {
7468
target: "success",
7569
action: (ctx, event) => {

0 commit comments

Comments
 (0)