Sobes.tech
Middle

Have you used FSD (Feature-Sliced Design) in your project? How did you write samples and subscribe to events in Effector when using FSD?

sobes.tech AI

Answer from AI

Yes, I have used Feature-Sliced Design (FSD) in projects to organize frontend code by functional slices, which improved scalability and maintainability.

When working with Effector within FSD to write samples and subscribe to events, I followed these practices:

  • Samples: created sample states or events that reflect specific parts of the functionality (e.g., a particular feature or slice).
  • Subscriptions: subscribed to events or effects within the relevant layer or feature to localize logic and avoid global dependencies.

Example of creating a sample and subscription:

import { createEvent, createStore, sample } from 'effector';

// event in feature
const fetchData = createEvent();

// store for data
const dataStore = createStore(null);

// sample: trigger loading effect on fetchData
sample({
  clock: fetchData,
  target: fetchEffect,
});

// subscribe to effect result
dataStore.on(fetchEffect.doneData, (_, payload) => payload);

Thus, in FSD, the Effector logic structure corresponds to feature separation, which simplifies support and scaling of the application.

Have you used FSD (Feature-Sliced Design) in your… - sobes.tech