DEV Community

Discussion on: Early thoughts on Angular with Redux (NgRx)

Collapse
 
hclatomic profile image
HCl Atomic • Edited

Angular is 2 way data binding, so all the changes of all variables are natively watched.

Therefore I make a store with a service, and I call directly this store inside the HTML templates of the component, and so I have no local variable to declare in the current component. The amount of code for each component is drastically lowered.

Any change of a variable in such a store, performed from the typescript or from an input of the HTML template, is automatically applied to all the application (depending upon the module where you imported your store service, see singleton of your store).

Nearly everything is async in Javascript (events, call to server, indexedDB, ....) so Angular is fundamentally designed to deal with this asynchronism. You only need to use the Elvis operator (myvar?.myproperty) for async variables in the template of the component, and initiate your component into a NgOnInit function, or ngAfterViewInit in some case. This is because initiating your component in the constructor will not be suitable with asynchroneous processes (see life cycle). The constructor is just used to import the store service.

All this is working tremendously well, and morever for very rich and complex applications (see for instance oceanvirtuel.eu).