Skip to content

Deprecate derived units in target #563

@AlexandrHoroshih

Description

@AlexandrHoroshih

What is the current behavior:
Usage of .on method is deprecated on derived stores and to be removed in the next release - this is very good news and, i think, makes everything a lot more consistent and predictable 👍

But now usage of derived stores as a target in operators is not warned or error by effector, so the problem of unexpected changes to derived stores still persists 😢

$readOnlyStore = $store.map(v => v)

// yay! error in console!
$readOnlyStore.on(ev, () => {})

// no error :(
sample({
 clock: $store,
 target: $readOnlyStore,
})

Also i think that stores created by restore from an event or effect should be considered as derived too, since they also have explicit dependency at the moment of creation: restore(changed, null) 🤔
UPD: Since restored event state still can be used by app and can't be derived from, for e.g., state in serialized scope during SSR, it is definetly not derived (at least, in a sense similiar to mapped stores)

Please provide the steps to reproduce and if possible a minimal demo of the problem via https://share.effector.dev, https://codesandbox.io or similar

https://share.effector.dev/yqvd359F

What is the expected behavior:
Any attempt of adding a new source of updates to dervied store is forbidden and warning/error is shown.
If such behaviour is needed - it is better to create classic (not derived) store and subscribe it to changes of original derived store.

Which versions of effector packages, and which browser and OS are affected by this issue? Did this work in previous versions of effector?:
effector@22.0.0^

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreeffector package

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions