[@naukriengineering] virtual dom

10
Virtual Dom FED | Naukri.com

Upload: naukricom

Post on 23-Jan-2018

336 views

Category:

Engineering


0 download

TRANSCRIPT

Page 1: [@NaukriEngineering] Virtual dom

Virtual DomFED | Naukri.com

Page 2: [@NaukriEngineering] Virtual dom
Page 3: [@NaukriEngineering] Virtual dom

What is Dom?It’s a way of representing a structured document via objects.

The HTML DOM is always tree-structured - which is allowed by the structure of

HTML document.

This is cool because we can traverse trees fairly easily. Unfortunately, easily doesn’t

mean quickly here.

Page 4: [@NaukriEngineering] Virtual dom

ChallengeManual DOM manipulation is messy.

Keeping track of the previous DOM state is tough.

Dom is slow and should be touched minimally and efficiently.

Page 5: [@NaukriEngineering] Virtual dom

What is Virtual Domvirtual-dom is a collection of modules designed to provide a declarative way of

representing the DOM for your app.

It is lightweight and detached from the browser-specific implementation details.

Page 6: [@NaukriEngineering] Virtual dom

HTML to Virtual DOM<div style={{

textAlign: 'center',

lineHeight: (100 + count) + 'px',

border: '1px solid red',

width: (100 + count) + 'px',

height: (100 + count) + 'px'

}}>{count}</div>

Virtual.createElement(

'div',

{ style: {

textAlign: 'center',

lineHeight: 100 + count + 'px',

border: '1px solid red',

width: 100 + count + 'px',

height: 100 + count + 'px'

} },

count

);

Page 7: [@NaukriEngineering] Virtual dom

Process involved

Page 8: [@NaukriEngineering] Virtual dom

Uses cases Virtual DomLet you write HTML as function of state.

Let you create isomorphic apps.

Ensure best practices of DOM reconciliation.

Allows easy dom batching a performance enhancement.

Page 9: [@NaukriEngineering] Virtual dom

Performance bitsVirtual Dom will re-render full app on state change.

Work with immutable data structures.

Keep node hierarchy flat.

Batch actual dom operations.

Do page profiling and check for janks.

Page 10: [@NaukriEngineering] Virtual dom

Thanks