Angular πŸ‡ΊπŸ‡¦ - practical notes
1.63K subscribers
1.6K photos
1 file
532 links
Angular - practical notes

This group is for posting practical notes for Angular developers. Mostly all posts are for quick implementation https://t.me/angular_practical_notes (Commenting on posts only in ENG and UA langs here). Welcome!
Download Telegram
πŸ“„ Angular’s GoF patterns. Factory Method.

#angular #patterns

Advantages:

β€” Flexibility and expandability: Allows for easy introduction of new types of products without changing existing code.
β€” Reducing dependencies: The Factory Method reduces the direct dependency between classes that create and use objects, making code modification and testing simpler.
β€” Ease of maintenance and updates: Code using the pattern is easier to maintain and update, as adding a new type of product often doesn’t require changes to the existing code that uses the factory.


Disadvantages:

β€” Complex architecture: Using Factory Method can complicate application architecture, especially when used unnecessarily or in simple scenarios.
β€” Code bloat: Creating many factory methods and classes can overload the code, making it hard to understand, particularly for new developers.
β€” Performance issues: In some cases, particularly with incorrect implementation, Factory Method can affect application performance due to additional method calls and object creations.
β€” Debugging difficulty: Following this pattern can make debugging harder since the actual object creation is hidden within the factory method, complicating error tracking.
β€” Need for careful planning: Effective use of Factory Method requires detailed planning and understanding of when and what objects should be created. Planning errors can lead to incorrect or excessive implementation.
β€” Limited flexibility in some scenarios: While Factory Method provides flexibility in object creation, it can be limited in scenarios requiring very dynamic or conditional object creation.
β€” Not suitable for simple applications: For small or simple applications with a relatively static structure, using Factory Method might be unnecessary and complicate the project.


βœ… Article link
πŸ‘2
πŸ“„ 1/8 JS Reactive Patterns: PubSub or Publish-Subscribe

#js #patterns #pubsub

PubSub is one of the most commonly used and fundamental reactivity patterns. The Publisher is responsible for notifying Subscribers about the updates and the Subscriber receives those updates and can react in response.

One popular example of its usage is Redux. This popular state management library is based on this
pattern (or more specifically, the Flux architecture). Things work pretty simple in the context of Redux:

β€” Publisher: The store acts as the publisher. When an action is dispatched, the store notifies all the subscribed components about the state change.

β€” Subscriber: UI Components in the application are the subscribers. They subscribe to the Redux store and receive updates whenever the state changes.
πŸ‘3❀1πŸ”₯1
πŸ“„ 2/8 JS Reactive Patterns: Custom Event Targets

#js #patterns #customEvent

If you prefer not to dispatch events globally on the window object, you can create your own event target.

By extending the native EventTarget class, you can dispatch events to a new instance of it. This ensures that your events are triggered only on the new class itself, avoiding global propagation. Moreover, you have the flexibility to attach handlers directly to this specific instance.
πŸ‘4
πŸ“„ 3/8 JS Reactive Patterns: Observer

#js #patterns #observer

The Observer pattern is really similar to PubSub. You subscribe to the Subject and then it notifies its subscribers (Observers) about changes, allowing them to react accordingly. This pattern plays a significant role in building decoupled and flexible architecture.
πŸ‘1
πŸ“„ 4/8 JS Reactive Patterns: Reactive Properties With Proxy

#js #patterns #proxy

If you want to react to changes in objects, Proxy is the way to go. It lets us achieve reactivity when setting or getting values of object fields.
πŸ‘1
πŸ“„ 5/8 JS Reactive Patterns: Individual Object Properties and Reactivity

#js #patterns #defineProperty

If you don’t need to track all the fields in the objects, you can choose the specific one using Object.defineProperty or group of them with Object.defineProperties.
πŸ“„ 6/8 JS Reactive Patterns: Reactive HTML Attributes With 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

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

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
πŸ‘2