Skip to content

Commit 3176d58

Browse files
refactor: add success callback
1 parent 2f09f27 commit 3176d58

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/composables/npm/useNpmSearch.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ export function useNpmSearch(
100100
size: opts.size ?? 25,
101101
})
102102

103+
opts.onSuccess?.({ query: q })
104+
103105
if (q !== toValue(query)) {
104106
return emptySearchResponse
105107
}
@@ -131,6 +133,8 @@ export function useNpmSearch(
131133
}),
132134
])
133135

136+
opts.onSuccess?.({ query: q })
137+
134138
if (!pkg) {
135139
return emptySearchResponse
136140
}
@@ -166,6 +170,8 @@ export function useNpmSearch(
166170
60,
167171
)
168172

173+
opts.onSuccess?.({ query: q })
174+
169175
// If query changed/outdated, return empty search response
170176
if (q !== toValue(query)) {
171177
return emptySearchResponse
@@ -181,8 +187,6 @@ export function useNpmSearch(
181187
// Success - clear rate limit flag
182188
isRateLimited.value = false
183189

184-
opts.onSuccess?.({ query: q })
185-
186190
return { ...response, isStale }
187191
} catch (error: unknown) {
188192
// Detect rate limit errors. npm's 429 response doesn't include CORS headers,

0 commit comments

Comments
 (0)