Allow to create/connect units in target of sample
Inspired by https://github.com/effector/effector/issues/555#issuecomment-980426132
please read the conversation to find answers to all questions
Proposal
sample({
filter: $isEditorOpened,
target() {
hotkey("Ctrl+Z", undo)
hotkey("Ctrl+Shift+Z", redo)
}
})
This variant looks really good!
Looks like this version of api can be problematic in the way it affects code 🤔
Since it allows to nest operator calls, it can lead to kind of "callback hell" in the code:
sample({
filter: page.$open,
target() {
sample({
clock: somethingHappened,
filter: $notifyEnabled,
fn: () => ({ title: "Something happened", level: "warning" }),
target: notify,
});
sample({
filter: $needData,
target() {
sample({
clock: buttonClicked,
target: getDataFx,
});
// keep nesting
},
});
},
});
And then we would need to apply or remove some filter condition to some of the nested samples - this way we would be required to basically collect all of the filters all the way up to the root clojure and then decide:
- should this
samplebe moved somewhere up? - should we add some more filters nesting?
- etc.
Looks like it is quite possible, that this method will add a much more trouble in the long run, compared to current way of adding filter to every sample in the module
Since currently all operator definitions are basically "flat", we will not have all of the nesting-related issues 🤔
I'm not sure if users of the effector will actually write crazy-deep-nested combinations of samples with this api - maybe they will not - but i think that this api makes very easy to do so
Or we can just add eslint rule for that :)
I don't get it - how this rule may work? 🤔 Cut maximum level of nesting at some number?
Just forcing 1 level of nesting only, at least on start
Not sure it is a good idea. Reopen if we plan to work on it.