effector / effector/effector

StoreWritable.on() reports `undefined` returned from reducer

Open
#1,034 3 comments 0 reactions 0 assignees View on GitHub
core documentation good first issue
Dominant language
TypeScript
Stars
4.9k
Forks
280
Avg merge
2d 6h
Merged PRs (30d)
7

Description

**What is the current behavior:**

`StoreWritable.on()` reports `undefined` returned from the reducer. This doesn't look as intended behavior neither from v23 release notes, nor from documentation.

> store: undefined is used to skip updates. To allow undefined as a value provide explicit { skipVoid: false } option

https://share.effector.dev/007a4LsA
```ts
const add = createEvent();
const $v = createStore(0)
.on(add, (a, b) => {
if (b !== undefined) {
return a + b;
}
})
.watch((v) => console.log(">> $s", v));
add.watch((v) => console.log(">> add", v));

add(50);
add();
add(-8);
```

Docs:

> ## Store
>
> *Store* is an object that holds the state value. Store is getting updates when receives a value that is not equal (`!==`) to current one and to `undefined`.

> ```js
> $store.on(trigger, reducer);
> ```
> A store cannot hold an `undefined` value. If a reducer function returns `undefined`, the store will not be updated.

Release notes:
> - Deprecate undefined as magical value to skip store updates, use `skipVoid: true` option in `combine` and `map` to enable old behavior.

**What is the expected behavior:**

Using `undefined` return value from `on()` reducer looks still fine from docs and release notes, so:
- either no error should be reported
- either docs should describe better the `undefined` status for `Store`

**Which versions**

- Effector 23.0.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.