Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
react 简介
Search
Yuheng Zhang
November 14, 2014
400
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
react 简介
react 简介
Yuheng Zhang
November 14, 2014
More Decks by Yuheng Zhang
See All by Yuheng Zhang
Unleash your Vim
zhangyuheng
0
260
Javascript 函数表达式
zhangyuheng
2
440
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
1k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
250
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.6k
Making the Leap to Tech Lead
cromwellryan
135
10k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
550
The Cult of Friendly URLs
andyhume
79
6.9k
Un-Boring Meetings
codingconduct
0
350
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
2
340
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
Transcript
React 简介 宫煌 2014.11.14
题外话 about Yahoo http://yahooeng.tumblr.com/post/101682875656/evolving-yahoo-mail
React
React
Overview • 只关注 view 层 • ⻚页⾯面细划分为各部分 component • 核⼼心是组件的
render
Features • ⻚页⾯面渲染性能好,使⽤用 virtual DOM,避免操纵 DOM 损耗性能 • DOM 的读/写批量进⾏行,减少
layout 计算次数 • 当属性变化时,基于 virtual DOM 全部重新渲染 • 不需要借⽤用模版语⾔言实现逻辑,no strings • 不需要专⻔门操作 DOM 的库(jQuery)
var ExampleApplication = React.createClass({ render: function() { var appName =
this.props.appName; var message = 'React has been successfully running.' + ' Appname is: ' + appName; return React.DOM.p(null, message); } }); var ExampleApplicationFactory = React.createFactory(ExampleApplication); React.render( ExampleApplicationFactory({appName: 'Demo'}), document.getElementById('container') ); Basic usage
Full example <!DOCTYPE html> <html> <head> <meta http-equiv='Content-type' content='text/html; charset=utf-8'>
<title>Example</title> <link rel="stylesheet" href="../shared/css/base.css" /> </head> <body> <h1>Example</h1> <div id="container"> </div> <script src="../../build/react.js"></script> <script> var ExampleApplication = React.createClass({ render: function() { var appName = this.props.appName; var message = 'React has been successfully running.' + ' Appname is: ' + appName; return React.DOM.p(null, message); } }); var ExampleApplicationFactory = React.createFactory(ExampleApplication); React.render( ExampleApplicationFactory({appName: 'Demo'}), document.getElementById('container') ); </script> </body> </html>
props & state • props 是各 component 之间传递的数据,不 可变 •
state 是 component 内部的属性
None
Flux • ⼀一种应⽤用设计⽅方式,适⽤用性⼲⼴广泛,不仅⽤用于 react • 区别于 MVC,提出 action dispatcher store
view 的概念,数据单向传输
None
None
None
Action • 定义语意化的的⽅方法,被 view 的 component 调⽤用 • 数据由 view
传到 action
Dispatcher • 应⽤用的枢纽,由 action 调⽤用 • 数据由 action 传⼊入 dispatcher
• new Dispatcher() -> dispatch()
Store • 通过调⽤用 dispatcher 注册 handle • Dispatcher.register(function(payload ){}) •
数据 payload 由 dispatcher 传⼊入 store
View • 从 store 获取数据,并监听 store 的变化 • 数据由 store
传⼊入 view • 当 view 通过 setState 改变 state 时,重 新渲染 • 当有浏览器事件时,调⽤用 action 对应⽅方法
Unidirectional data flow
Flux 的例⼦子 • React docs
Tools • chrome devtools
Tools
Q&A
Thanks!