6 Concepts to Master to be an Angular Architect

栏目: IT技术 · 发布时间: 5年前

内容简介:Six concepts every Angular developer should explore in-depth in order to master Angular and design well-architected applications.Angular is one of the biggest frameworks around: it provides a lot of features out-of-the-box, which means there are quite a fe

Six concepts every Angular developer should explore in-depth in order to master Angular and design well-architected applications.

6 Concepts to Master to be an Angular Architect

Angular is one of the biggest frameworks around: it provides a lot of features out-of-the-box, which means there are quite a few concepts to be able to master if from top to bottom.

There are six specific concepts I think every Angular developer should explore in-depth in order to master Angular and be able to be proficient with writing well-architected applications.

No, knowing its source code is not what’s I think it’s required — although I’ve personally had to explore in a small number of situations.

An Architecture for Cloud Component Hubs

Cloud component hubs like Bit.dev are commonly used to publish, document and organize Angular components. We use them to maximize code reuse and build apps that scale.

As you’ll see in this post, a good Angular architecture ensures our codebase is built in a way that enables easy sharing and reusing components in and across repositories.

6 Concepts to Master to be an Angular Architect
Exploring components published on Bit.dev

1) Module/Library Architecture

Angular’s Module architecture is a bit unique, and probably one of the hardest parts to fully grasp for beginners.

The most confusing concept about it is that we’re already using a module architecture on top of it: of course, I’m talking about ES imports.

Because Angular Modules add an additional layer of logical grouping, it’s important to keep them as much related as possible.

But knowing how to separate and split your app’s functionality in well-defined modules is a fundamental part of architecting Angular apps.

Different Types of Angular Modules

There are different types of Angular Modules you should be aware of:

  • Declarations/Widget Module (example: a module that is a collection of UI Components, Directives and Pipes)
  • Services Module (example: HttpClientModule)
  • Routing Module
  • Domain/Feature Module
  • Core/Shared Module

I wrote in details about each type in the article below:

Library or Module?

I would argue that we can bring this distinction at the library-level : a library with only services, a library that represents a route, and so on.

But whether you’re writing a module or a library depends a lot on your project type, and whether you are using a monorepo or a multi-repo project

Questions to ask yourself before writing a module

Before writing a module, there are a few questions to ask yourself:

  • What sort of module am I writing? If you can’t answer this question, you should familiarize yourself with the different types of modules I listed above.
    It’s highly likely you’ll need one or two types of modules, so the answer may very well be two modules: Routing and Service
  • Should this module be its own library or should it be simply a module? This is a little bit harder to answer: if you’re using a monorepo, my opinion is that building libraries would be a better option in the long run

2) Separation of Concerns between Components, Services, and Directives

Separating concerns is simple in theory, and yet harder than it seems. We’ve been taught since the Angular.js days to keep components “lean” and services “fat”, and fundamentally there hasn’t been a substantial difference in the newest versions.

It is still important to understand what exactly belongs into Components and what belongs into Services , and why Directives may just be an incredibly underrated feature.

State

Placing state is a matter of understanding whether the data is accessed and shared outside of a component or whether it is local and encapsulated.

  • If the state is shared between components, or it needs to be accessed from services, then place your state in a service . It doesn't really matter what State Management tool you use in this case as long as it is in a service
  • If the state is local (ex. a form) and only used within a component, then simply store it in a component

DOM Manipulation

Most DOM Manipulation should probably happen within Directives. Let’s assume you’re adding a Drag and Drop functionality to one of your components.

Sure, you can create a component and bind events from there, but at that point, you’re mixing two things:

  • how the component looks
  • how a certain component’s feature behaves

Directives are the ultimate reusability feature in Angular and I see them underused in almost every project I have worked on. Directives can be used to take off lots of responsibility from Components.


以上所述就是小编给大家介绍的《6 Concepts to Master to be an Angular Architect》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Windows内核原理与实现

Windows内核原理与实现

潘爱民 / 电子工业出版社 / 2010年4月 / 99.00元

本书从操作系统原理的角度,详细解析了Windows如何实现现代操作系统的各个关键部件,包括进程、线程、物理内存和虚拟内存的管理,Windows中的同步和并发性支持,以及Windows的I/O模型。在介绍这些关键部件时,本书直接以Windows的源代码(WRK, Windows Research Kernel)为参照,因而读者可以了解像Windows这样的复杂操作系统是如何在x86处理器上运行的。 ......一起来看看 《Windows内核原理与实现》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

随机密码生成器
随机密码生成器

多种字符组合密码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器