π 6/8 JS Reactive Patterns: Reactive HTML Attributes With MutationObserver
#js #patterns #MutationObserver
#js #patterns #MutationObserver
One way to achieve reactivity in the DOM is by using MutationObserver. Its API allows us to observe changes in attributes and also in the text content of the target element and its children.
π 7/8 JS Reactive Patterns: Custom Events as a Browser Version Of PubSub
#js #patterns #CustomEvent
#js #patterns #CustomEvent
The browser offers an API for triggering and subscribing to custom events through the CustomEvent class and the dispatchEvent method. The latter provides us with the ability not only to trigger an event but also to attach any desired data to it.
π 8/8 JS Reactive Patterns: Reactive Scrolling With IntersectionObserver
#js #patterns #IntersectionObserver
#js #patterns #IntersectionObserver
The IntersectionObserver API enables reacting to the intersection of a target element with another element or the viewport area.
π Angular Design Patterns: Factory Pattern
#angular #patterns #guide
β οΈ The example is for presentation purposes only and can be refactored.
β Article link
#angular #patterns #guide
β οΈ The example is for presentation purposes only and can be refactored.
β Article link
π2
π Composite Design Pattern
#js #patterns #composite
β Article link
#js #patterns #composite
Composite: Basic Idea
The first thing we need to look at is the definition offered by the book from the Gang of Four:
βCompose objects into tree structures to represent part-whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.β
β Article link
#js #patterns
Pub/Sub, which means Publish-Subscribe, uses a more structured approach. Instead of depending on DOM components, it uses a central message bus, similar to an events message board. Here is the summary:
- Publishers: These are the event announcers who broadcast messages (events) via the messaging bus.
- Subscribers: These are the visitors who registered to receive specific announcements (events). When a relevant interaction comes, subscribers get notified and can take action.
β Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π2
#js #interview #deepClone #patterns
Analysis: Currying of the add function is achieved by recursively calling a function that continues to accept parameters.
Please open Telegram to view this post
VIEW IN TELEGRAM
#angular #patterns #composite
The Composite pattern defines two basic types of elements sharing the same interface: simple leaves and complex containers. A container can consist of both leaves and other containers. This allows for the construction of a nested, recursive structure of objects resembling a tree.
β Article link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π4
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π1
π The Adapter Pattern in TypeScript
#ts #patterns #adapter
β Article link
#ts #patterns #adapter
The Adapter Pattern is a structural design pattern that allows incompatible interfaces to work together by providing a "wrapper" or "adapter" around an existing class. Below is a real-world example of the Adapter Pattern in TypeScript, where we want to integrate a new payment gateway into an existing e-commerce application.
β Article link
π1
#angular #patterns
Why Design Patterns are important
1. Scalability
Design Patterns help break your app into small, reusable pieces. This makes it easy to add new features later without messing up existing ones.
2. Maintainability
Following design patterns ensures your code has a clear, organized structure.
For example using patterns like the Singleton Pattern makes the app more maintainable because you only have to change one piece of code in the service, and all the components that depend on it will automatically adapt.
3. Testability
Design patterns promotes the separation of concerns which makes it easier to mock and test components
4. Code Reusability
Patterns encourage writing reusable code.
For example, patterns like Factory and Singleton help you organize similar tasks in one place, so you can easily reuse them without rewriting the same logic.
β Article Link
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π4
π9
Please open Telegram to view this post
VIEW IN TELEGRAM
Please open Telegram to view this post
VIEW IN TELEGRAM
π5