Skip to Content
微前端设计与实现
book

微前端设计与实现

by Luca Mezzalira
August 2022
Beginner to intermediate
270 pages
7h 38m
Chinese
Posts & Telecom Press
Content preview from 微前端设计与实现
44
4
多时间,并减少心智负担。当代码限定在一定的范围内时,总是比分散在应用的多个部分
时更容易让人理解。
当库甚至逻辑被用于多个业务领域中时,比如在表单验证库中,你有以下几个选择。
复制代码
代码重复并不一定总是一个坏做法,这取决于优化代码的目的是什么以及重复代码的整
体影响。比方说,有一个组件根据用户状态和它所在的视图的不同会有不同的状态,且
与其他任何领域相比,这个组件在某个业务领域中经常发生变更。你可能想把这类组件
集中起来管理,但请记住,每当有一个集中管理的库或组件时,必须建立一个可靠的管
理机制,以确保当这个共享的库或组件发生更新时,它也会在每个使用这个共享库或组
件的微前端中被更新。当这种情况发生时,还必须确保新版本不会破坏任何一个微前端
的任何功能,你需要协调多个团队一起升级。这样的话,这个组件并不难实现,而且对
于每个使用它的团队来说,它都将变得更容易构建,因为需要考虑的状态更少。这使
得每个团队都能以自己的速度独立开发,提高了交付速度并且降低了每个团队的外部依
赖。当需要复制的代码不是很多时,这种方法效果最好。而当有几十个类似的组件需要
复制时,这种方法就不再适用了,需要做的是把它们抽离成一个库。
将代码抽离到一个共享库中
在某些情况下,你确实想将业务逻辑集中到某个库或者组件中,以确保每个微前端都使
用相同的实现,比如集成支付能力。因为结账用的表单中实现了多种支付方式,包括表
单验证逻辑、错误处理逻辑等,所以复制如此复杂且精妙的东西是不明智的。而创建一
个共享库有助于保持跨应用的一致性,且可以简化整个平台的整合过程。在自动化流水 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python语言及其应用(第2版)

Python语言及其应用(第2版)

Bill Lubanovic

Publisher Resources

ISBN: 9787115595089