Is it a good idea to make public variables on a service BehaviorSubject types as a standard approach.
The idea being, that if you want to make a variable public, chances are big that you want to respond to changes of them (now or in the near future). That seems to be the case for pretty much every public variable I add on a service.
I started to change the type of some variables because I had to, and now I am starting to see this as some kind of pattern.
An example would be a public variable which holds the connection state. isConnected. When the connection of the service is broken, you want to show a popup message to the end user, and make it dissapear when the connection is restored.
Another example: a variable contains the UI settings of the currently logged in user. When one of these settings changes, you want to apply these settings immediately and re-render the screen layout.
Since I haven't read about this as a pattern before, is this strategy flawed for some reason ? If so, why ?
Aucun commentaire:
Enregistrer un commentaire