Skip to content

Commit 66ebe32

Browse files
committed
fix: save matching calls to invocations
1 parent 072a6ea commit 66ebe32

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

examples/with-nextjs/src/app/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function Home() {
77
const [inputValue, setInputValue] = useState('')
88

99
function submit() {
10+
console.log('Input Value:', inputValue)
1011
if (inputValue === 'wrong') {
1112
throw new Error(`Input value "${inputValue}" is wrong!`)
1213
}

pnpm-lock.yaml

Lines changed: 0 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,24 @@ const addFunctionInvocation = (functionId: string, invocation: CaptureInvocation
409409
}
410410

411411
function saveFunctionCall(opts: FlytrapCallOptions) {
412-
const functionCallIndex = _functionCalls.findIndex((call) => call.id === opts.id)
413-
if (functionCallIndex === -1) {
414-
_functionCalls.push({
415-
id: opts.id,
416-
invocations: [
417-
{
418-
...opts,
419-
timestamp: Date.now()
420-
}
421-
]
412+
const matchingFunctionCall = _functionCalls.find((call) => call.id === opts.id)
413+
if (matchingFunctionCall) {
414+
matchingFunctionCall.invocations.push({
415+
...opts,
416+
timestamp: Date.now()
422417
})
418+
return
423419
}
420+
421+
_functionCalls.push({
422+
id: opts.id,
423+
invocations: [
424+
{
425+
...opts,
426+
timestamp: Date.now()
427+
}
428+
]
429+
})
424430
}
425431

426432
function saveOutputForFunctionCall<T>(functionCallId: string, output: T) {

0 commit comments

Comments
 (0)