[@naukriengineering] virtual dom

Post on 23-Jan-2018

336 Views

Category:

Engineering

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Virtual DomFED | Naukri.com

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.

ChallengeManual DOM manipulation is messy.

Keeping track of the previous DOM state is tough.

Dom is slow and should be touched minimally and efficiently.

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.

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

);

Process involved

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.

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.

Thanks

top related