+ All Categories
Home > Technology > Доклад "React under the hood"

Доклад "React under the hood"

Date post: 14-Jan-2017
Category:
Upload: kateryna-porshnieva
View: 294 times
Download: 8 times
Share this document with a friend
27
ReactJS under the hood Поршнева Катерина 2016
Transcript
Page 1: Доклад "React under the hood"

ReactJS under the hoodПоршнева Катерина

2016

Page 2: Доклад "React under the hood"
Page 3: Доклад "React under the hood"

React re-renders the whole app on any data (state) change

Page 4: Доклад "React under the hood"

DOM is slow, JavaScript is fast.

Page 5: Доклад "React under the hood"

DOM is slow, JavaScript is fast.

Page 6: Доклад "React under the hood"

Виртуальный DOM

Page 7: Доклад "React under the hood"

Легковесная копия реального DOM в виде JavaScript объектов

Виртуальный DOM

Page 8: Доклад "React under the hood"

<Nav color="blue"> <Profile> Katya </Profile> </Nav

React.createElement( Nav, {color:"blue"}, React.createElement( Profile, null, "Katya" ) );

до после

JSX

Page 9: Доклад "React under the hood"

При каждом изменении

React строит новое виртуальное DOM-дерево

Сравнивает с предыдущим

Рассчитывает минимальное количество изменений DOM-дерева и добавляет их в очередь

Применяет все изменения к реальному DOM-дереву

Page 10: Доклад "React under the hood"

• Эффективные алгоритмы сравнения

• Группировка операций чтения/записи при работе с DOM

• Эффективное обновление только под-деревьев

• Эффективная работа со списками элементов

Page 11: Доклад "React under the hood"

Сравнение DOM-деревьев

Page 12: Доклад "React under the hood"
Page 13: Доклад "React under the hood"
Page 14: Доклад "React under the hood"

Списки

Page 15: Доклад "React under the hood"

Списки

Page 16: Доклад "React under the hood"

Списки

Page 17: Доклад "React under the hood"

Списки

а

а

b

b

с

сd

keys

Page 18: Доклад "React under the hood"

var blog = articles.map(function(article) { return ( <div key={article.id}> <h1>{article.title}</h1> <p>{article.text}</p> </div> ); })

Page 19: Доклад "React under the hood"

Batching

Page 20: Доклад "React under the hood"

setState()

Page 21: Доклад "React under the hood"
Page 22: Доклад "React under the hood"
Page 23: Доклад "React under the hood"

shouldComponentUpdate(nextProps, nextState) { return this.props.name !== nextProps.name; }

Page 24: Доклад "React under the hood"

shouldComponentUpdate() === false

Page 25: Доклад "React under the hood"

События

Page 26: Доклад "React under the hood"

onClick

onClick

onClick

onClick

onClick

onClick

onClick

onClick

onClick

Делегирование событий

Page 27: Доклад "React under the hood"

Спасибо за внимание!

😊


Recommended