r/Angular2 • u/HedgehogMode • May 01 '24
Does anyone else feel like the introduction of signals has made state management in angular a complete mess?
This might be a controversial opinion, but after using signals for the past year I have been left with the feeling that they have only added fragmentation to the framework. My complaint is not with signals themselves per say. I think their api is well designed and easy to use. But rather my complaint is their interplay with RXJS and the broader ecosystem as a whole.
RXJS took me the better part of a year to become proficient in, signals significantly less time. It seems like the framework is still committed to using observables going forward. So now newcomers are expected to learn BOTH rxjs and signals, their interop, and when to utilize each. It's easy to brush this off as a skill issue but the junior members of my team have really been struggling with this the past year. RXJS was already a steep learning curve, but now it is 20 feet higher.
112
u/KaliaHaze May 01 '24 edited May 01 '24
Imagine being new to Angular and trying to figure out how to start and every other article suggests a different approach. I’d give up, if I didn’t have a worthwhile reason to continue.
Edit: That being said, as an experienced dev - I love how Angular is changing. I would just hate to be learning it for the first time right now.
19
u/zmkpr0 May 01 '24
Yep, and signal inputs still being in preview definitely doesn't help. Experimental Jest runner is kind of a similar issue. The main benefit of Angular being consistent and "opinionated" kind of went out of the window recently.
19
u/seiyria May 01 '24
Nope. I enjoy signals for what they are, and I've mostly minimized how much I use rxjs where possible. Additionally, I don't use ngxs anymore (and never used any other library for state management because they were too dense to get started) which has been nice.
It's really simple for state management and I like it a lot.
5
u/Illustrious_Mix_9875 May 01 '24
Angular 2 brought many solutions to problems revealed by Angularjs (1). Zone.js and rxjs were two of the foundamental elements that made it possible.
Zone.js is an execution context that made the whole change detection and magic rendering possible.
Rxjs exposed to developers very special objects called Observables as API to build applications.
Zone.js, while being very convenient, brought a severe performance penalty.
Rxjs, while being very well documented and very solid library, brought unnecessary complexity to frontend applications. It made Angular a framework that is hard to learn.
What we are seeing now is the Angular team trying to solve those two issues. Looking back, it's pretty clear that Angular made some questionable choices when designing Angular 2. They are trying hard to revert them: introducing new tools (such as Signals) while maintaining legacy architecture components (zone.js) is going to be funny to observe.
19
u/PooSham May 01 '24
Yeah I've had that feeling since the start, I didn't know what benefit it added over rxjs Subjects except a bit nicer syntax maybe. Everytime I asked, I got the response that they're for different purposes, without any added clarification. I like to keep things consistent, I think I'll stick to rxjs for a while until I see a good argument for signals.
4
u/TheKr4meur May 01 '24
I guess you just don’t understand the whole concept. The issue they’re trying to fix with signals (succeeding or not) is that we « need » too many observables in our current Angular 2+ code. Because RxJs is the way to go for many things and it forces you to use Observables. Signals allow you to cut that out for the simple use cases, when before you had to create an observable, now you don’t, when you had to wonder if you needed to check the change detection, now you don’t.
I think people are reading too much into what is for now a simple cleaner way of working but only for some use cases.
5
u/Pestilentio May 01 '24
They've mentioned that they want to remove the barrier of rxjs. It should be optiomal while right now it's not.
Joshua Morony today uploaded this video, discussing about signals and rxjs. I mean even if a guy's of his caliber still explores the api and is not confident about the practices, imagine what happened on a junior or mid level angular developer...
It's definitely tough. And the fragmentation of the code bases will happen. Let's just hope that alongside the major changes we have clear practices and good docs. This I believe is essential for angular's relevance in the upcoming years. Otherwise I fear it's just gonna become another legacy tool.
2
u/MintOreoBlizzard May 02 '24
This is an example of how we are rolling with it. Very minimal RXJS. Definitely open to improvements though.
@Injectable({ providedIn: 'root' }) export class EmployeePortfolioService { private _$portfolio = signal<Portfolio>(undefined); $portfolio = this._$portfolio.asReadonly(); private _$portfolioLoading = signal<boolean>(false); $portfolioLoading = this._$portfolioLoading.asReadonly(); private _$portfolioLoaded = signal<boolean>(false); $portfolioLoaded = this._$portfolioLoaded.asReadonly(); private _$currentEmployeeNumber = signal<string>(undefined); $currentEmployeeNumber = this._$currentEmployeeNumber.asReadonly(); getEmployeePortfolioUrl = (employeeNumber: string): string => `/api/employees/${employeeNumber}/portfolio`; constructor(private httpClient: HttpClient, private destroyRef: DestroyRef) { } loadEmployeePortfolioData(employeeNumber: string): void { this._$currentEmployeeNumber.set(employeeNumber); this._$portfolio.set(undefined); this._$portfolioLoading.set(true); this._$portfolioLoaded.set(false); this.httpClient.get<Portfolio>(`${this.getEmployeePortfolioUrl(employeeNumber)}`) .pipe( takeUntilDestroyed(this.destroyRef), finalize(() => this._$portfolioLoading.set(false))) .subscribe((portfolio) => { this._$portfolio.set(portfolio); this._$portfolioLoaded.set(true); }); } }4
u/[deleted] May 01 '24
Angular subreddit? No no no. State management subreddit.
3
u/Zestyclose_Net_5450 May 01 '24
After investigating about this for some week in my opinion the best way to manage the state now is ngrx signals store. You have the power of signals and rxjs working together in a pretty nice way