effector icon indicating copy to clipboard operation
effector copied to clipboard

Allow to create/connect units in target of sample

Open sergeysova opened this issue 4 years ago • 5 comments

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)
  }
})

sergeysova avatar Nov 26 '21 20:11 sergeysova

This variant looks really good!

Kelin2025 avatar Nov 27 '21 16:11 Kelin2025

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 sample be 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

AlexandrHoroshih avatar Aug 14 '22 13:08 AlexandrHoroshih

Or we can just add eslint rule for that :)

Kelin2025 avatar Aug 14 '22 18:08 Kelin2025

I don't get it - how this rule may work? 🤔 Cut maximum level of nesting at some number?

AlexandrHoroshih avatar Aug 15 '22 05:08 AlexandrHoroshih

Just forcing 1 level of nesting only, at least on start

Kelin2025 avatar Aug 15 '22 08:08 Kelin2025

Not sure it is a good idea. Reopen if we plan to work on it.

sergeysova avatar Feb 15 '23 12:02 sergeysova