Skip to content

fix(splitMap): stop fall through when a case returns a falsy value - #357

Open
bardrop wants to merge 1 commit into
effector:mainfrom
bardrop-oss:fix-split-map-falsy-case
Open

bardrop wants to merge 1 commit into
effector:mainfrom
bardrop-oss:fix-split-map-falsy-case

Conversation

@bardrop

@bardrop bardrop commented Nov 14, 2026

Copy link
Copy Markdown

Description

Fixes #356.

splitMap builds the remainder after each case with current.filter({ fn: (data) => !fn(data) }), while the case event itself uses filterMap(fn), which only skips undefined. So when a case returns 0, '', false or null, the case event fires and the payload still goes on to later cases and __:

source({ count: 0 });
// before: count(0), then __({ count: 0 })
// after:  count(0) only

The docs say cases are tried "until function returns non undefined" and __ fires when "each other function returns undefined", so the remainder filter is now fn(data) === undefined.

Added a test in split-map.test.ts with 0, '', false and null results; it fails on main and passes with the fix. jest: 60 suites, 423 tests pass.

The remainder after each case used !fn(data), so a case that returned 0, '', false or null fired and the payload still went on to later cases and __. Only undefined means no match now, same as filterMap.

Fixes effector#356
@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

splitMap: a case that returns a falsy value (0, '', false, null) fires and then still falls through to later cases and __

1 participant