Announcing SmartNgRX

Do you use NgRX in your Angular code?

Imagine an NgRX world where you almost never knew you were using NgRX. A world where you never had to write a reducer, action, or effect. A world where you never had to call store.dispatch(). A world where the data you worked with automatically persist to the server. A world where the data is retrieved from the server as it is needed and removed from memory when it is not, or never removed if that's what you want. A world where the data automatically refreshes from the server, or you can use websocket messages to refresh the data and, in either case, the only data that refreshes is the data the code is actively using. A world where optimistic UI is built into the framework.

Introducing SmartNgRX. A framework I've been working on for over a year that does everything I just mentioned and more. It's a framework that is built on top of NgRX and works with your existing NgRX code.

The full documentation is available at SmartNgRX Documentation but let me give you a brief overview of how it works.

Brief Overview

First, there are two providers you will need to add to your application. The first is provideSmartNgR(), which is added to the providers array in your AppModule. The second is provideSmartFeatureEntities() which is added to the module, or route, nearest where you'll use it.

These two providers set up the configuration information that SmartNgRX will need so it can perform its magic. They control things such as how often to refresh the data, when to remove unused data from memory, what service to call to retrieve the data for an NgRX slice and what a placeholder row looks like for a particular slice of data.

For you to define the service the SmartNgRX effect will call, you'll need to create an EffectService. This service is where you control how the CRUD operations interact with the server. This and the selectors are the only code you'll need to write.

Which brings us to the selectors. Instead of using the createSelector function from NgRX, you'll use the createSmartNgRXSelector function from SmartNgRX. This function defines the relationship between a parent selector and any children it may have. You can use selectors created with createSmartNgRXSelector with selectors created with createSelector and mix and match them as needed.

That's it. All the other code you normally write is handled by SmartNgRX.

Give it a try and let me know what you think.

Karthik C

Senior Full Stack Developer @Amex | Java, GraphQL, PL/SQL, Kotlin, Spring Boot, Microservices | Expert in React, Angular, Kafka, Golang, Okta, AEM, IAM, Docker & Kubernetes, AWS, GCP, Azure

4 个月

Thanks, Dave Bush, for introducing this and sharing insights on how it can streamline the workflow!?

回复
Ian Drake

Senior Technology Consultant | .NET & Web Technologies Expert | Finance & Insurance Industry Specialist

4 个月

This sounds interesting. The documentation is a bit dense with an example that is clearly meant to show off the fully realized power of the library. It would be great to see a side-by-side comparison of the NgRX basic example show here https://ngrx.io/guide/store to get a flavor for how much boiler plate goes away and what new conventions would replace it.

要查看或添加评论,请登录

社区洞察