GDG DevFest 2017 Seoul 프론트엔드 모던 프레임워크 낱낱히 파헤치기Kenneth Ceyer
GDG DevFest 2017 Seoul
프론트엔드 모던 프레임워크 낱낱히 파헤치기 세션의 발표자료입니다.
이 발표자료에서는 여러분이 항상 궁금해 하신
프론트엔드 프레임워크의 삼총사
Angular, React, VueJS를 다차원적으로 깊이있게 비교하고 각각의 이점과 특화된 기능을 소개하고 있습니다.
이러한 프레임워크를 경험해보지 못한 분들을 위해 프레임워크 별로 특징부터 쉽게 접근하여 설명하기 때문에 경험 불문하고 가볍게 읽어 보실 수 있습니다.
GDG DevFest 2017 Seoul 프론트엔드 모던 프레임워크 낱낱히 파헤치기Kenneth Ceyer
GDG DevFest 2017 Seoul
프론트엔드 모던 프레임워크 낱낱히 파헤치기 세션의 발표자료입니다.
이 발표자료에서는 여러분이 항상 궁금해 하신
프론트엔드 프레임워크의 삼총사
Angular, React, VueJS를 다차원적으로 깊이있게 비교하고 각각의 이점과 특화된 기능을 소개하고 있습니다.
이러한 프레임워크를 경험해보지 못한 분들을 위해 프레임워크 별로 특징부터 쉽게 접근하여 설명하기 때문에 경험 불문하고 가볍게 읽어 보실 수 있습니다.
2. Question
export default {
data () {
return {
isBlue : true
}
},
methods : {
toggleColor () {
this.isBlue = !this.isBlue
}
},
mounted () {
makeItRed( document.querySelector(‘#btn) )
}
}
.btn-red { background: red !important}
.btn-white { background: white}
.btn-blue { background: blue}
function makeItRed (el){
el.classList.add(‘btn-red’);
}
<button id = ”btn”
:class = ”isBlue? ’btn-blue’ : ’btn-white’ ”
@click = ”toggleColor”
>click here</button>
When this component mounted, the background of the button is red
(makeItRed has been called and .btn-red beats .btn-blue by ‘!important’)
If you click the button, what would be the background of button?
4. Dom and Virtual Dom
DOM virtual DOM
해결?문제?
<section class=”section”>
<header class=”header”>
<h1></h1>
</header>
<article>
<div class=”box”></div>
<a href=”#”></a>
….
</article>
</section>
{
tag: ‘section’,
data: { class: ‘section’ },
children: [
{ tag: ’header’, …,
data: { class: ‘header’}
children: [ {tag: ’h1’...} ]
},
{ tag: ‘article’, … }
…..
}
document와 document 내부의 태그에 대한 정의와 api를
규격화 한 모델. 기존 BOM(Browser object model)의
크로스 브라우징이 어려워 w3c에서 권고됨.
DOM을 본따 만든 javascript object.
메모리상에 있어 생성과 수정, 삭제가 빠름. Dom 처럼
트리구조를 가짐
5. Virtual Dom is faster than Dom, so?
Real Dom?
Virtual Dom?
6. Virtual Dom prevents bad performance
bad performance?
virtual dom도 결국 dom에 patch가 되어야 하니 DOM을 직접
제어하는 코드보다 빠를수 없다.
DOM을 필요없이 읽거나 또는 잘못된 순서로 처리 되면
bad performance를 야기시킴
redux의 창시자 Dan Abramov
7. Virtual Dom prevents bad performance
chrome > 개발자 도구 >console drawer> rendering > paint flashing 체크
Green => reflow, repaint
DOM의 업데이트 내용을 다시 브라우저에 표시하기 위해
다시 layout을 계산하고 그리는 작업(reflow, repaint)이 발생,
변경된 DOM뿐 아니라 근처의 DOM과 node tree의 DOM
까지 영향을 주기 때문에 필요하지 않은 과정이 반복된다면
performance에 악영향을 줌
이런 layout 재작업은 DOM의 속성을 읽을 때도 발생
나도
다시
그려줘~
넌 관계도 없는데
왜?
8. Changing one DOM leads to..
Dom is Fast!
B.U.T
Reflow, Repaint aren’t
how many…;;;
10. Other Benefits
$('.img').mouseover(function(e){
if (err ) {
$('.tranvel-msg').text(err)
.show();
}
}).mouseout(function(e){
$('.tranvel-msg').hide();
})
<img src="img.png" class="img"
@mouseover="show = error && true"
@mouseout="show = false">
<div class='travel-msg'
v-show="show">{{{error}}}</div>
jQuery Vue
1. DOM과 유사한 형태로 쓰기 때문에 가독성 증가
2. 쉬운 유지 보수 확장
3. DOM의 정적인 attrs 를 functional 하게 만들어줌
21. Rendering example(https://kellywoo.github.io/vnode/ -2.render)
숫자가 렌더링 템플릿에 더해짐숫자가 렌더링 템플릿에 없음
show Numbers: trueshow Numbers : false
아무리 버튼을 클릭해도 숫자 증가 없음
각 숫자는 해당 컴포넌트가 새로운 virtual dom을 생성할때 마다(render function 호출 때 마다) 1씩 증가
버튼 클릭시 child component만 1씩 증가,
자식 컴포넌트인 grand-child 는 변경없음
click click4
23. keep-alive example(https://kellywoo.github.io/vnode/ -3.vnode)
case: false
버튼에 빨간색이 적용이
사라짐
버튼에 빨간색이 적용이
그대로임
case: true
❋console에 vueconsole()을 입력, parent
component.$children 항목을 볼 수 있습니다.
-keep-alive: false
child destroy hook이 발생되며
component가 제거되어 create을 누르면 다시
component가 생성, element도 재생성되며
기존에 있던 .btn-red 클래스는 사라짐.
vueconsole() => (2) [a, a]
-keep-alive: true
child deactivate hook이 발생,
자식 컴포넌트가 그대로 남아있어,create을
눌렀을 때 별도의 data 변경이 없다면
render 함수가 실행되지 않아 이전의 $el을
그대로 보여줌
vueconsole() => (3) [a, a, a]
24. Answer : white
export default {
data () {
return {
isBlue : true
}
},
methods : {
toggleColor () {
this.isBlue = !this.isBlue
}
},
mounted () {
makeItRed( document.querySelector(‘#btn) )
}
}
.btn-red { background: red !important}
.btn-white { background: white}
.btn-blue { background: blue}
function makeItRed (el){
el.classList.add(‘btn-red’);
}
<button id = ”btn”
:class = ”isBlue? ’btn-blue’ : ’btn-white’ ”
@click = ”toggleColor”
>click here</button>
When this component mounted, the background of the button is red
(makeItRed has been called and .btn-red beats .btn-blue by ‘!important’)
If you click the button, what would be the background of button?
25. Again, Patch function doesn’t care the element’s state
OLD VNode NEW VNode
patch 함수 내부에선 old vnode와 new vnode 만 비교,
class 영역의 diff 발견 => element의 class 업데이트
이때 vnode와 연결되지 않은 .btn-red 클래스는 사라집니다.
Virtual Dom은 자신에게 알려지지 않은 속성들에 대해서는 책임지지 않습니다.
확인을 위해 하늘색 버튼 더블 클릭
26. nonetheless, vue is Javascript.
결과를 아는 것 보다, 왜 그렇게 되는 것인지 이해하는 것이
vue를 더 잘 쓸 수 있는 방법