Best practices
Effector provides you pretty powerful tooling to migrate all the remaining logic from views to your models(events, effects, stores and its connections in general)
Here are some advices with code examples:
Store handlers
To avoid semantic inconsistency you handle all store updates with original store, not mapped ones since its values will be updated automatically.
File Structure
Any business logic could be split by models. You should create a folder for each model by its scope of responsibility in /models
directory.
Every model consists of declarations and initialization file. So, declarations is index.js
and initialization file is init.js
.
Imagine we have another responsibility scope with bigger index.js
, so we had to separate store declarations into state.js
to improve readability
Root init.js
imports all init files from models.
It should be imported in your app root.
Init file in model exports nothing, it only imports events, stores, effects from different models.
This is a place where you initialize your effects and store handlers, to keep other modules pure. Just after that, you start buildling the dataflow of the model (connecting Units aka forward
, sample
, guard
, merge
, split
)
Init files as well could contain imports from another models to deal with cross-model business-logic.