-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
218 additions
and
59 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"label": "计算机基础", | ||
"label": "前端基础", | ||
"position": 2, | ||
"link": { | ||
"type": "generated-index", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
sidebar_position: 5 | ||
--- | ||
|
||
# 计算机网络 | ||
|
||
计算机网络由若干节点和链路组成。 | ||
|
||
因特网根据工作方式可以分成以下的两大块: | ||
* 边缘部分:用户直接使用,用来通信和资源共享。 | ||
* 核心部分:由大量网络和连接这些网络的路由器组成,为边缘部分提供服务。 | ||
|
||
在边缘部分:端可以是一个手机、平板、电脑,也可以是大型计算机,摄像头。 | ||
在网络边缘的端系统之间的通信方式通常可划分为两大类:客户-服务器方式(c/s)和对等方式(p2p) | ||
|
||
在核心部分:起特殊作用的是路由器。路由器是**实现分组交换**的关键构件,其任务是转发收到的分组。 | ||
|
||
在建立连接->通话->释放连接。这三个步骤被称为电路交换。 | ||
## 什么是报文 | ||
分组交换采用存储转发技术。通过将一个报文拆解,每个数据端携带必要的首部及组合信息,通过(多个)交换机的连接最终找到需要通信的主机。(类似快递:收货->城市1仓库->城市2仓库...->送达) | ||
|
||
## 交换方式 | ||
* 电路交换:整个报文的比特流连续地从源头到终点 | ||
* 报文交换:整个报文到相邻节点,最后再到终点 | ||
* 分组交换:单个分组到相邻节点,最后再到终点 | ||
|
||
计算机网络的最简单定义是:一些互相连接的、自洽的计算机的集合。这里自洽的概念即独立的计算机,有自己的硬件和软件,可以单独运行使用,而相互连接代表他们之间能够进行数据通信或交换信息。 | ||
|
||
* 按网络的作用范围可以分成:广域网WAN、城域网MAN、局域网LAN、个人局域网PAN。 | ||
* 按网络的使用者可以分成:公用网、专用网、接入网 | ||
|
||
## 性能指标 | ||
|
||
1. 速率:传输数据的速率 单位bit | ||
2. 带宽:允许信号的频带范围 | ||
3. 吞吐量:单位时间通过的数据量 | ||
4. 时延:数据从一端到另一段所需的时间 | ||
5. 时延带宽积:传播时延✖️带宽 | ||
6. 往返时间 | ||
7. 利用率 | ||
|
||
非特性指标 | ||
1. 费用 | ||
2. 质量 | ||
3. 标准化 | ||
4. 可靠性 | ||
5. 可扩展性和可升级行 | ||
|
||
## 五层协议的体系结构 | ||
|
||
### 应用层 | ||
|
||
通过应用进程间的交互来完成特定网路应用。应用层协议定义的是应用进程间通信和交互的规则。 | ||
|
||
### 运输层 | ||
|
||
运输层的任务就是负责向两个主机中进程之间的通信提供通用的数据传输服务 | ||
|
||
TCP 协议 —— 提供面向连接的、可靠的数据传输服务,其数据传输的单位事报文段。 | ||
UDP 协议 —— 提供无连接的、尽最大努力的数据传输服务(不保证数据传输的可靠性)。数据传输的单位是用户数据报。 | ||
|
||
### 网络层(网际层) | ||
|
||
通过分组交换网上不同的主机提供通信服务。 | ||
|
||
IP协议 | ||
|
||
> 网络层网络二字,已不是我们通常谈到的具体的网络,而是在计算机网络体系结构模型中的专用名词。 | ||
### 数据链路层 | ||
|
||
数据链路层将网络层交下来的IP数据报组装成帧(framing),在两个相邻结点间的链路上传送帧(frame)。每一帧包括数据和必要的控制信息(同步信息、地址信息、差错控制等) | ||
|
||
### 物理层 | ||
|
||
传输的数据事比特。要考虑用多大的电压代表0或者1。 | ||
|
||
> 传递信息所利用的物理媒介不在物理层内。 | ||
|
||
每一层加上必要的控制信息就变成了下一层的数据单元。而第一层(物理层由于是比特流的传送,所以不再加上控制信息。 | ||
|
||
* 实体:任何可发送或接受信息的硬件或者软件进程。 | ||
* 协议:控制两个对等实体(或多个实体)进行通信的规则的集合。 | ||
* 服务:要实现本层协议,还需要使用下面一层所提供的服务。 | ||
* 服务访问点:在同一系统中相邻两层的实体进行交互的地方 | ||
|
||
其中,协议事水平的,服务是垂直的。 | ||
|
||
## TCP/IP的体系结构 | ||
|
||
应用层: HTTP SMTP DNS RTP | ||
运输层: TCP UDP | ||
网络层: IP | ||
数据链路层: 网络接口1 网络接口2 | ||
|
||
## 物理层 | ||
|
||
### 物理层的任务 | ||
物理层考虑的是怎样才能在连接各种计算机的传输媒体上传输数据比特流,而不是指具体的传输媒体。物理层的作用是要尽可能地屏蔽掉多种传输媒体和通信手段的差异,使物理层上面的数据链路层感觉不到这些差异。用于物理层的协议也常被称为物理层规程。 | ||
可以将物理层的主要任务描述为确定与传输媒体的接口有关的一些特性: | ||
1. 机械特性:接口所用接线器的形状和尺寸,引脚数目和排列等等。 | ||
2. 电器特性:指明在接口电缆的各条线上出现的电压的范围。 | ||
3. 功能特性:指明某条线上出现的某一电平的电压表示何种意义。 | ||
4. 过程特性:指明对于不同功能的何种可能时间的出现顺序。 | ||
|
||
几种常用的信道复用技术 | ||
|
||
集中常用的宽带接入技术,主要是ADSL和FTTx | ||
|
||
### 数据通信系统的模型 | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# 为什么 React 团队在函数式组件中弃用了 defaultProps | ||
|
||
[源链接](https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md#deprecate-defaultprops-on-function-components) | ||
|
||
简单来说,就是没有必要。 | ||
|
||
在函数式组件中,我们完全可以使用用JS默认参数的形式,来申明默认属性,代码如下: | ||
```typescript | ||
function Foo({foo = 1, bar = "hello"}) { | ||
let props = {foo, bar}; | ||
//... | ||
} | ||
``` | ||
|
||
对于大多数团队来说 `React` 的 `defaultProps` 是一个黑盒,如果我们把默认属性的行为放在函数组件定义中,从代码质量来说更加可控。 | ||
|
||
而`defaultProps`设计之出是为了什么呢? | ||
|
||
`React` 团队认为 `defaultProps`在类上非常有用,因为`props`对象会被传递给许多不同的方法。生命周期、回调等等。每一个都在它自己的范围内。这使得它很难使用`JS`默认参数,因为你必须在每个函数中复制相同的默认值。 | ||
|
||
简而言之,就是在每个生命周期和方法的作用域中可以使用新的默认值。 | ||
|
||
```typescript | ||
class Foo { | ||
static defaultProps = {foo: 1}; | ||
componentDidMount() { | ||
let foo = this.props.foo; | ||
console.log(foo); | ||
} | ||
componentDidUpdate() { | ||
let foo = this.props.foo; | ||
console.log(foo); | ||
} | ||
componentWillUnmount() { | ||
let foo = this.props.foo; | ||
console.log(foo); | ||
} | ||
handleClick = () => { | ||
let foo = this.props.foo; | ||
console.log(foo); | ||
} | ||
render() { | ||
let foo = this.props.foo; | ||
console.log(foo); | ||
return <div onClick={this.handleClick} />; | ||
} | ||
} | ||
``` | ||
|
||
因此,在 React 团队的后续更新中已经实现:在函数是组件中使用`defaultProps`,`React`会在`createElement`中添加一个警告。这包括其他特殊组件,如`forwardRef和memo`。 | ||
|
||
|
||
## 总结:在函数式组件中应当使用JS函数默认参数定义组件默认属性,避免使用 defaultProps |
67ce956
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
blog – ./
blog-jade-five-78.vercel.app
blog-dbsds.vercel.app
blog-git-main-dbsds.vercel.app