DEV Community

Discussion on: JS and Design patterns - Chapter 2 🚀

Collapse
juanda_dev profile image
Juan Martínez • Edited on

I'm sort of new to these topics like design patterns and programming paradigms, but I recently saw a video of a guy managing a cookie library with something like this but in a class. I think it'll be great for most common functions like handling the change of a state in a text field on React. Also, I guess it improves this declarative programming stuff instead of putting all the logic visible in your code, isn't it?

Thanks for sharing this, It's good to learn something new every day!

Collapse
codespresso profile image
Codespresso Author

Thank you for your comment! 🚀 There are certainly ways of how you could use, and when we use design patterns. Cookie library is one of the ways we are using it, also, we could use it to implement a singleton service, that way we can hold a part of an application's state, for example, we could expose an API service to an application, that will allow us to interact with that specific piece of state. Those services can provide, for example, that we don't have to send props down to the child components from the respective parent components, but instead, we are using application state and giving direct access to the state for any component. The state that is governing the text field change is actually a specific Component current state. The state as it is should be treated as immutable. So, manual state mutation may be overridden when setState is processed. Of course, managing the entire application state with store comes with drawbacks, for example, Redux, the reducer updates the state by returning a new state every time, because of immutability. That can cause excessive use of memory. So we should be very careful when deciding to use application state management.

I will certainly talk about this in future blogs, so please stay tuned! 😎

Collapse
juanda_dev profile image
Juan Martínez

Amazing! I never thought about this problem with Redux. I recently learned how to use it in my projects but it looks like it's going to be a problem in the future. I'll be waiting for your posts.