<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rai Siqueira</title>
    <description>The latest articles on DEV Community by Rai Siqueira (@raisiqueira).</description>
    <link>https://dev.to/raisiqueira</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F40039%2F3d4f65d9-122d-434b-a876-968d4df62697.jpg</url>
      <title>DEV Community: Rai Siqueira</title>
      <link>https://dev.to/raisiqueira</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raisiqueira"/>
    <language>en</language>
    <item>
      <title>Dev vocabulary: What is tree shaking 🌲</title>
      <dc:creator>Rai Siqueira</dc:creator>
      <pubDate>Sun, 17 May 2020 03:43:16 +0000</pubDate>
      <link>https://dev.to/raisiqueira/dev-vocabulary-what-is-tree-shaking-3ap7</link>
      <guid>https://dev.to/raisiqueira/dev-vocabulary-what-is-tree-shaking-3ap7</guid>
      <description>&lt;p&gt;Originally posted on: &lt;a href="https://raisiqueira.dev/blog/2020-05-17-what-is-tree-shaking"&gt;https://raisiqueira.dev/blog/2020-05-17-what-is-tree-shaking&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We are used to using modules in JavaScript (aka &lt;a href="https://nodejs.org/api/esm.html"&gt;esm&lt;/a&gt;)&lt;br&gt;
since &lt;em&gt;ES6&lt;/em&gt; (or &lt;em&gt;ES2015&lt;/em&gt;) ECMAScript modules are the official standard format for packing JavaScript code for reuse. In applications with multiple modules it's constant to have functions, methods, variables and many others pieces of code not used in our apps.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;tree shaking&lt;/em&gt; term in the JavaScript world refers to dead-code elimination from our application, the name became popular with &lt;em&gt;Rollup&lt;/em&gt; — an &lt;em&gt;ES2015&lt;/em&gt; module bundler. Tree shaking is a technique that statically analyzes the code that is imported from some module and during the bundle removes unused codes. This step is very important when we are going to prepare a production build, generating smaller files.&lt;/p&gt;

&lt;p&gt;Tools like &lt;strong&gt;Webpack&lt;/strong&gt; or the &lt;strong&gt;Rollup&lt;/strong&gt; mentioned above detect these codes that are not being used in the application and remove them from the package generated.&lt;/p&gt;
&lt;h2&gt;
  
  
  Nice, but what is actually considered a dead code?
&lt;/h2&gt;

&lt;p&gt;This answer is simple, we will use the &lt;strong&gt;Webpack&lt;/strong&gt; as &lt;em&gt;module bundle&lt;/em&gt; in our exemple, it is the code that Webpack does not see you using around the application, it’ll follow the trail of imports and exports throughout our app, if it finds any imported module that does not being used in the module that imported it, the Webpack will consider it as “dead code”.&lt;/p&gt;

&lt;p&gt;Let’s see an example 😬&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// module-01.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;minus&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// main-module.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;minus&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./module-01&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;main&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the function &lt;em&gt;minus&lt;/em&gt; was not executed in the code, just imported, which means that, this will not be in our final bundle, the same happens with properties of objects that are not used, see the example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// person.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Rai Siqueira&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;birthday&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2 december&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// main.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;person&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./person&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the &lt;em&gt;birthday&lt;/em&gt; property is not accessed, so it will be removed from our final bundle.&lt;/p&gt;

&lt;p&gt;Tree shaking only works with &lt;em&gt;import&lt;/em&gt; and &lt;em&gt;export&lt;/em&gt; syntax, so it doesn’t work with the syntax used in modules of the CommonJS type (using &lt;code&gt;require&lt;/code&gt; syntax). The above examples also apply to dependencies that we download from NPM, a practical example of this is when using &lt;em&gt;Lodash&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lodash/map&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code snippet above will only add the Lodash &lt;code&gt;map&lt;/code&gt; function to our build, not Lodash entirely. Using the tree shaking technique and eliminating dead code can significantly reduce the size of the code we have in our application.&lt;/p&gt;

&lt;p&gt;Another technique that we can use is using the website BundlePhobia, which brings several details of a package published in NPM, such as the subject of this article - tree shaking.&lt;/p&gt;

&lt;p&gt;Example of a package with tree shaking support (note the tree icon below the package name):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6KJjdPTL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raisiqueira.dev/static/d323813bb2f54c38a325aba7e3a0e7bf/29007/bundlephobia01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6KJjdPTL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raisiqueira.dev/static/d323813bb2f54c38a325aba7e3a0e7bf/29007/bundlephobia01.png" alt="Bundlephobia with tree shaking" width="800" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Example of a package without tree shaking support (without the tree icon below the package name):&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--61zuCoif--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raisiqueira.dev/static/f78a9d427c5f2ec9c2c7930ea2150588/29007/bundlephobia02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--61zuCoif--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://raisiqueira.dev/static/f78a9d427c5f2ec9c2c7930ea2150588/29007/bundlephobia02.png" alt="Bundlephobia without tree shaking" width="800" height="603"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can improve the identification of dead code using lint tools, for example ESLint or TSLint. I’ll indicate the &lt;strong&gt;ESLint Plugin unused imports&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://www.npmjs.com/package/eslint-plugin-unused-imports"&gt;eslint-plugin-unused-imports - npm&lt;/a&gt; that will help you to identify unnecessary imports when you are coding.&lt;/p&gt;

&lt;p&gt;Well, I hope I helped you to demystify this term that we hear a lot when we are using modules in JavaScript.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Did you find something wrong in the text? Click on the "&lt;strong&gt;edit on GitHub&lt;/strong&gt;" link after the references. This is my first text in English, all feedback is welcome.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;References:&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking"&gt;https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://webpack.js.org/guides/tree-shaking/"&gt;https://webpack.js.org/guides/tree-shaking/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://nodejs.org/api/esm.html#esm_introduction"&gt;https://nodejs.org/api/esm.html#esm_introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://rollupjs.org/guide/en/"&gt;https://rollupjs.org/guide/en/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bundlephobia.com"&gt;https://bundlephobia.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>webpack</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Debug de componentes Angular com window.ng no Angular 9</title>
      <dc:creator>Rai Siqueira</dc:creator>
      <pubDate>Thu, 26 Dec 2019 23:36:16 +0000</pubDate>
      <link>https://dev.to/raisiqueira/debug-de-componentes-angular-com-window-ng-no-angular-9-3bn2</link>
      <guid>https://dev.to/raisiqueira/debug-de-componentes-angular-com-window-ng-no-angular-9-3bn2</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraisiqueira.dev%2Fimg%2Fcaptura_de_tela_2019-12-23_a_s_21.04.22.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraisiqueira.dev%2Fimg%2Fcaptura_de_tela_2019-12-23_a_s_21.04.22.png" title="console browser" alt="console browser"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Com a versão 9 do Angular prestes a sair, temos algumas novas features que vão nos ajudar a desenvolver nossas aplicações e também a debugar-las de maneira certa, e uma dessas novidades é o objeto global &lt;code&gt;window.ng&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;window.ng&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Com o &lt;code&gt;window.ng&lt;/code&gt; conseguimos ter acesso direto a Diretivas, Componentes entre outras features do Angular direto do console do browser, tudo isso com o Angular 9 e a nova api do &lt;a href="https://angular.io/guide/ivy" rel="noopener noreferrer"&gt;Ivy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Para fazer nosso teste vamos precisar na última &lt;code&gt;RC&lt;/code&gt; do Angular (9.0.0-rc.7 até o momento deste post). Vamos criar um novo projeto com Angular 9:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @angular/cli@next new ng-console
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conhecendo a nova API do &lt;code&gt;window.ng&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Ok, com nosso projeto rodando vamos conhecer como que a api do &lt;code&gt;window.ng&lt;/code&gt; funciona com alguns exemplos, o primeiro e o mais importante é o &lt;code&gt;ng.getComponent()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraisiqueira.dev%2Fimg%2Fangular-component-01.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraisiqueira.dev%2Fimg%2Fangular-component-01.png" title="Angular componente" alt="Angular componente"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Com o nosso componente criado, vamos atualizar o valor do atributo &lt;code&gt;title&lt;/code&gt; do nosso componente, para isso precisamos acessar o &lt;code&gt;HTMLElement&lt;/code&gt; do componente, para isso vamos usar a função do Chrome &lt;code&gt;$(selector)&lt;/code&gt; e armazenar em uma variável, &lt;code&gt;el&lt;/code&gt;. A função &lt;code&gt;ng.getComponent()&lt;/code&gt; recebe um elemento, neste caso vamos usar o elemento que está armazenado na variável &lt;code&gt;el&lt;/code&gt;, com isso já conseguimos atualizar o valor do atributo &lt;em&gt;title&lt;/em&gt; do nosso componente.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// armazena o elemento em uma variável&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// invoca a função getComponent() passando o elemento armazenado&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// atualiza o valor do atributo title do componente&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hey new ng api!!!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// invoca o change detector do Angular&lt;/span&gt;
&lt;span class="nx"&gt;ng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markDirty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Exemplo:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdwc5hkby0%2Fimage%2Fupload%2Fv1577148580%2Frs-blog-posts%2Fng-component-ng-api.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fres.cloudinary.com%2Fdwc5hkby0%2Fimage%2Fupload%2Fv1577148580%2Frs-blog-posts%2Fng-component-ng-api.gif" title="live demo 1" alt="live demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Casos de uso para o &lt;code&gt;ng.getComponent()&lt;/code&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Acessar um service injetado no componente e disparar algum método do mesmo manualmente e acessar os valores via console;&lt;/li&gt;
&lt;li&gt;Fazer um subscribe em algum Observable e emitir o valor também no console;&lt;/li&gt;
&lt;li&gt;Acessar algum método do próprio componente e analisar se o comportamento está como esperado.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;ng.markDirty()&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Você deve ter notado que no final do último exemplo usamos o método &lt;code&gt;markDirty()&lt;/code&gt;. Essa função é importante ao debugar usando o console, ela é responsável por chamar a API de &lt;em&gt;change detector&lt;/em&gt; do Angular e fazer as devidas alterações no componente especificado, mais uma vez vamos usar o nosso exemplo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// armazena o elemento em uma variável&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// invoca a função getComponent() passando o elemento armazenado&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// atualiza o valor do atributo title do componente&lt;/span&gt;
&lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hey new ng api!!!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// invoca o change detector do Angular&lt;/span&gt;
&lt;span class="nx"&gt;ng&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;markDirty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ao invocar o o &lt;code&gt;markDirty()&lt;/code&gt; nos estamos dizendo ao Angular para atualizar o estado do componente, com isso podemos especificar uma instância de algum componente e acionar o &lt;em&gt;change detector&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusão
&lt;/h2&gt;

&lt;p&gt;Com a nova API vamos interagir rapidamente com os componentes e testar as coisas sem precisar ir e voltar entre o editor e o navegador, com isso novas extensões de desenvolvimento podem ser desenvolvidas sobre essas APIs para facilitar ainda mais nossa vida. 🥳&lt;/p&gt;

</description>
      <category>angular</category>
      <category>ivy</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
