+ All Categories
Home > Software > Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Date post: 08-May-2015
Category:
Upload: moscowjs
View: 736 times
Download: 2 times
Share this document with a friend
37
Пишем "Excel" на AngularJS: 2000 watchers не предел Миша Башкиров, AT Consulting
Transcript
Page 1: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Пишем "Excel" на AngularJS:2000 watchers не пределМиша Башкиров, AT Consulting

Page 2: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

... my measurement is always something about 2,000 bindings per page. So,

if you imagine a complicated page, let’s say it has 100 rows and 20 columns,

then a table would have about 2,000 items on it. That’s pretty much the

limit of what you can show to the user before the user kind of scream and

say, “Hey! This page is ridiculous! You don’t give me back information or do

something to make the page more presentable.”

Miško Hevery, команда AngularJS

“2

Page 3: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Поздним зимним вечеромв одном Enterprise-приложении

> countWatchers()

23659

3

Page 4: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

23 659 watchers!

Page 5: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Как докатились

до жизни такой?

Page 6: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 7: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 8: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 9: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 10: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Красиво!

Но...

Page 11: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 12: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

У нас проблемы:— нажатие клавишы в input-е занимает от секунды до нескольких

— так ли хорош dirty checking? и тот ли framework мы выбрали O_o?

— ng-repeat на ng-repeat'е, ng-repeat'ом погоняет

— медленно работают сумматоры и прочие формулы

— перегружен UI

— ...

12

Page 13: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 14: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Учимся готовить

"черепаху"

Page 15: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 16: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Поверхностный поиск— < 2000 биндингов

— дерегистрируем $watch

— одноразовые биндинги

— bindonce

— angular-once

Уже кое-что...

16

Page 17: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 18: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Быстрые

итераторыpowered by Vanilla JS ;)

Page 20: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 21: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

ng-if

vsng-show

Page 22: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

ng-if "изолирует" биндинги<div ng-if="true">

<input ng-model="model.attribute1">

</div>

<div ng-if="false">

<input ng-model="model.attribute2">

</div>

countWatchers() => 3 ... и каждый раз рендерится с нуля

01.

02.

03.

04.

05.

06.

22

Page 23: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

ng-show нет<div ng-show="true">

<input ng-model="model.attribute1">

</div>

<div ng-show="false">

<input ng-model="model.attribute2">

</div>

countWatchers() => 4 ... зато быстрее рендерится

01.

02.

03.

04.

05.

06.

23

Page 24: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 25: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Нужны ли

мгновенныеобновления?

Page 26: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

"Monkey patch" input + ng-modelappModule.directive 'input', ->

restrict: 'E'

priority: 1

link: ($scope, $element, $attrs) ->

$element.off 'compositionstart compositionend

input change'

Будет обновляться только при потере focus.

01.

02.

03.

04.

05.

26

Page 27: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 28: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

И как оно?

Page 29: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Результаты:— разгрузили UI

— медленные участки кода переписали на Vanilla JS (прости, underscore.js)

— убрали лишние watchers

— изолировали watchers через ng-if

— даже если их много, обновление происходит только при потере focus

— где не помогает техника, ищем способ дополнительно разгрузить UI

29

Page 30: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 31: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Будущее?

Page 32: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Будущее!— ngModelOptions NEW!

самый долгий в истории AngularJS merged pull request

— AngularJS 2.0 Object.observe()

"... 20-40x increase in speed ..."

— AngularDart

32

Page 33: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov
Page 34: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Bonus!

Page 35: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Экспорт HTML-таблиц в Excel<table id="important-excel-report">

<tr>

<td>Я откроюсь в Excel!</td>

</tr>

</table>

+ FileSaver.js

01.

02.

03.

04.

05.

35

Page 36: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

23 659 thanks!

Page 37: Writing "Excel" Using Angular: 2000 Watchers Is Not a Limit by Misha Bashkirov

Пишем "Excel" на AngularJS:2000 watchers не пределМиша Башкиров, AT Consulting

— bashmish.com

[email protected]

Презентация: bashmish.com/pres/ng-excel/

37


Recommended