angularangular-akitaangular-state-managmement

Why are Akita Queries accessed directly in components


I am learning Akita to add state management to an Angular application. When looking at the architecture diagram in the Akita documentation and examples such as this one on the Akita GitHub repo I see that the Query is accessed directly in components. I was surprised to see this because I expected that the state management part of an application would be hidden behind the services and abstracted away from the consumers, i.e. components. Unlike the Query, the Store is hidden behind the Service and not accessed directly in the components. The way I see it, if the Query was hidden behind the Service like the Store is hidden behind the Service, then the consumers would only need to import one thing, i.e. the Service, for each data source.

So my question is why does Akita want us to access the Query directly in components but not the Store? Is there a downside to hide the Query behind the Service?


Solution

  • I asked the same question in the Akita Gitter channel, and Netanel Basal, the author of Akita, responded to my question with the following:

    There is no downside to do what you want. I already saw people that work like that, and it's totally valid. The Store is the data layer, and the component shouldn't know about it. It only should know how to get the data. That's why we inject the Query in the components.