Skip to content

Commit 791ee89

Browse files
fix(overmind): fix forEach operator with no items
1 parent ab689f6 commit 791ee89

File tree

1 file changed

+16
-10
lines changed
  • packages/node_modules/overmind/src

1 file changed

+16
-10
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -968,16 +968,22 @@ export function forEach<
968968
}
969969
startDebugOperator('forEach', '', context)
970970

971-
array.forEach((value, index) => {
972-
lastContext = createContext(
973-
lastContext || context,
974-
value,
975-
context.execution.path && context.execution.path.concat(String(index))
976-
)
977-
const nextWithPath = createNextPath(evaluate)
978-
// @ts-ignore
979-
forEachItemOperator(null, lastContext, nextWithPath)
980-
})
971+
if (array.length) {
972+
array.forEach((value, index) => {
973+
lastContext = createContext(
974+
lastContext || context,
975+
value,
976+
context.execution.path &&
977+
context.execution.path.concat(String(index))
978+
)
979+
const nextWithPath = createNextPath(evaluate)
980+
// @ts-ignore
981+
forEachItemOperator(null, lastContext, nextWithPath)
982+
})
983+
} else {
984+
stopDebugOperator(context, context.value)
985+
next(null, createContext(context, context.value))
986+
}
981987
}
982988
}
983989
instance[IS_OPERATOR] = true

0 commit comments

Comments
 (0)