{"id":199,"date":"2021-01-24T09:32:06","date_gmt":"2021-01-24T09:32:06","guid":{"rendered":"http:\/\/santosh-shah.com\/?p=199"},"modified":"2021-02-15T06:02:05","modified_gmt":"2021-02-15T06:02:05","slug":"incremental-dom-with-ivy-in-angular","status":"publish","type":"post","link":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/","title":{"rendered":"Incremental DOM with IVY in Angular"},"content":{"rendered":"\n<p>Incremental DOM is used internally at Google, and it is defined by this key idea:<\/p>\n\n\n\n<p><em>Every component gets compiled into a series of instructions. These instructions create DOM trees and update them in-place when the data changes.<\/em><\/p>\n\n\n\n<p>For instance, the following component:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Component({\n  selector: 'todos-cmp',\n  template: `\n    &lt;div *ngFor=\"let t of todos|async\">\n        {{t.description}}\n    &lt;\/div>\n  `\n})\nclass TodosComponent {\n  todos: Observable&lt;Todo&#91;]> = this.store.pipe(select('todos'));\n  constructor(private store: Store&lt;AppState>) {}\n}<\/code><\/pre>\n\n\n\n<p>Will be compiled into:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var TodosComponent = \/** @class *\/ (function () {\n  function TodosComponent(store) {\n    this.store = store;\n    this.todos = this.store.pipe(select('todos'));\n  }\n\n  TodosComponent.ngComponentDef = defineComponent({\n    type: TodosComponent,\n    selectors: &#91;&#91;\"todos-cmp\"]],\n    factory: function TodosComponent_Factory(t) {\n      return new (t || TodosComponent)(directiveInject(Store));\n    },\n    consts: 2,\n    vars: 3,\n    template: function TodosComponent_Template(rf, ctx) {\n      if (rf &amp; 1) { \/\/ create dom\n        pipe(1, \"async\");\n        template(0, TodosComponent_div_Template_0, 2, 1, null, _c0);\n      } if (rf &amp; 2) { \/\/ update dom\n        elementProperty(0, \"ngForOf\", bind(pipeBind1(1, 1, ctx.todos)));\n      }\n    },\n    encapsulation: 2\n  });\n\n  return TodosComponent;\n}());<\/code><\/pre>\n\n\n\n<p>The template function contains the instructions rendering and updating the DOM. Note that the instructions aren\u2019t interpreted by the framework\u2019s rendering engine.\u00a0<strong>They are the rendering engine.<\/strong><\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"dc38\">Why Incremental DOM<\/h1>\n\n\n\n<p>Why did the Google team go with incremental DOM instead of virtual DOM?<\/p>\n\n\n\n<p><strong>They have one goal in mind: applications have to perform well on mobile devices. This mainly meant optimizing two things: the bundle size and the memory footprint.<\/strong><\/p>\n\n\n\n<p>To achieve the two goals:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The rendering engine itself has to be tree shakable<\/li><li>The rendering engine has to have low memory footprint<\/li><\/ul>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"3d00\">Why Incremental DOM is Tree Shakable?<\/h1>\n\n\n\n<p>When using incremental DOM, the framework does not interpret the component. Instead, the component references instructions. If it doesn\u2019t reference a particular instruction, it will never be used. And since we know this at compile time, we can omit the unused instruction from the bundle.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Incremental DOM is used internally at Google, and it is defined by this key idea: Every component gets compiled into a series of instructions. These instructions create DOM trees and update them in-place when the data changes. For instance, the following component: Will be compiled into: The template function contains the instructions rendering and updating [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-199","post","type-post","status-publish","format-standard","hentry","category-angular"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Incremental DOM with IVY in Angular - Santosh Kumar Shah<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Incremental DOM with IVY in Angular - Santosh Kumar Shah\" \/>\n<meta property=\"og:description\" content=\"Incremental DOM is used internally at Google, and it is defined by this key idea: Every component gets compiled into a series of instructions. These instructions create DOM trees and update them in-place when the data changes. For instance, the following component: Will be compiled into: The template function contains the instructions rendering and updating [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/\" \/>\n<meta property=\"og:site_name\" content=\"Santosh Kumar Shah\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-24T09:32:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-15T06:02:05+00:00\" \/>\n<meta name=\"author\" content=\"Santosh Kumar Shah\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Santosh Kumar Shah\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/\",\"url\":\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/\",\"name\":\"Incremental DOM with IVY in Angular - Santosh Kumar Shah\",\"isPartOf\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\"},\"datePublished\":\"2021-01-24T09:32:06+00:00\",\"dateModified\":\"2021-02-15T06:02:05+00:00\",\"author\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\"},\"breadcrumb\":{\"@id\":\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/santosh-shah.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Incremental DOM with IVY in Angular\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#website\",\"url\":\"https:\/\/santosh-shah.com\/blog\/\",\"name\":\"Santosh Kumar Shah\",\"description\":\"JavaScript Developer\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f\",\"name\":\"Santosh Kumar Shah\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g\",\"caption\":\"Santosh Kumar Shah\"},\"description\":\"I am JavaScript developer.\",\"sameAs\":[\"https:\/\/santosh-shah.com\/blog\"],\"url\":\"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Incremental DOM with IVY in Angular - Santosh Kumar Shah","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/","og_locale":"en_US","og_type":"article","og_title":"Incremental DOM with IVY in Angular - Santosh Kumar Shah","og_description":"Incremental DOM is used internally at Google, and it is defined by this key idea: Every component gets compiled into a series of instructions. These instructions create DOM trees and update them in-place when the data changes. For instance, the following component: Will be compiled into: The template function contains the instructions rendering and updating [&hellip;]","og_url":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/","og_site_name":"Santosh Kumar Shah","article_published_time":"2021-01-24T09:32:06+00:00","article_modified_time":"2021-02-15T06:02:05+00:00","author":"Santosh Kumar Shah","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Santosh Kumar Shah","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/","url":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/","name":"Incremental DOM with IVY in Angular - Santosh Kumar Shah","isPartOf":{"@id":"https:\/\/santosh-shah.com\/blog\/#website"},"datePublished":"2021-01-24T09:32:06+00:00","dateModified":"2021-02-15T06:02:05+00:00","author":{"@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f"},"breadcrumb":{"@id":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/santosh-shah.com\/blog\/incremental-dom-with-ivy-in-angular\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/santosh-shah.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Incremental DOM with IVY in Angular"}]},{"@type":"WebSite","@id":"https:\/\/santosh-shah.com\/blog\/#website","url":"https:\/\/santosh-shah.com\/blog\/","name":"Santosh Kumar Shah","description":"JavaScript Developer","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/santosh-shah.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/b17cb45bdd5f518e74a08ad2c6c4b39f","name":"Santosh Kumar Shah","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/santosh-shah.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf46c57219d897547f3204b6b302169b3302b17507ccc902946b622a78d0b98b?s=96&d=mm&r=g","caption":"Santosh Kumar Shah"},"description":"I am JavaScript developer.","sameAs":["https:\/\/santosh-shah.com\/blog"],"url":"https:\/\/santosh-shah.com\/blog\/author\/sks7yu\/"}]}},"_links":{"self":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/199","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/comments?post=199"}],"version-history":[{"count":1,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/199\/revisions"}],"predecessor-version":[{"id":233,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/posts\/199\/revisions\/233"}],"wp:attachment":[{"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/media?parent=199"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/categories?post=199"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/santosh-shah.com\/blog\/wp-json\/wp\/v2\/tags?post=199"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}