6 Concepts to Master to be an Angular Architect

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

内容简介: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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

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

数据结构

数据结构

邓俊辉 / 清华大学出版社 / 2013-9 / 39.00元

《清华大学计算机系列教材:数据结构(C++语言版)(第3版)》按照面向对象程序设计的思想,根据作者多年的教学积累,系统地介绍各类数据结构的功能、表示和实现,对比各类数据结构适用的应用环境;结合实际问题展示算法设计的一般性模式与方法、算法实现的主流技巧,以及算法效率的评判依据和分析方法;以高度概括的体例为线索贯穿全书,并通过对比和类比揭示数据结构与算法的内在联系,帮助读者形成整体性认识。一起来看看 《数据结构》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

MD5 加密
MD5 加密

MD5 加密工具

SHA 加密
SHA 加密

SHA 加密工具