Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we really provide "DI"? #571

Open
BANOnotIT opened this issue May 15, 2023 Discussed in #570 · 0 comments
Open

Do we really provide "DI"? #571

BANOnotIT opened this issue May 15, 2023 Discussed in #570 · 0 comments

Comments

@BANOnotIT
Copy link
Collaborator

Discussed in #570

Originally posted by BANOnotIT May 15, 2023
There's a design pattern called Inversion of Control. In general, it states that it's not you who call some functionality but something, namely framework or library, calls your code when something specific needs to be done. You delegate some functionality to some other code and handle its result later. The simplest example of IoC is Callback pattern that is widely used in Node.js and Listeners that are used by Web platform in general.

Dependency injection is a specific form of IoC that is used to compose complex things using simple ones. DI is used to delegate composition to someone. Many DI libraries employ interface/implementation segregation to replace one implementation with another without breaking the interface. Also, there are many features in contemporary DI libraries such as conditional resolution, scopes, and lifetime control.

Reatom uses IoC in these situations:

  • hooks are the iconic IoC pattern employed by many frameworks and libraries
  • atoms delegate storing state to context
  • computed atoms dependency tracking is delegated to context also

But reatom doesn't provide any functionality to compose atoms automatically. All atoms are explicitly composed by a developer using ctx.spy(specificAtom) and ctx.get(specificAtom).

Note: atom fabrics, such as reatomAsync, are fabrics which are producing pattern.

I propose replacing "Implicit DI for simple SSR and testing" with something else. SSR often involves IoC usage to unify the state among servers and browsers. Testing, mainly unit testing, does heavily encourage IoC to only test one unit at a time but still doesn't require DI to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant