Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
174
7
7
-
7
FacebookFlux设计模式
Flux
中,
Action
State
都是不可变数据。
Action
可以来自某个
View
,或者来自其他
源地址,一般是一个
Web
服务器。
每次变更都需要一个
Action
。每个
Action
提供制造变更的一组指令集。
Action
也可以
被当作菜谱,告诉我们变更的内容是什么,创建变更时用到了哪些数据,以及
Action
的源头。用户唯一可以变更的就是
Store
Store
更新了数据,
View
UI
上渲染这些更
新,而
Action
会告知我们发生变更的过程和原因。
将用户的应用程序的数据流限制在这种设计模式下,将会使应用程序更易于修复和扩
展。来看看图
7-8
中的应用程序。我们会发现每个被分发的
Action
都被记录到控制台
上。这些
Action
告知我们当前
UI
显示大号数字
3
的具体流程。
如你所见,导致最后一次
State
变更的是一个
TICK
。它将之前的计数值修改为现在的
计数值
3
,看上去之前的计数值应该是
4
。这些
Action
告诉我们
State
的变化过程。我们
可以按图索骥,向上追溯到源头发现首次变更的计数值是
9
,因此该程序大概是一个
10
开始的倒计时程序。
来看看这个倒计时应用程序是如何使用
Flux
设计模式构建的。我们将会介绍设计模式
的每个部分,并讨论它们对倒计时应用中单向数据流的贡献。
View
让我们先从
View
开始,即一个
React
无状态组件。
Flux
将会管理应用程序的
State
,因
此除非用户需要使用一个生命周期函数,否则将不会用到类组件。
倒计时应用的
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

React快速上手开发

React快速上手开发

Stoyan Stefanov
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236