<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Siwat Kaolueng on Medium]]></title>
        <description><![CDATA[Stories by Siwat Kaolueng on Medium]]></description>
        <link>https://medium.com/@perjerz?source=rss-6bc0d1386272------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*G9F4bktVCKjfftNndY3dfw.jpeg</url>
            <title>Stories by Siwat Kaolueng on Medium</title>
            <link>https://medium.com/@perjerz?source=rss-6bc0d1386272------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 21:37:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@perjerz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Shifting Left— Our Storybook-First UI, Page-level Tests, MSW and the Storybook Test Harness]]></title>
            <link>https://perjerz.medium.com/shifting-left-our-storybook-first-ui-page-level-tests-msw-and-the-storybook-test-harness-e0fdf4b75c5f?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0fdf4b75c5f</guid>
            <category><![CDATA[earnin]]></category>
            <category><![CDATA[storybook]]></category>
            <category><![CDATA[snapshot-testing]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Sat, 17 Jan 2026 18:04:36 GMT</pubDate>
            <atom:updated>2026-01-18T05:36:07.416Z</atom:updated>
            <content:encoded><![CDATA[<p>In my team, we shifted left on quality by treating <strong>Storybook</strong> as the canonical environment for UI development and <strong>page-level testing</strong>. Our team builds <strong>pages and route components inside Storybook</strong>, runs page-level tests there (interaction tests, scoped snapshots and analytics contracts), and relies on <strong>MSW scenarios</strong> for deterministic, realistic network behavior. This approach gives our team fast, reliable feedback during feature development and code review.</p><h3>The problem we solved</h3><p>Large UIs with many conditional states and multiple backend surfaces are expensive to validate with traditional end-to-end (E2E) tests. E2E suites are:</p><ul><li>slow to run,</li><li>brittle (lots of external wiring),</li><li>expensive to maintain for many edge cases.</li></ul><p>We needed a testing layer that is:</p><ul><li>fast enough to run on every pull request,</li><li>realistic enough to catch browser/runtime issues,</li><li>expressive enough to model page state without booting the entire system.</li></ul><p>We solved this by <strong>starting UI development in Storybook</strong> and making Storybook the canonical test harness for <strong>page-level</strong> verification. For our team a “page” (the route component) is the unit we exercise in Storybook — not only tiny presentational components.</p><h3>Storybook as our test harness (overview)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0fO2vzxq9sBevAO11BmjZQ.png" /><figcaption>How our team uses Storybook + MSW scenarios + a shared decorator runtime to run page-level play tests, including analytics and webview behaviors.</figcaption></figure><p>We treat Storybook not just as a gallery, but as the environment where we:</p><ul><li>compose a page’s runtime (API contexts, query client, router, feature flags, permissions, analytics),</li><li>mount realistic MSW scenarios for network responses,</li><li>run page-level tests in a browser runtime using Storybook Test Runner (play)</li><li>assert both DOM outcomes and analytics / bridge contracts.</li></ul><p>At the top level we initialize MSW and register a small sb helper for module mocks so that every story is deterministic and reproducible in CI. This is how our team gets fast, actionable feedback.</p><h3>Chromatic: hosted review + visual regression for our Storybook pages</h3><p>Chromatic is how our team turns Storybook into a PR-friendly workflow. We publish Storybook to Chromatic so anyone reviewing can open the hosted environment and validate changes in the exact states we model (happy path, loading, error, edge cases). Chromatic’s visual regression checks add a second layer of protection: when a layout or styling change slips in unintentionally, we see it immediately as part of the same PR feedback loop.</p><p>When a story is meant to test contracts rather than visuals (for example, analytics-only stories), we can explicitly disable visual snapshots to reduce noise:</p><pre>export default {<br>  // ...<br>  parameters: {<br>    chromatic: { disableSnapshot: true },<br>  },<br>}</pre><h3>Preview: Storybook bootstrapping (MSW + sb)</h3><pre>// .storybook/preview.ts<br>import { type Preview } from &#39;@storybook/react&#39;<br>import { initialize, mswLoader } from &#39;msw-storybook-addon&#39;<br>import { sb } from &#39;./storybook-test-utils&#39; // small helper in our repo<br><br>const preview: Preview = {<br>  parameters: {<br>    layout: &#39;fullscreen&#39;,<br>    options: { storySort: { order: [&#39;web&#39;, &#39;design system&#39;, &#39;*&#39;] } },<br>  },<br>  loaders: [mswLoader],<br>  decorators: [],<br>  beforeAll: async () =&gt; {<br>    // MSW: bypass unhandled requests in the test environment<br>    initialize({ onUnhandledRequest: &#39;bypass&#39; })<br>  },<br>}<br>// Convenience: automock a helper module for stories<br>sb.mock(() =&gt; import(&#39;@/shared/utils/document-helpers&#39;))<br>export default preview</pre><p><strong>Notes from our team</strong></p><ul><li>mswLoader wires story rendering to story-scoped MSW handlers.</li><li>initialize() configures MSW for the Storybook test environment.</li><li>sb.mock(...) is our small helper to automock modules across stories and keep tests deterministic.</li></ul><h3>The mock provider pattern we use</h3><p>Pages in our product expect many providers. We centralize that glue into composable decorators so stories remain concise and consistent.</p><h3>routerDecorator — compose runtime for route/page stories</h3><pre>// libs/web-lib/src/utils/route-stories/routerDecorator.tsx<br>import { Decorator } from &#39;@storybook/react&#39;<br>import { QueryClient, QueryClientProvider } from &#39;@tanstack/react-query&#39;<br>import { MemoryRouter, Route, Routes } from &#39;react-router-dom&#39;<br>import { ApiContext } from &#39;@/contexts/ApiContext&#39;<br>import { WebAppBackendAPIContext } from &#39;@/contexts/WebAppBackendAPIContext&#39;<br>import { AnalyticsWrapperProvider } from &#39;@/analytics&#39;<br>import { OptimizelyProvider } from &#39;@optimizely/react-sdk&#39;<br><br>// Example mock base URLs<br>const MOCK_CORE_API = &#39;https://mock-core.local&#39;<br>const MOCK_AUX_API = &#39;https://mock-aux.local&#39;<br>export function routerDecorator({<br>  path,<br>  initialEntry,<br>  mockAnalytics,<br>  permissions,<br>}: {<br>  path: string<br>  initialEntry: string<br>  mockAnalytics?: AnalyticsType<br>  permissions?: Permission[]<br>}): Decorator {<br>  return (Story) =&gt; {<br>    const queryClient = new QueryClient({ defaultOptions: { queries: { retry: 0 } } })<br>    // Use injected analytics or a lightweight noop fallback<br>    const analyticsProvider = mockAnalytics ?? { sendEvent: (evt) =&gt; console.debug(&#39;analytics&#39;, evt) }<br>    return (<br>      &lt;AnalyticsWrapperProvider value={analyticsProvider}&gt;<br>        &lt;OptimizelyProvider optimizely={/* a minimal instance or mock */ undefined }&gt;<br>          &lt;ApiContext.Provider value={{ baseUrl: MOCK_CORE_API }}&gt;<br>            &lt;WebAppBackendAPIContext.Provider value={{ baseUrl: MOCK_AUX_API }}&gt;<br>              &lt;QueryClientProvider client={queryClient}&gt;<br>                &lt;MemoryRouter initialEntries={[initialEntry]}&gt;<br>                  &lt;Routes&gt;<br>                    &lt;Route path={path} element={&lt;Story /&gt;} /&gt;<br>                  &lt;/Routes&gt;<br>                &lt;/MemoryRouter&gt;<br>              &lt;/QueryClientProvider&gt;<br>            &lt;/WebAppBackendAPIContext.Provider&gt;<br>          &lt;/ApiContext.Provider&gt;<br>        &lt;/OptimizelyProvider&gt;<br>      &lt;/AnalyticsWrapperProvider&gt;<br>    )<br>  }</pre><p><strong>Why our team chose this</strong></p><ul><li>We mount the page at the exact route it expects (including route params).</li><li>We provide API contexts with mock base URLs so pages talk to MSW handlers rather than real services.</li><li>We inject mockAnalytics so stories can assert events reliably.</li></ul><h3>defaultDecorators and smaller utility decorators</h3><pre>// libs/webview-lib/src/utils/storybook/decorators.tsx<br>import { action } from &#39;storybook/actions&#39;<br>import { AnalyticsWrapperProvider } from &#39;@/analytics&#39;<br><br>// Analytics decorator<br>export function analyticsDecorator(mockAnalytics?: { sendEvent: Function }) {<br>  const analytics = mockAnalytics ?? { sendEvent: action(&#39;sendAnalytics&#39;) }<br>  return (Story) =&gt; &lt;AnalyticsWrapperProvider value={analytics}&gt;&lt;Story/&gt;&lt;/AnalyticsWrapperProvider&gt;<br>}<br>// Open external link provider for webview stories<br>export function OpenExternalURLProviderStorybook({ children, overrideOnClick }) {<br>  const getExternalLinkProps = (url) =&gt; ({<br>    href: url,<br>    onClick: (e) =&gt; {<br>      e.preventDefault()<br>      if (overrideOnClick) overrideOnClick(url)<br>      else action(&#39;open-external-url&#39;)(url)<br>    },<br>  })<br>  return &lt;OpenExternalURLContext.Provider value={{ getExternalLinkProps }}&gt;{children}&lt;/OpenExternalURLContext.Provider&gt;<br>}<br>// Combined default decorators used by our team<br>export function defaultDecorators(params = {}) {<br>  return [<br>    appEventsDecorator(),   // no-op app events by default<br>    apiDecorator(),<br>    analyticsDecorator(params.overrideAnalytics),<br>    openExternalURLDecorator(),<br>    routerDecorator({ path: params.overrideRouterPath ?? &#39;/&#39;, initialEntry: params.overrideRouterPath ?? &#39;/&#39; }),<br>    workContextDecorator(),<br>  ]<br>}</pre><p><strong>Benefit for </strong>defaultDecorators</p><ul><li>Stories are concise and uniform: each story imports defaultDecorators() and supplies an MSW scenario.</li><li>The decorator composition is the single source of runtime glue for page stories in our repo.</li></ul><h3>MSW scenarios &amp; baseScenario</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wAcoSKT4UiEcrQA_B0-ztA.png" /><figcaption>Our MSW pattern: a shared baseScenario() provides common handlers, and each story adds focused overrides for edge cases.</figcaption></figure><p>We group MSW handlers into <strong>scenarios</strong>. Our team maintains a baseScenario that implements the common endpoints every page expects.</p><pre>// libs/mocks/src/scenarios/base.ts<br>import { create } from &#39;../scenarios&#39;<br><br>export const baseScenario = create(({ core, aux }) =&gt; [<br>  // bootstrap/init endpoint<br>  core.post(&#39;/api/ui/bootstrap&#39;, ({ response }) =&gt;<br>    response(200).json({ session: { id: &#39;mock-session&#39; }, config: { features: [] } })<br>  ),<br>  // basic user/org info<br>  core.get(&#39;/api/users/me/orgs&#39;, ({ response }) =&gt;<br>    response(200).json({ orgs: [{ id: &#39;org-1&#39;, name: &#39;Mock Org&#39; }] })<br>  ),<br>  // paychecks list for a given user<br>  core.get(&#39;/api/svc/:svcId/orgs/:orgId/users/:userId/paychecks&#39;, ({ params, response }) =&gt;<br>    response(200).json({ paychecks: generatePaychecks(params) })<br>  ),<br>  // detailed paycheck retrieval<br>  core.get(&#39;/api/svc/:svcId/orgs/:orgId/users/:userId/paychecks/:paycheckId&#39;, ({ params, response }) =&gt;<br>    response(200).json({ paycheck: findPaycheck(params) })<br>  ),<br>  // auxiliary endpoints (direct deposit / time off)<br>  core.get(&#39;/api/svc/:svcId/orgs/:orgId/users/:userId/direct-deposits&#39;, ({ response }) =&gt;<br>    response(200).json({ accounts: [ /* ... */ ] })<br>  ),<br>])</pre><p><strong>How this helps our team</strong></p><ul><li>baseScenario() is our realistic baseline for pages.</li><li>For specific stories we prepend or append small handler overrides (errors, latency, special data), keeping story-specific mocks short and reviewable.</li></ul><h3>Analytics contract testing</h3><p>We treat analytics as a contract and validate it in Storybook stories. We inject an analytics spy at the provider level and assert events from play.</p><h3>Analytics decorator (context)</h3><pre>export function analyticsDecorator(mockAnalytics?: { sendEvent: Function }) {<br>  const analytics = mockAnalytics ?? { sendEvent: action(&#39;sendAnalytics&#39;) }<br>  return (Story) =&gt; &lt;AnalyticsWrapperProvider value={analytics}&gt;&lt;Story/&gt;&lt;/AnalyticsWrapperProvider&gt;<br>}</pre><h3>Example page story we use</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_yLwway6ped5l8E4t9DeBw.png" /><figcaption>Anatomy of a page story: meta + decorators define runtime, MSW defines data state, play validates UI behavior and analytics.</figcaption></figure><pre>// Web/WorkProfile/Analytics/StateElectionsAnalytics.stories.tsx<br>import { expect, fn, userEvent } from &#39;storybook/test&#39;<br>import { baseScenario } from &#39;@/mocks/scenarios/base&#39;<br>import { routerDecorator } from &#39;@/utils/route-stories/routerDecorator&#39;<br>import { StateElections } from &#39;./StateElections&#39;<br>// mock analytics spy used by our tests<br>const mockAnalytics = { sendEvent: fn() }<br>export default {<br>  title: &#39;Web/WorkProfile/Analytics/StateElectionsAnalytics&#39;,<br>  component: StateElections,<br>  decorators: [<br>    routerDecorator({<br>      // route: keep param shape but avoid obvious internal names<br>      path: &#39;/work/:workRef/profile/settings/state/:stateId&#39;,<br>      initialEntry: &#39;/work/w-1/profile/settings/state-s1&#39;,<br>      mockAnalytics,<br>    }),<br>  ],<br>  parameters: {<br>    msw: {<br>      handlers: baseScenario(),<br>    },<br>  },<br>}<br>export const ViewScreen = {<br>  play: async ({ canvas }) =&gt; {<br>    // wait for the page to settle<br>    await canvas.findByTestId(&#39;edit-my-elections-button&#39;)<br>    expect(mockAnalytics.sendEvent).toHaveBeenCalledWith({<br>      type: &#39;ViewScreen&#39;,<br>      screenName: &#39;StateElections&#39;,<br>    })<br>  },<br>}<br>export const InteractEditMyElections = {<br>  play: async ({ canvas }) =&gt; {<br>    const editBtn = await canvas.findByTestId(&#39;edit-my-elections-button&#39;)<br>    mockAnalytics.sendEvent.mockClear()<br>    await userEvent.click(editBtn)<br>    expect(mockAnalytics.sendEvent).toHaveBeenCalledWith({<br>      type: &#39;UserInteractedWithElement&#39;,<br>      screenName: &#39;StateElections&#39;,<br>      elementName: &#39;EditMyElections&#39;,<br>      component: &#39;Button&#39;,<br>    })<br>  },<br>}</pre><p><strong>Guidance from our team</strong></p><ul><li>Assert event names and the critical properties downstream systems rely on.</li><li>Avoid asserting volatile fields (timestamps, generated IDs).</li><li>Keep the play function focused: one behavioral contract per story.</li></ul><h3>Webview analytics &amp; open external links</h3><p>For pages that run inside a webview we validate bridge messages and external-link behavior. We provide a testable OpenExternalURLProvider and an appEventsDecorator we override in stories when needed.</p><pre>// libs/my-lib/src/storybook/OpenExternalURLProviderStorybook.tsx<br>export function OpenExternalURLProviderStorybook({ children, overrideOnClick }) {<br>  const getExternalLinkProps = (url) =&gt; ({<br>    href: url,<br>    onClick: (e) =&gt; {<br>      e.preventDefault()<br>      if (overrideOnClick) overrideOnClick(url)<br>      else action(&#39;open-external-url&#39;)(url)<br>    },<br>  })<br>  return &lt;OpenExternalURLContext.Provider value={{ getExternalLinkProps }}&gt;{children}&lt;/OpenExternalURLContext.Provider&gt;<br>}</pre><p>When we need to assert bridge messages we override the app events provider with a spy that records messages and assert them in the story play.</p><h3>Page-level testing rules we follow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJx4I06GQUXmMITyB1wOpQ.png" /><figcaption>Our test mix: keep E2E for critical journeys, rely heavily on Storybook page tests for UI behavior + analytics contracts, and use unit tests for pure logic.</figcaption></figure><ul><li><strong>We test pages, not tiny presentational components.</strong> Pages (route components) are the unit our team builds and ships.</li><li><strong>One behavioral contract per story.</strong> Keep stories named View, InteractX, ErrorCase.</li><li><strong>Scoped snapshots only.</strong> Snapshot meaningful containers instead of entire pages.</li><li><strong>Normalize analytics/bridge values</strong> in tests — assert the properties downstream systems depend on, not volatile fields.</li><li><strong>Keep </strong><strong>baseScenario stable</strong> and small; scenario overrides should be focused.</li></ul><h3>Closing</h3><p>This Storybook-first, page-level testing approach has given our team faster feedback, more deterministic tests, and clearer artifacts for code review (stories are living documentation + tests). The important elements that made it practical for us are:</p><ul><li><strong>Start UI development in Storybook</strong> and treat route components (pages) as the unit of development.</li><li><strong>Compose a single runtime via decorators</strong> so stories remain concise and consistent across our repo.</li><li><strong>Drive pages with MSW scenarios</strong> — baseScenario() for common endpoints and focused overrides per story.</li><li><strong>Inject analytics and bridge spies</strong> at the provider level and assert the contract from play functions.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0fdf4b75c5f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Power of Defaults (Settings)]]></title>
            <link>https://perjerz.medium.com/power-of-defaults-settings-14cc97aa7d79?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/14cc97aa7d79</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[default]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Mon, 03 Mar 2025 13:49:41 GMT</pubDate>
            <atom:updated>2025-03-03T14:00:53.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIiQ71LJjEIFoitKrhS27g.png" /><figcaption>Generated by ChatGPT 4o</figcaption></figure><p>ผมเห็น Tweets ของโปรแกรมเมอร์ท่านนึงที่ผมนับถือ</p><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/victorsavkin/status/1684667459973099522&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/c38cd0174d0646dbf3282b83cb79f30b/href">https://medium.com/media/c38cd0174d0646dbf3282b83cb79f30b/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/victorsavkin/status/1684667465111121921&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d9a6456c09a012959b4d029a8360e9e/href">https://medium.com/media/4d9a6456c09a012959b4d029a8360e9e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=twitter&amp;url=https%3A//x.com/victorsavkin/status/1684667470379167744&amp;image=" width="500" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/09aa50d3495acc0ae4d2b1944cbb0075/href">https://medium.com/media/09aa50d3495acc0ae4d2b1944cbb0075/href</a></iframe><p>ซึ่งเป็นสิ่งที่ผมเชื่อมานานแล้วแต่อยากให้ <strong>AI มาเขียนสรุปไว้อีกรอบ</strong></p><p><strong>Power of Default Settings</strong>: บทเรียนจาก Victor Savkin และตัวอย่างที่ใช้ได้จริง</p><p>ในโลกของการพัฒนาซอฟต์แวร์และเทคโนโลยี การปรับแต่ง (customization) กลายเป็นสิ่งที่หลายคนหลงใหล ไม่ว่าจะเป็นการปรับแต่งคีย์บอร์ดให้เหมาะกับทุกแอปพลิเคชัน หรือการตั้งค่าหน้าจอให้มีธีมสีเฉพาะตัว แต่ Victor Savkin ผู้มีชื่อเสียงในชุมชน Angular และผู้ร่วมก่อตั้ง Nrwl.io ได้จุดประกายมุมมองที่น่าสนใจผ่านโพสต์บน X (<a href="https://medium.com/victorsavkin/status/1684667457343270918">ลิงก์โพสต์</a>) ว่า Default Settings อาจเป็นเครื่องมือทรงพลังที่ช่วยเพิ่มประสิทธิภาพและลดความซับซ้อนในระยะยาว บทความนี้จะสำรวจแนวคิดของเขา พร้อมยกตัวอย่างการประยุกต์ใช้ เช่น การใช้คำสั่ง Git แบบเต็มแทนการตั้ง Alias และการใช้ Default Preset Design System ของ Tailwind CSS เพื่อให้ AI สามารถ Generate UI พร้อมใช้งานได้เลย</p><p><strong>Lessons from Victor Savkin: เหตุผลที่ Default Settings มีพลัง</strong></p><p>Victor Savkin เล่าถึงประสบการณ์ของเขาในโพสต์บน X ว่า เขาเคยเป็น “นักปรับแต่งขั้นสุด” ที่ใช้เวลาหลายชั่วโมงไปกับการปรับแต่งสภาพแวดล้อมการทำงาน เช่น การใช้คีย์บอร์ด ErgoDox ที่มีเลเยอร์สำหรับทุกแอป หรือการปรับแต่งโปรแกรมแก้ไขให้มีธีมสีเฉพาะตัว แต่จุดเปลี่ยนเกิดขึ้นเมื่อเขาเป็นพ่อและมีเวลาน้อยลง เขาค้นพบว่าการใช้ Default Settings เช่น การเปลี่ยนจาก Linux มาใช้ macOS หรือใช้ Apple Notes แทนการจดบันทึกที่ซับซ้อน ช่วยให้เขาทำงานได้มีประสิทธิภาพมากขึ้นและรู้สึกดีขึ้นโดยรวม</p><p>เขายังสะท้อนว่า การปรับแต่งมากเกินไปมักเชื่อมโยงกับ “อัตลักษณ์ส่วนตัว” มากกว่าประสิทธิภาพที่แท้จริง ซึ่งคล้ายกับแฟชั่นที่ดูดีแต่ไม่จำเป็นต้องใช้งานได้ดีขึ้น คำแนะนำจากเพื่อนร่วมงานรุ่นใหญ่ของเขา ที่ชื่อ Sasha ว่า “Default Settings อาจไม่สมบูรณ์แบบ แต่เพียงพอและช่วยประหยัดเวลาในระยะยาว” กลายเป็นจริงเมื่อ Savkin ต้องเผชิญกับข้อจำกัดด้านเวลา</p><p><strong>Power of Default Settings ในทางปฏิบัติ</strong></p><p>แนวคิดนี้ไม่ได้จำกัดอยู่แค่เรื่องส่วนตัวของ Savkin เท่านั้น แต่สามารถนำไปใช้กับการพัฒนาซอฟต์แวร์และการออกแบบได้อย่างกว้างขวาง ลองดูตัวอย่างสองกรณีที่แสดงให้เห็นถึงพลังของ Default Settings:</p><p><strong>1. Full Git Commands แทน Alias</strong></p><p>ในวงการพัฒนาซอฟต์แวร์ นักพัฒนาหลายคนชอบตั้ง Alias ให้กับคำสั่ง Git เพื่อความรวดเร็ว เช่น ตั้ง ga แทน git add หรือ gc แทน git commit แม้ว่าจะช่วยประหยัดเวลาให้คนที่ตั้งค่าได้ แต่ก็มีข้อเสียสำคัญ: คนใหม่ในทีมต้องเรียนรู้ Alias เหล่านี้อีกครั้ง หากทีมใช้คำสั่ง Git แบบเต็ม เช่น git add . หรือ git commit -m “message” ทุกคนจะเข้าใจได้ทันทีโดยไม่ต้องเสียเวลาถอดรหัส Alias ของคนอื่น</p><p>ตัวอย่างเช่น หากคุณใช้ git push origin main แทน Alias ที่กำหนดเองอย่าง gpom นักพัฒนาคนใหม่หรือสมาชิกทีมที่เพิ่งเข้ามาจะสามารถอ่านและทำงานต่อได้ทันทีโดยไม่ต้องถามว่า “gpom หมายถึงอะไร?” การยึดคำสั่งเริ่มต้นยังช่วยให้โค้ดและ Workflow สามารถถ่ายโอนข้ามทีมได้ง่ายขึ้น โดยเฉพาะในโปรเจกต์ที่ต้อง Collaborate หลายคน</p><p><strong>2. Default Preset Tailwind CSS แทน Customization</strong></p><p>Tailwind CSS เป็น Framework ยอดนิยมที่มาพร้อมกับ Design System เริ่มต้น เช่น ขนาดฟอนต์ สี และระยะห่าง (spacing) ที่ออกแบบมาอย่างดี แม้ว่านักออกแบบหรือนักพัฒนาจะสามารถ Customize ทุกอย่างได้ตามใจชอบ เช่น เปลี่ยนสีหลักจาก blue-500 เป็นสีที่กำหนดเอง หรือปรับขนาดฟอนต์ให้เข้ากับแบรนด์ แต่การยึดตาม Preset เริ่มต้นมีข้อดีที่ชัดเจน: ช่วยให้ AI สามารถ Generate UI พร้อมใช้งานได้ทันที</p><p>สมมติว่าคุณใช้ Tailwind ร่วมกับเครื่องมือ AI เช่น Figma-to-Code หรือ AI UI Generator ถ้าคุณยึดตาม Default Settings ของ Tailwind (เช่น bg-blue-500, text-lg, p-4) AI จะสามารถ Generate โค้ดที่สอดคล้องกับ Design System ได้อย่างรวดเร็วและแม่นยำ โดยไม่ต้องเสียเวลา Mapping สีหรือขนาดที่กำหนดเอง การ Customize มากเกินไป เช่น การกำหนด primary-color: #1a73e8 ในไฟล์ tailwind.config.js อาจทำให้ AI ต้องเรียนรู้เพิ่มเติมหรือเกิด Error ในการสร้าง UI ในทางกลับกัน หากใช้ Preset เริ่มต้น ผลลัพธ์จะออกมาเร็วและใช้งานได้ทันที</p><p>3. <strong>Minimal Customization กับ Nx</strong></p><p>Nx เป็นเครื่องมือทรงพลังสำหรับการจัดการ Monorepo และ Workflow การพัฒนาในโปรเจกต์ขนาดใหญ่ โดยเฉพาะที่เกี่ยวข้องกับ JavaScript และ TypeScript ซึ่ง Victor Savkin เองก็มีส่วนร่วมในการพัฒนา แม้ว่า Nx จะอนุญาตให้ Customize ได้อย่างมาก เช่น การปรับแต่ง Task Pipeline หรือการกำหนด Custom Executors แต่การยึด Default Settings ของ Nx ให้มากที่สุดมีข้อดีสำคัญ: ลดความเสี่ยงในการอัพเกรด Version ใหม่ที่อาจไม่เข้ากันได้กับสิ่งที่ Customize ไป</p><p>ตัวอย่างเช่น หากคุณ Customize Nx ด้วยการเขียน Executor หรือ Generator เฉพาะตัวมากเกินไป เมื่อ Nx ออก Version ใหม่ (เช่น จาก 16.x ไป 17.x) การเปลี่ยนแปลงใน Core API อาจทำให้โค้ดที่คุณ Customize ไว้ใช้ไม่ได้ ต้องเสียเวลาแก้ไขหรือเขียนใหม่ แต่ถ้าคุณใช้ Default Configuration เช่น การรัน nx build หรือ nx test โดยไม่ปรับแต่งเพิ่มเติม ทีม Nx จะรับประกัน Compatibility ระหว่าง Version ทำให้การอัพเกรดราบรื่นขึ้น ผลลัพธ์คือชีวิตของโปรแกรมเมอร์สบายขึ้น เพราะไม่ต้องกังวลกับการตามแก้ Bug หรือปรับโค้ดทุกครั้งที่มีการอัพเดต</p><p><strong>Benefits of Default Settings</strong></p><ol><li><strong>Time-Saving</strong>: ไม่ต้องเสียเวลาไปกับการปรับแต่งหรือเรียนรู้สิ่งที่คนอื่นปรับแต่งไว้</li><li><strong>Consistency</strong>: ทีมงานทุกคนทำงานบนพื้นฐานเดียวกัน ลดความสับสน</li><li><strong>Scalability</strong>: เครื่องมือหรือ AI สามารถทำงานร่วมกับ Default Settings ได้ง่ายขึ้น</li><li><strong>Reduced Mental Load</strong>: ไม่ต้องตัดสินใจเยอะเกินไปในเรื่องที่ไม่สำคัญต่อผลลัพธ์หลัก</li><li><strong>Future-Proofing</strong>: ลดความเสี่ยงจากปัญหาความเข้ากันได้เมื่ออัพเกรดเครื่องมือ</li></ol><p><strong>Counterarguments</strong>: เมื่อไหร่ที่ควร Customize?</p><p>แน่นอนว่าไม่มีอะไรสมบูรณ์แบบ Default Settings อาจไม่เหมาะกับทุกสถานการณ์ เช่น หากโปรเจกต์ต้องการ Specificity สูง (เช่น การสร้าง Branding ที่แตกต่าง) การ Customize อาจจำเป็น แต่คำถามที่ควรถามคือ “การ Customize นี้เพิ่มมูลค่าจริงหรือแค่สนองความต้องการส่วนตัว?” ดังที่ Savkin ชี้ว่า การปรับแต่งมักเกี่ยวข้องกับอัตลักษณ์มากกว่าประสิทธิภาพ หากคำตอบคือ “แค่รู้สึกดี” อาจถึงเวลาทบทวนว่าควรยึด Default Settings ไว้หรือไม่</p><p><strong>Conclusion</strong>: พลังที่มองข้ามของ Default Settings</p><p>จากประสบการณ์ของ Victor Savkin และตัวอย่างที่ยกมา Default Settings ไม่ใช่แค่ทางเลือกสำหรับคนขี้เกียจ แต่เป็นกลยุทธ์ที่ชาญฉลาดในการเพิ่มประสิทธิภาพ ลดความซับซ้อน และทำให้การทำงานร่วมกันราบรื่นขึ้น ไม่ว่าจะเป็นการใช้ Full Git Commands เพื่อให้ทุกคนเข้าใจตรงกัน, การยึด Default Preset ของ Tailwind CSS เพื่อให้ AI Generate UI ได้ทันที หรือการใช้ Nx โดย Customize น้อยที่สุดเพื่อลดความเสี่ยงในการอัพเกรด การยอมรับพลังของ Default Settings อาจเป็นกุญแจสำคัญที่ช่วยให้เราทำงานได้มากขึ้นโดยใช้ความพยายามน้อยลง และทำให้ชีวิตของโปรแกรมเมอร์สบายขึ้นจริงๆ</p><p>ดังนั้น ครั้งต่อไปที่คุณคิดจะตั้ง Alias ใหม่ใน Git, Customize Tailwind Config หรือปรับแต่ง Nx ลองหยุดและถามตัวเองว่า “Default Settings เพียงพอแล้วหรือยัง?” คำตอบอาจทำให้คุณประหลาดใจ</p><p><em>หากคุณคิดว่าบทความนี้มีประโยชน์ อย่าลืม share ให้เพื่อนๆ หรือแสดงความคิดเห็น</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14cc97aa7d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Year in Review 2022 in Thai]]></title>
            <link>https://perjerz.medium.com/year-in-review-2022-in-thai-a27a7844c6da?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/a27a7844c6da</guid>
            <category><![CDATA[year-in-review]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Sat, 31 Dec 2022 15:30:36 GMT</pubDate>
            <atom:updated>2022-12-31T15:30:36.568Z</atom:updated>
            <content:encoded><![CDATA[<p>เกือบจบปีแล้วมาบันทึกสิ่งได้เรียนรู้กันหน่อย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQoCz5k-C3KHIXu2ePHHdg.jpeg" /><figcaption>เจมส์ที่ไร่ชาฉุยฟง</figcaption></figure><p><strong>งาน</strong></p><ul><li>ฟรีแลน์ต้นปีงานหายหมด รายจ่ายเพิ่มขึ้น ทำงานกับ ITOPPLUS มากขึ้น</li><li>สนใจสร้าง Low Code Platform, Collaboration Tools, CRDTs, Local-first software</li><li>ได้โจทย์ยากที่น่าสนใจมาก CMS (Low code — Drag &amp; Drop) ใช้เอง</li><li>Research Low Level Angular, Reversed Engineering Internal Angular Data Structure, LView, Runtime JIT Compiler, ร่วม Architect Store Front สร้าง JS Router เอง อ่าน Angular source code ตลอด เป็นงานที่สนุกมาก</li><li>เข้าใจ MongoDB มากขึ้นจากการที่ต้องทำ Auto &amp; Manual App Level Backup</li><li>ถอด Image Resizer WASM, WebWorker ใน Squoosh (React App) มาใส่ใน CMS (Angular)</li><li>ต่อยอด WebWorker ด้วยการเอา Compress Logic ย้ายออกจาก Main thread</li><li>Coach รุ่นน้องย้ายสายคนนึง อัจริยะ หัวไว พารู้จัก Leetcode, System Design Interview ตอนนี้ออกไปได้งานใหม่เงินเดือนอัพ x2 ในปีเดียว อนาคตไกล ตอนเลี้ยงส่งน้องเมานิดหน่อยบอกผมจะเก่งกว่าพี่ให้ได้ 4–5 รอบ ผมชักเริ่มไม่มั่นใจว่านับถือผมหรือยังไง 55 ผมก็ยอมไม่ได้หรอก ต้องเก่งขึ้นกว่านี้ 55</li><li>สอนทีมใช้ Angular, RxJS, Edge Dev Tools คิดว่าจำเป็นและเป็นประโยชน์สำหรับทีม</li><li>ได้เขียน Lua เป็นภาษาที่น่าสนใจมากใน Scripting Language ที่ติดมากับ OpenResty Powerful มากสำหรับการ Customize Reversed Proxy, Web Server ถึงแม้ DX แย่ไปนิด</li><li>ElasticSearch พลาดไม่ได้สำหรับคนทำ Full-text search ภาษาไทย ซึ่งหนีไม่พ้นสำหรับคนทำ Product, Pages, Content Search เขียน Query บางส่วน ตัดคำเอง เพิ่งเห็นว่า MongoDB มี Full-text search เหมือนกัน แต่ไม่มั่นใจภาษาไทยว่าดีแค่ไหน Inverted Index, Trie Data Structure นี่เด็ดจริงๆ<br> ออกแบบ Nested Structure พลาดไป ต้อง Flat structure ยังแก้ทัน พี่วิกแนะนำมา</li><li>นั่ง Research &amp; Prototype End to end testing ให้ทีม QA มองภาษาที่ High Level หน่อยคือ Robotframework แล้วค้นพบว่า Selenium โคตรกาก ช้า ไม่แน่นอน (Non-deterministic) เลยไปเจอตัว Robocorp RPA ที่ Wrap Playwright ให้นี่แหละเร็วและใช้งานได้ดีที่สุด</li><li>(Chrome, Edge) Dev Tools, Profiling Debugging ใช้บ่อยมาก MacBook Ram 16 GB ระเบิดบ่อยๆ</li><li>อยู่ใน Stage ที่คุยกับพี่ต้นแล้ว library, เครื่องมือ ที่ใช้อยู่ไม่ตอบโจทย์ มี edge case ต้องแก้เช่น quill, cdk ต้อง fork มาแก้</li><li>Stress Test Components &amp; DOMs จำนวนมาก ได้แก้โจทย์ Layout thrashing</li><li>ขอบคุณพี่ต้นที่ให้โอกาส ถึงแม้เราจะเถียงกันบ่อยในหลายๆเรื่อง แต่เราก็เถียงกันด้วยเหตุผลเพื่อทำให้งานออกมาดี อะๆไม่ต้อง OnPush, markForCheck ก็ได้ครับพี่ ผมหยวนให้ 5555</li><li>เป้าหมายสำเร็จแล้ว Core Logic เสร็จ คนทำต่อได้</li><li>เป้าหมายใหม่ หางานใหม่ โจทย์ใหม่</li><li>สัมภาษณ์งาน</li><li>เตรียมตัว มันตื่นเต้น ได้รู้ว่าตัวเองไม่รู้อะไร รู้ว่าความสามารถอยู่ตรงไหนของตลาด รวมถึงราคา</li><li>เล็งต่างชาติ Remote | Relocated Jobs</li><li>สัมภาษณ์บริษัทดังนี้<br> <br> StrikeSocial (Blognone) <br> รอบเดียวคุยกับ Tech Lead เลย, พบว่าผมให้สัมภาษณ์แบบ Causal เกินไปหน่อยเลยพลาด ถามเคยใช้ NgRx, RxJS ไหม สุดท้ายก็จบด้วย Email Let’s keep in touch.<br> <br> Creately (Linkedin)<br> อยากเข้ามากเพราะ Product เป็นความสนใจ Collaboration Tools <br> <br> ทำข้อสอบออนไลน์ผ่าน Chatbot AdaFace วัดความรู้ทั่วไป สถิติ ปัญหาเชาว์ การตีความกราฟ JavaScript พื้นฐานโดนแต่เรื่อง Promise, แล้วก็ Coding Problem หนึ่งข้อ ภายใน 1.5 ชั่วโมง <br> <br> สัมภาษณ์ 3 รอบ <br> <br> สัมภาษณ์รอบแรก Pair Programming แก้โจทย์ OOP Vacuum Cleaner Robot ทำความสะอาดพื้นที่ Floor NxN กับ Engineer ค่อนข้างตึ๊บตอน Pair เพราะตื่นเต้นเป็นสนามแรกๆ ทำเสร็จในขั้นต้น แต่ดีหน่อยเค้าบอกแก้ต่อได้ดีขึ้นได้ เราก็นั่งคิดต่อคนเดียว เออแปลกดีทำไมมันคิดออกแบบลื่นไหลเลยส่งแก้ไป<br> <br> สัมภาษณ์​ System Design กับ Tech Lead สองคนให้ออกแบบ Collaboration Todo List ให้ Architect เลือก Technology Frontend Backend Database เราก็เลือก MongoDB เพราะมันไม่ค่อยมี Relation เป็น Document Oriented ซึ่งผิดเพราะมันมีส่วนของ User ที่เป็น Relation ต้องเลือก DBMS ด้วย ให้ออกแบบ Database อันนี้เหวอเพราะไม่ค่อยได้ออกแบบ Database แต่ก็เอาตัวรอดไปได้<br> <br> รอบสุดท้ายสัมภาษณ์กับ CEO ถาม Technical ด้วย<br> อันนี้เจ็บใจที่สุดเข้าไปรอบสุดท้ายแล้วถึง CEO เจอ CEO ถามว่าจะจัดการ Conflict กับหัวหน้ายังไง เป็นคำถามที่ไม่ได้เตรียมตัว ก็ตอบไปตามตรงว่าคุยกันตรงๆ ยอมรับฟังเหตุผลของหัวหน้า และคำถาม Technical นิดหน่อยให้อธิบาย Google Search ตั้งแต่ต้นจนจบ คำถามนี้ก็เหวอนิดๆ ต้องอธิบายตั้งแต่ DNS, TCP, Handshake TLS, Client Site Render, Data Structure ที่ใช้ Trie, Inverted Index, CDN, Google Page Rank Algorithm, Makrov Chain Model, Crawler เลยหรือเปล่า ตอบไปพอประมาณ แต่คิดว่าทำได้ไม่ดี ถามเรื่อง PubSub ก็เลยเล่าไปว่าเคยใช้ Google Cloud PubSub ส่ง Notification Message, Redis Pub Sub + SocketIO ทำ Chat กว่าจะตอบเมล์ปฏิเสธผม ให้ผมรอตั้งสองเดือนต้องเมล์กลับไปถาม พอจะเข้าใจว่าเค้ามาแค่สำรวจตลาด ไม่เห็นรับใครเลย เห็นเปิดรับสัมภาษณ์หลายประเทศมากทั้ง SEA, Singapore ไปจนถึง Romania} เห็น Applicants 1000+<br> <br>Celonis (Referal ขอบคุณ Santosh Yadev) <br>ได้รู้ว่าตัวเองไม่รู้เรื่องทำ Recursive Embeded View Template สัมไปสองรอบ รอบแรกทั่วไปทำความรู้จัก แล้วได้โจทย์ให้นำเสนอในรอบต่อไปให้ทำ Visulization Equation Calculator Convert ไปกลับระหว่าง UI Symbol ที่ Add Edit Delete ได้ ที่แสดงสูตรที่ใส่บนเครื่องคิดเลข นั่งเขียน Recursive Function Tree Tokenizer อันนี้ก็ทำได้ไม่ดีตีโจทย์ผิดว่าเค้าอยากให้ wrap ได้ดันไป Tokenize Symbol เป็นชิ้นๆเลย ทำให้ Visualization สูตรในวงเล็บไม่ได้ Parenthsis Group Deleted ไม่ได้ แล้วก็ถามผมเรื่อง RxJS — NgRx, OOP, Design Pattern รู้จักอะไรบ้างเคยใช้ยังไง ผมไม่ค่อยอินคำถามนี้เท่าไหร่แต่ก็เข้าใจเหตุผลที่เค้าถาม<br> <br> Honest Bank (Head Hunter รบเร้า แต่จริงๆไม่ได้คาดหวังเพราะ Onsite) {สัมภาษณ์รอบแรกเน้นถามเรื่องกระบวนการทำงานบริษัทเก่า CI, CD, Estimate เปิด Ticket}</li><li>สิ้นปีได้งานใหม่พอดี บริษัทต่างชาติ Remote work สมใจ รวมคนเก่ง พร้อมลุยงานเต็มที่ ไม่หลับ ไม่นอน ถวายชีวิต ให้บริษัท เริ่มงานปีหน้า มกราคมเกือบได้ไปฉลอง Rebrand บริษัทที่ US Headquarter แล้ว ไม่มี US VISA แต่ไม่เป็นไรเรามาทำงานค่อยไปปีหน้าหน้านะ</li><li>It’s time for React!</li></ul><p><strong>เงิน</strong></p><ul><li>เงินเก็บเท่าทุน</li><li>ช็อปของเข้าบ้านเก่งมากค่า ครีม, Gadget, เครื่องใช้ไฟฟ้า, Course, อาหารเสริม, หนังสือ ตามโปรโมรชั่นล้วนๆ ทาสการตลาดที่แท้ทรู</li><li>กินแพงพอประมาน อยากกินไรก็สั่ง อยากประหยัดเมื่อไหร่ก็กินถูกๆ</li><li>ไม่ได้ลงทุนอะไรเป็นพิเศษ เพราะจากประสบการณ์อันน้อยนิดและสไตล์การลงทุนยังไม่เห็นอะไรดีกว่าเงินฝากตอนนี้ จ่ายภาษีเต็มของปีที่แล้ว เจ็บหนัก แต่คิดว่าดีสุดแล้ว</li><li>ปกติไม่อินเรื่องหวย แต่ซื้อใบสองใบบ้าง เปิดประตูดวง 1 ในล้าน</li><li>เป็นหนี้รถพ่อ</li><li>ผ่อนรถให้พ่อมาแล้ว 1/3</li><li>ค่าเทอมน้องสู้ต่อไป</li></ul><p><strong>สุขภาพ</strong></p><ul><li>เจอคลิปทอมครูซกับนางเอก Tops Gun แล้วเป็นแรงบันดาลใจในการ ดูแลหน้า ทาครีมกันแดด ใช้ Serum Hyalu B5 ญาติๆบอกว่าหน้าใสขึ้น อุ๊ต๊ะ</li><li>ติดโควิท -&gt; รู้จัก Probotics</li><li>เป็น NAFLD <a href="https://www.bing.com/search?q=non-alcoholic+fatty+liver+disease&amp;filters=dtbk:%22MCFvdmVydmlldyFvdmVydmlldyEzYjUwMzE3Mi0wNjVkLTcyZDQtNmUzMC1hM2Y4ZjIzZDBmNTA%3d%22+sid:%223b503172-065d-72d4-6e30-a3f8f23d0f50%22+tphint:%22f%22&amp;FORM=DEPNAV">Non-alcoholic fatty liver disease</a>, LDL สูง <br> เลิกกินเครื่องใน ลดไข่แดง</li><li>ทานอาหารเสริมจากงานวิจัยที่ AI สรุป Research Paper (<a href="https://elicit.org/">https://elicit.org</a> เจ๋งมาก) ให้แล้ว Validate กับเพื่อน เช่น EGCg, Silymarin, L-Carnitine, L-Theanine, Probiotics, Soluble Fiber</li><li>Quercetin แก้ภูมิแพ้ กินแล้วไม่ช่วยเท่าไหร่</li><li>ออกกำลังกาย ไม่ค่อยเลย ทำไมมันยากจัง :P</li></ul><p><strong>หนังสือที่อ่าน</strong></p><ul><li>System Design Interview: An Insider’s Guide by Alex Xu</li><li><a href="https://www.amazon.com/System-Design-Interview-Insiders-Guide/dp/1736049119">System Design Interview — An Insider’s Guide: Volume 2</a> by Alex Xu &amp; Shan Lam (On going)</li><li><strong>Thaksin Shinnawatra Theory and Thought</strong> by Tony Woodsmen</li></ul><p><strong>ความรัก</strong></p><ul><li>ช่วยย้ายงานแฟนมาเป็น Tester ได้สำเร็จผ่านโปร เย้ๆๆ</li><li>เราอยู่ด้วยกันบ่อยขึ้นเลยต้องปรับตัวเข้าหากัน เว้นพื้นที่ให้กันบ้าง คิดถึงกันมากขึ้น</li><li>เก็บตังด้วยกัน</li><li>ปีหน้าเราไปเที่ยวต่างประเทศกันนะ :) ญี่ปุ่น หรือ สิงค์โปรดี</li></ul><p><strong>เป้าหมาย พันธกิจ ทำนายอนาคต ปีหน้า</strong></p><ul><li>เป็น Global Citizen ให้ได้</li><li>Setup Product ให้อยู่ตัว Maintainable ง่าย</li><li>อ่าน <a href="https://www.amazon.com/gp/product/1098118731/ref=ox_sc_act_title_2?smid=ATVPDKIKX0DER&amp;psc=1">The Staff Engineer’s Path: A Guide for Individual Contributors Navigating Growth and Change</a> by Tanya Reilly จบ</li><li>อ่าน Data Intensive เล่มแดง by เสด็จพ่อ Martin Kleppmann</li><li>อ่าน <a href="https://www.amazon.com/gp/product/B0BHX8BQ9C/ref=ox_sc_act_title_4?smid=ATVPDKIKX0DER&amp;psc=1">Engineering Management for the Rest of Us</a> by Sarah Drasner จบ</li><li>เชื่อว่า Local-first Software มาแน่ ลงลึกใน CRDTs, Collaboration Tools</li><li>ไล่เก็บหนังสือที่ดองไว้ Blue Ocean Strategy, Software Architecture: The Hard Parts</li><li>“ลดน้ำหนักจริงจัง” ตรวจ Fibroscan ลดค่าตับอักเสบ</li><li>AI จะเข้ามาช่วยชีวิตประจำและงานมากขึ้น ใครที่ Leverage AI ได้ก็จะ Productive ขึ้นไปอีก</li></ul><p><strong>ถอดบทเรียนหรือปรัชญาแบบ Life Coach</strong></p><ul><li>จากฟรีแลนซ์เลือกงานกลายเป็น Part-time และต่อไปเป็น Full-time จริงๆ​ Full-time ก็ไม่ได้แย่นะเราได้เจอโจทย์ในสเกลที่ใหญ่ขึ้นเรื่อยๆ ท้าทายและสนุกมากในการแก้โจทย์บริษัทที่มี Product เป็นของตัวเอง</li><li>ไปสัมภาษณ์งานบ้าง จะได้รู้ว่าตัวเองอยู่ตรงไหนของตลาด ทั้งราคาและความสามารถของตัวเอง จะได้ปรับปรุงในสิ่งที่เราไม่รู้</li><li>ชีวิตคือการเรียนรู้ ทุกอย่างเป็นบทเรียน ถูกบ้าง พลาดบ้าง ให้เราโตขึ้น เก่งขึ้น แล้วส่งต่อสิ่งดีให้คนอื่น (Curiosity Driven Development)</li><li>Ikigai อิกิไก<a href="https://th.hrnote.asia/tips/210730-ikigai/#1_What_you_love__What_you_are_good_at__Passion"> 1. สิ่งที่เรารัก — 2. สิ่งที่เราทำได้ดี — 3. สิ่งที่โลกต้องการ — 4. สิ่งที่ทำให้เกิดรายได้</a> หาสิ่งที่ทำให้เกิดรายได้ให้เจอก็พอ แล้วหารายได้มากไปทำอย่างอื่นก็ได้</li><li>กิน อิ่ม นอน หลับ พักผ่อน สมหวัง (ออกกำลังกาย)<br> เครียด ทุกข์ ผิดหวัง ก็จัดการ เล่นเกมส์ คุยกับเพื่อน นอนหลับ เดะพรุ่งนี้ก็ดีขึ้น ชีวิตมันก็แค่นั้น ทุกข์ สุขปนกัน จะไปจมอยู่กับทุกข์หรือสุขมากไปทำไม มันก็แค่ชั่วคราว</li></ul><p>แฮปปี้นิวเยีย 2023 ครับ<br> ขอให้ทุกท่านที่อ่านจบถึงตอนนี้สุขภาพแข็งแรง ปลอดภัย สุขเยอะๆทุกข์น้อยๆ เฮงๆ รวยๆ ถูกหวยรางวัลที่ 1</p><p>สู้ชีวิตต่อไปเพื่อตัวเองและคนที่เรารัก</p><p><strong>เป็นพลังบวกให้คนรอบตัว :D</strong></p><p>#perjerz</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a27a7844c6da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Year in Review 2022 in English]]></title>
            <link>https://perjerz.medium.com/year-in-review-2022-in-english-b78a638f1d65?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/b78a638f1d65</guid>
            <category><![CDATA[year-in-review]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Sat, 31 Dec 2022 15:26:36 GMT</pubDate>
            <atom:updated>2023-01-01T01:13:38.212Z</atom:updated>
            <content:encoded><![CDATA[<p>Almost end of the year, let’s note what I learn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jQoCz5k-C3KHIXu2ePHHdg.jpeg" /><figcaption>Jame at Choui Fong Tea (ชาฉุยฟง)</figcaption></figure><p><strong>Work</strong></p><ul><li>Freelance works were almost none. I have more expense, so I work more at the ITOPPLUS.</li><li>Interested in Low Code Platform, Collaboration Tools, CRDTs, Local-first Software</li><li>Got the challenged to build CMS from scratch (Low code Drag &amp; Drop)</li><li>Researched low level Angular, did reversed engineering internal Angular Data Structure — View, Runtime JIT Compiler, Architected storefront JS Router for MPA, read a lot of Angular source codes, it was fun.</li><li>Understood MongoDB because of building auto &amp; manual app level backup</li><li>Copied image WASM Resizer, WebWorker from Sqoosh (React) to CMS (Angular)</li><li>Enhanced WebWorker by moving some compress logic out of the main thread</li><li>Coached the genius junior dev that doesn’t come from CS background by introducing Leetcode, System Design Interview. Now, he got x2 Salary in one year. During farewell he did drunkly tell me that he is going to be improved himself better than me 4–5 times. I am confusing that he is respect me or not. Lol. However, I have to improve myself to better also. LOL</li><li>Gave Angular, RxJS, Edge Dev Tools Workshop. It is important and useful for a team.</li><li>Wrote Lua. Lua is interesting scripting language that embedded in OpenResty. It is powerful to customize reverse proxy or web server, even it has bad DX.</li><li>Elasticsearch is good for Thai full-text search. It is inevitable for products, pages, and contents search features. I wrote some queries. I have to tokenize words myself. Also, I found that MongoDB has full text search also, but I am not sure that is good for Thai language. Inverted Index &amp; Trie data structures are cool. I designed nested structure incorrectly, it should be flatten structure. P’ Vick has suggested.</li><li>Researched &amp; prototyped end to end testing for QA team. I was looking for high level language which is Robotframework. I also found out that Selenium is suck. It is slow and non-deterministic. The good alternatives is Robocorp RPA which wrapping Playwright. It is the fastest and reliable.</li><li>Always used Edge Dev Tools for profiling and debugging, However, MacBook Ram 16 GB is not enough for this project. It was always crashed.</li><li>I’ve usually talked CTO P’Ton that the libraries we use don’t handle edge case that we have — Quill, CDK. We have to fork and customize them.</li><li>Stress Test complexed overwhelmingly components and DOMs</li><li>Fixed layout thrashing problems</li><li>Thanks to CTO P’Ton for giving me this opportunity even we have been conflict sometimes. We have good arguments for better products. OK P’Ton. I let you skip OnPush, markForCheck. LOL.</li><li>The core logics are completed. Everyone can extend it.</li><li>I am looking for new goals, new jobs, and new challenges.</li><li>Interviewing</li><li>Preparing Interview is nervous but it help you know what you don’t know, so you know what level you are both prices and skills</li><li>Looking for international remote or relocated jobs</li><li>Here is the list of the companies I did interview</li></ul><p>StrikeSocial (Blognone)</p><p>One round interview with Tech Lead, the problem is I gave interview too casual. She asked me that have I used NgRx, RxJS. However, it was end with the email said Let’s keep in touch.</p><p>Creately (Linkedin)</p><p>I was excited to apply Creately because the product is my interest (Collaboration Tools)</p><p>I did the general exam test via AdaFace. There are statistics, problem solving, graph interpretation, JavaScript &amp; Java problems, and one coding problem in 1.5 hours. It was intense.</p><p>There are three interview rounds.</p><p>First is pair programming with Creately Senior Software Engineer to solve OOP problem. The problem is Vacuum Cleaner Robot cleaning the floor NxN. I was too excited, however, I solved the problem in a first level. Luckily, it was possible to refactor this code base later. Therefore, I solo spent more times refactored this code for more encapsulation, decoupling the two classes Vacuum Cleaner and Floor.</p><p>Next round is to System Design Interview with two tech leads. The interview was to architect the Collaboration Todo List. I had to design the system, choose technologies, databases and tools. I chose MongoDB instead of RDBMS because I think it has not so much relation. It is more Documented-base. I was wrong. There is user that is relation for RDBMS. This problem shocked me because I have rarely designed database tables. However, I did survive this part. And we talked about drag and drop. This was interesting to me because my experience was designing drag &amp; drop. The question is in order to efficient, consistent query, add, move, edit, delete the todo list, everyone is dragging todo and, how to store todo list in databases. My previous solution from in CMS was used single linked list. To update list, just update the next node by skipping and repointing to new one. There is no reason to sort list in the database everyone when adding, I just update the pointer. The problem is that the backend has to construct the sorted linked list after query from the database. The simple solution from Tech Lead is to keep the order number in each node. This solution came from <a href="https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html">CRDTs: The Hard Parts</a> from <a href="https://martin.kleppmann.com/2020/07/06/crdt-hard-parts-hydra.html">Martin Kleppmann</a>. I have tried this before, but the problem is when inserting one todo between todo #3 and todo #4. I have to resorted order no for 3# 4# 5#. Tech Lead suggest me that I just use floating number for order number so I can insert 3.5 between two todos. And that is the exact “Ahha” moment I have watched this before in the CRDTs: The Hard Parts Youtube Video. I am really respected the Tech Lead to help me for the interview.</p><p>Last round is interview with CEO. It was shocked to me for the first question is that how do I manage conflict with the boss. I haven’t not much problems with my boss. Therefore, I answered that I agree on the boss argument because he has his reason, but I always concern what the problem with his solution, and the boss has to accept that.</p><p>And then I got the technical question to explain when we type something in google.com, what happen behind. I was shocked a little bit. Shall I start at the DNS resolve IP Address at google.com, TCP, TLS Handshake, Client Site Render, Data Structure (Trie, Inverted Index) CDN, Google Page Rank Algorithm, Makrov Chain Model, Backlink, Crawler? I do explain a little and end with Data Structure Inverted Index. And he also asked about Pub Sub that I did. I explained about Google PubSub I used for notification and Redis PubSub + SocketIO for chat rooms.<br> <br>That was rough. Then, I was waiting for the result with patient. Sadly, there was no response for two months. I decided to ask HR via email. And I got the answer that I don’t get accepted. I am still looking at the LinkedIn Company People. When are new employees number is going to be increased more than 60 which mean new employee got accepted. It was long time now, it is still 60 people. I do monitor that they recruit so many rounds in so many places — Southern East Asia, Singapore, Thailand, Romania, Europe. There is still no new person got accepted. I guessed there are 1000+ applicants. They are still looking for the best candidates in the world. Maybe you could apply. I’ve gotten rejected since 22 September.</p><p>Celonis (Referral by Santosh Yadav)</p><p>I learned that I don’t know about recursive embedded view. It was 2 rounds interview.<br> The first round is chit-chat about the experience, then I got the challenged project to build Visualization Equation Calculator that can convert the equation including symbols, operators and numbers to the Visualized Component UIs that can be edited, added, and deleted. It had to be convert back and forth. I have written the Recursive Tree Tokenizer Function. The problem was that I misunderstood the problem. I have written tokenize symbol to piece by piece, but the equation has to wrap some statement together. For example, in the parenthesis (a+b+c), The goal was to assume that the statement in the parenthesis can be deleted, but I did tokenize (, a, +, b, c separately. And then I got the question about have I used RxJS, NgRx. I did answer yes I have. I don’t buy asking this question, but I understand why interviewer asking.</p><p>Honest Bank (Head Hunter encourage me to apply but I didn’t expect because of onsite)</p><p>I like they give me the overview process of all interview rounds.</p><p>The first round is talked with some Senior. He asked me about the experience, and we talked about the software development process including CI, CD, Estimation, Opening tickets.</p><p>At the end of the year, I finally got a new job with international remote work. I am very happy.</p><p>There are so many talented engineers that I know. I am so exited to start working without sleeping. I will use my whole life for the company. It is going to start in January. I almost get the visit the US Headquarter. However, I have no US Visa. I have no chance for this year but may next year I maybe have.</p><p><strong>Wealth</strong></p><ul><li>Saving no loss no profit</li><li>I do a lot of shoppings, Facial creams, gadgets, appliances, courses, supplements, books. I am such a promotional victims.</li><li>Expensive Eating sometimes, sometimes order what I want, sometimes order cheap foods when I want to save money.</li><li>I did not invest in anything special. From my little experience and my investment styles, I have not seen anything better than saving account. I did fully pay the tax for this year. It was hurt, but it was the best.</li><li>I did not interest for lotteries, however, I have bought 1–2 lotteries for having a chance to be millionaire with one in million possibilities.</li><li>Dad’s car debt has bee paid 1/3</li><li>Sister tuition fee is just started. Cheer up!</li></ul><p><strong>Health</strong></p><ul><li>Watched Tom Cruise and main actress in old Top Guns. I was inspired by how Tom Cruise take caring his face. Therefore, I’ve bought the facial cream including Serum Heal B5. My family told me that my face is brighter. Wow!</li><li>Got Covid -&gt; Try Probiotics.</li><li>I have NAFLD <a href="https://www.bing.com/search?q=non-alcoholic+fatty+liver+disease&amp;filters=dtbk:%22MCFvdmVydmlldyFvdmVydmlldyEzYjUwMzE3Mi0wNjVkLTcyZDQtNmUzMC1hM2Y4ZjIzZDBmNTA%3d%22+sid:%223b503172-065d-72d4-6e30-a3f8f23d0f50%22+tphint:%22f%22&amp;FORM=DEPNAV">Non-alcoholic fatty liver disease</a>, high LDL. I am avoid pork intestines, high <a href="https://www.google.com/search?sxsrf=ALiCzsZG9a9gJLZ3VMzEUb1hK55QVAkE8w:1672498702629&amp;q=cholesterol&amp;spell=1&amp;sa=X&amp;ved=2ahUKEwjWtrqYj6T8AhUcumMGHbBNDc0QkeECKAB6BAgJEAE">cholesterol</a> foods and red eggs.</li><li>Take supplements from research papers that has been summarized by the AI (<a href="https://elicit.org/">https://elicit.org</a> is cool). I also recheck with my friends about the effects. There are EGCg, Silymarin, L-Carnitine, L-Theaine, Probiotics, Soluble Fiber.</li><li>Quercitin is for curing allergy, but it doesn’t help much.</li><li>Exercise is so hard to start.</li></ul><p><strong>Read Books</strong></p><ul><li>System Design Interview: An Insider’s Guide by Alex Xu</li><li><a href="https://www.amazon.com/System-Design-Interview-Insiders-Guide/dp/1736049119">System Design Interview — An Insider’s Guide: Volume 2</a> by Alex Xu &amp; Shan Lam (On going)</li><li><strong>Thaksin Shinnawatra Theory and Thought</strong> by Tony Woodsmen</li></ul><p><strong>Love</strong></p><ul><li>Help my girlfriend to be QA, pass probation! Holey!</li><li>We live together more. We have to adapt more. We leave some spaces. We miss each other more.</li><li>Saving together</li><li>Next year let’s travel Japan or Singapore.</li></ul><p><strong>Goal, Mission, Future Prediction in 2023</strong></p><ul><li>Be global citizen</li><li>Setup product to be stable, Maintainable</li><li>Finish reading <a href="https://www.amazon.com/gp/product/1098118731/ref=ox_sc_act_title_2?smid=ATVPDKIKX0DER&amp;psc=1"><strong>The Staff Engineer’s Path: A Guide for Individual Contributors Navigating Growth and Change</strong></a></li><li>Read Giant Red Book Data Intensive by Martin Kleppmann</li><li>Finish reading <a href="https://www.amazon.com/gp/product/B0BHX8BQ9C/ref=ox_sc_act_title_4?smid=ATVPDKIKX0DER&amp;psc=1">Engineering Management for the Rest of Us</a> by Sarah Drasner</li><li>I believe Local-First software will be mainstream. I will deep dive into CRDTs and collaboration tools.</li><li>Back to old books that I bought — Blue Ocean Strategy, Software Architecture: The Hard Parts</li><li>“Loss weight”, Fibroscan, decrease SGOT SGPT</li><li>AIs will be in our daily life more. Who is able to leverage AI power will have more productivity.</li></ul><p><strong>Lesson and Philosophy Learn as Life Coach</strong></p><ul><li>From Freelance to Part-time to Full-time experience, the full-time doesn’t really bad. I have seen the bigger scaled problem. It was challenged to solve the problem from the self product company.</li><li>Sometimes, take the interview. So you can learn which position are you right now including prices and skills.</li><li>Life is long-learning. Everything is lesson. Sometimes, you are wrong, Sometimes, you are right. It make you grow up. You then give to the others.</li></ul><p>(Curiousity Driven Development)</p><ul><li>Ikigai 1. What you love 2. What you are good 3. What world needs, 4. What make money. Finding what make more money first then find others later.</li><li>Eat, Full, Sleep, Relax, Satisfy, Exercise.</li><li>Stress, suffering, disappointing are temporary. You have to manage yourself by playing game, talking to your friends and sleeping. Tomorrow is going to be better.</li></ul><p><strong>Happy New Year 2023</strong></p><p>Hope you all be healthy, save, more happy, less sad, lucky, rich, win first lottery.</p><p>Keep moving for yourself and your loves</p><p><strong>Be positive vibes for people around you. :D</strong></p><p><strong>#perjerz</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b78a638f1d65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular คืออะไร เหมาะกับใคร งานแบบไหน]]></title>
            <link>https://perjerz.medium.com/angular-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3-%E0%B9%80%E0%B8%AB%E0%B8%A1%E0%B8%B2%E0%B8%B0%E0%B8%81%E0%B8%B1%E0%B8%9A%E0%B9%83%E0%B8%84%E0%B8%A3-%E0%B8%87%E0%B8%B2%E0%B8%99%E0%B9%81%E0%B8%9A%E0%B8%9A%E0%B9%84%E0%B8%AB%E0%B8%99-64a5e33220a0?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/64a5e33220a0</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[enterprise]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Tue, 15 Dec 2020 04:17:23 GMT</pubDate>
            <atom:updated>2020-12-15T06:35:27.424Z</atom:updated>
            <content:encoded><![CDATA[<p>บทความนี้จะทำให้คุณเข้าใจ</p><ul><li>ภาพกว้างของ Angular</li><li>เหมาะกับใคร งานแบบไหน</li><li>ใครใช้อยู่บ้างในไทยและต่างประเทศ</li><li>ไม่เหมาะกับงานแบบไหน</li></ul><p>มาเริ่มกันเลย</p><h3>ภาพกว้างของ Angular</h3><p>ถ้าพูดถึง Technology ที่ทำ Singe Page Application (SPA) แล้ว Angular เป็นหนึ่งในตัวเลือกที่ดีในการสร้าง<strong> </strong>Web Application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQMJCKzTRHlhdCIwktdP7A.png" /><figcaption>ng-conf 2019 Day 1 Keynote — <a href="https://youtu.be/JX5GGu_7JKc?t=41">https://youtu.be/JX5GGu_7JKc?t=41</a></figcaption></figure><p>จากรูปด้านบนแสดงให้เห็นถึงการนำ Angular ไปสร้าง Web Application <br>แกน Y บ่งบอกถึงผู้ใช้งาน (User) Web Application ยิ่งสูงแปลว่าผู้ใช้งาน Application จำนวนมาก<br>แกน X บ่งบอกถึงจำนวน Application ที่ถูกสร้างยิ่งชิดขวายิ่งมี Application จำนวนมาก</p><p>จากกราฟเราก็จะเห็นได้ว่ามีไม่กี่ Application บนโลกหรอกที่ผู้ใช้จำนวนมากระดับพันล้าน (นับมือได้เลย) ซึ่งจะเห็นพื้นที่ใต้กราฟว่าไม่มีสีแดงซึ่งหมายถึงไม่มี Angular Application อยู่ในนั้น</p><p>แต่ถ้าเป็น Web Application ที่ใช้ในองค์กรขนาดใหญ่ (Enterprise) ที่มีผู้ใช้ประมาณ 100–100,000 คน (มีบริษัทในไทยมีพนักงาน 1,000,000+ คน ทักมาบอกผมหน่อย) พื้นที่ใต้กราฟสีแดงจะเข้มมากนั้นหมายถึง Angular ถูกนำไปใช้สร้าง Web Application เพื่อใช้แก้ปัญหาทางธุรกิจ</p><p>ในทำนองเดียวกัน Web Application ขนาดเล็กหรือกลางที่มีผู้ใช้งาน 1–99 คน Angular ถูกนำไปใช้สร้างเครื่องมือเพื่อแก้ปัญหาหรืออำนวยความสะดวกบางอย่างเช่นกัน</p><h3>Angular เหมาะสำหรับทำ Web Application “ใช้ในองค์กร” ทั้งขนาดเล็ก กลาง และใหญ่ แต่เหมาะที่สุดกับองค์กรขนาดใหญ่</h3><p>ซึ่งผมจะอธิบายในหัวข้อถัดไปว่าทำไม Angular ถึงเหมาะ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8IEKQEnKSwXus-8MTLnJCA.png" /></figure><h3>Framework</h3><p><strong>Angular</strong> นั้นเป็น <strong>Web Framework </strong>นั้นหมายถึงมีเครื่องมือครบทุกอย่างให้แล้วเพียงพอที่จะใช้สร้าง Web Application ขึ้นมาโดยไม่จำเป็นต้อง <br> <strong>“เลือก” </strong>ใช้อะไรเพิ่ม “<strong>เอง” </strong>ซึ่งต่างจากแนวคิดของ Library ที่คุณจะต้องเลือกเครื่องมือประกอบ <strong>“เอง” </strong>ทั้งหมด ซึ่งคุณต้องมีความ “<strong>เชี่ยวชาญพอ” </strong>ที่จะเลือกของให้เหมาะกับงานของคุณ</p><p>จากรูปด้านบนจะเห็นได้ว่า Angular มี Tools ครบแทบทุกอย่าง</p><ul><li><strong>Protactor &amp; Karma</strong> — ทำ End-to-End Testing</li><li><strong>Forms </strong>— สร้าง Validation ให้กับ Form</li><li><strong>PWA </strong>— สร้าง Progress Web Application</li><li><strong>Augury</strong> — Chrome และ Firefox Dev Tools สำหรับ Angular apps</li><li><strong>Language Services </strong>— Protocol ที่ช่วยให้ Editor สามารถใช้ Auto completion, บอก Errors, Hints, และ Navigation (Go to definition)ใน Angular templates (HTML)</li><li><strong>Router </strong>— สร้าง Application หลายๆหน้าโดย Wrap History API ของ Browser ให้</li><li><strong>Elements</strong> — สร้าง Web Component ด้วย Angular เพื่อเอาไปใช้นอก Angular ได้</li><li><strong>CDK (Component Development Kit) </strong>— เครื่องมือสำหรับสร้าง Component เช่น Virtual Scroll, Table, Drag &amp; Drop</li><li><strong>Universal </strong>— ทำ Server Side Rendering (SSR) ใน Angular</li><li><strong>Labs </strong>— โปรเจคทดลองใน Angular</li><li><strong>Compiler </strong>— Compile code ที่เราเขียนเป็น HTML, CSS, JavaScript ที่ Browser เข้าใจ</li><li><strong>i18n</strong> — Internalization สำหรับทำ Application หลายภาษา</li><li><strong>Http </strong>— สำหรับยิง Http Request โดย Wrap XMLHttpRequest(XHR)</li><li><strong>Material </strong>— Material Design Component ใน Angular</li><li><strong>Animations</strong> — สำหรับทำ Animation ใน Angular โดย Wrap CSS Transition</li><li><strong>CLI</strong> — Command-line interface สำหรับสร้าง App, Libray, Component, Service, Pipe, Directives และอื่นๆ</li></ul><p>Tools ทุกอย่างนี้ถูกสร้างและดูแลโดย Google เอง ทำให้มั่นใจได้ในระดับนึงว่ามันจะยังถูกดูแลโดยสุดยอด Software Engineer และเรายังสามารถใช้งานมันต่อไปได้นานๆ</p><h3>TypeScript</h3><p>TypeScript พิสูจน์ตัวเองแล้วว่ามันช่วยให้ Software ที่เราสร้าง สามารถถูกดูแลในระยะยาว (Maintainability) จากการมี Type System ในการ</p><ul><li>ลดระยะเวลาในการอ่านและทำความเข้าใจ Code (Readability) <br>ทำให้ Abstraction นั้นชัดเจน (Explicit) ได้ เช่นตั้งชื่อตัวแปร user ถ้าหากไม่มี TypeScript เราก็ต้องไปเช็คเองว่าใน user มีอะไรกันแน่แต่ถ้ามี TypeScript เราสามารถรู้ได้เลยว่าใน user มีอะไรบ้าง</li><li>ทำให้เราได้ใช้ความสามารถของ Autocompletion ได้ Editor, Go to definition ย้อนกลับไปต้นทางของ Type, Refactor Type เพียงดีดนิ้ว และ แจ้ง Error นะ Compile time เพื่อลด Error ณ Runtime บางส่วนออกไปได้ นี้ยังไม่รวมถึงใช้ฟีเจอร์ใน EcmaScript ที่กำลังจะออกใหม่ก่อน</li></ul><p>Angular ถูกสร้างโดย TypeScript ตั้งแต่แรกซึ่งนั้นทำให้ Angular เป็น Framework ที่ Support TypeScript มากที่สุด ทำให้เราสามารถใช้โดยไม่รู้สึกสะดุดเลย <br>ซึ่งนั้นทำให้ Angular และ TypeScript เหมาะกับโปรเจคขนาดใหญ่<br>อ่านเพิ่มเติมได้ที่<br><a href="https://vsavkin.com/writing-angular-2-in-typescript-1fa77c78d8e8">Angular: Why TypeScript?| by Victor Savkin | Angular (vsavkin.com)</a></p><p>จริงแล้ว Angular เองนั้นทำให้ TypeScript โตขึ้นมาก แต่ในมุมมองผมคือ TypeScript ก็ช่วยทำให้ Angular โตขึ้นเหมือนกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*NZyBGNwopm2fWSz9" /><figcaption><a href="https://insights.stackoverflow.com/trends?tags=angular%2Ctypescript">Stack Overflow Trends</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/0*mS9G5OO6YMSSc54e" /></figure><blockquote>Oh, it was definitely Google announcing that they were going to use TypeScript with Angular. That’s kind of lost to time now. But if you look at the graphs for TypeScript, literally any graph — GitHub stars, downloads, pull requests — you can see the exact point when that Angular announcement came out. And the graph just changes. It never looks back. You can’t see that little bend in the curve anymore because the curve kept going. That was a real inflection point. And I think it’s been interesting that people thought at the time that TypeScript was going to be just what Angular people use and not much else. That didn’t turn out to be the case. Obviously, we’re still popular among Angular devs. But that was a real momentum builder for us.</blockquote><blockquote>Ryan Cavanaugh, Principal Engineering Lead TypeScript language at Microsoft</blockquote><blockquote><a href="https://stackoverflow.blog/2020/06/15/talking-typescript-with-ryan-cavanaugh/">Talking TypeScript with the engineer who leads the team — Stack Overflow Blog</a></blockquote><h3>Opionionated vs Unopinionated</h3><p>Opinionated มันคืออะไรกันนะ?<br>Opinion แปลว่าความเห็น เติม -ated กลายเป็น Adjective แปลได้ประมาณว่า “ที่มีความเห็นลงไป” เกี่ยวกับอะไร Angular นะ?</p><p>Angular เป็น Framework ที่มีเครื่องมือให้คุณใช้งานชัดเจน มีบางส่วนที่คุณเลือกหรือใส่ความเห็นได้เองบ้าง แต่เครื่องมือหลักๆ Google จะจัดไว้ให้แล้ว ความหมายคือ Angular Team ใส่ความเห็นลงไปว่าคุณควรจะใช้ Tools, Concept, Syntax, Design Pattern เหล่านี้ที่ทีมสร้างให้ ไม่ต้องไปเลือกหรือใส่ความเห็นตัวเองว่าจะใช้อะไรแทน Tools, Concept, Syntax, Design Pattern เหล่านั้น</p><p><strong>แล้วมันดียังไง? <br>ในการทำ Software ในองค์กรขนาดใหญ่ ที่มีหลายทีมรวมแล้วกว่า 500 คน “ถ้า”แต่ละทีมสร้าง Software ของตัวเองโดยใช้ Tools ตามใจชอบ, ไม่มี Standard หรือ Best Practices ร่วมกัน ในการหมุนเวียนคนทั้งคนในด้วยกันเองหรือคนเข้าคนออก (Turnover) ผลลัพธ์ที่ตามมาคือจะต้อง “ใช้เวลามากขึ้น” ในการสื่อสารเพราะต้องทำความเข้าใจกับ Tools, Standard และ No Practice ใหม่ที่ไม่คุ้นชิน<br>แต่ถ้า “มีความเห็นลงไปตั้งแต่แรก”เลยจาก Framework ว่าในการแก้ปัญหาเรื่องนี้ “เรารู้กันตั้งแต่แรก” ว่าเราจะใช้เครื่องมือ, Standard หรือ Best Practice นี้ย่อมช่วยลด “เวลา” ไปได้เลยในการที่จะ Onboard คนใหม่เข้ามาในโปรเจ็ค</strong></p><blockquote><a href="https://blog.nrwl.io/12-things-to-help-large-organizations-do-angular-right-f261a798ad6b">https://blog.nrwl.io/12-things-to-help-large-organizations-do-angular-right-f261a798ad6b</a></blockquote><h3>Dependency Injection &amp; Object Oriented Programming &amp; Type System</h3><p>Angular นั้นมี <strong>Dependency Injection, Object Oriented Programming และ Type System (TypeScript) Concept </strong>เหมือนกับภาษา<strong> .NET (C#), Java </strong>ที่ใช้แพร่หลายใน<strong> บริษัทขนาดใหญ่ (Enterprise) </strong>และใช้กันมานานแล้ว</p><p><strong>Depedency Injection<br></strong>เป็นหนึ่งในเทคนิคของ <a href="https://en.wikipedia.org/wiki/Inversion_of_control">inversion of control</a> (I) ซึ่งอยู่ใน SOLID Principles มาจากหนังสือ Design Pattern ของ Gang of Four (GoF) ที่ว่าด้วยเรื่องของการออกแบบ Software ให้เข้าใจง่าย ยืดหยุ่น และดูแลต่อสบายใน Object Oriented Programming<br>โดยที่ความตั้งใจของ Dependency Injection คือได้มาซึ่ง<a href="https://en.wikipedia.org/wiki/Separation_of_concerns"> Seperation of Concerns </a><br>ของการสร้างหรือใช้ Object Instance เพื่อ Readability และ Reusability</p><p>โดยการแยกสร้าง Dependency Object นั้นใน Class ที่จะต้องการจะใช้งานมัน<br>ทำให้การสร้าง Dependency Object ใน Class นั้นตรงๆมันเปลี่ยนไม่ได้ และทำให้ Test ยากเพราะว่า Dependency Object นั้นไม่สามารถถูกแทนที่ด้วย Mock Object</p><p>แต่ถ้าเราเปลี่ยนว่าใน Class นั้นๆเราขอ Dependency Object ตามนี้ไม่สนใจว่าจะได้มายังไงให้ หามาให้เอง ทำให้เรา Test ง่าย</p><p>ซึ่งใน <strong>.NET(C#), Java </strong>มีเทคนิคนี้เหมือนกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2VQE8kdzCVFQCzHdvhxFGA.png" /><figcaption><a href="https://github.com/perjerz/firebase-ivy-live-feed/blob/master/src/app/firebase-toolbar/firebase-toolbar.component.ts">https://github.com/perjerz/firebase-ivy-live-feed/blob/master/src/app/firebase-toolbar/firebase-toolbar.component.ts</a></figcaption></figure><p><strong>Decorator Pattern</strong></p><p>Decorator Pattern เป็น 1 ใน 23 pattern ใน หนังสือ Design Pattern ของ Gang of Four (GoF) ซึ่งว่าด้วยเรื่องของการออกแบบ ​Software ใน Object Oriented Programming ซึ่งทำให้เราเพิ่มความสามารถของ Object, Class, Function ได้ด้วยการไปแปะไว้ที่ Decorator (Annotation) ไว้ที่หัวของสิ่งๆนั้น <br>จากตัวอย่างข้างบน เรามี AppComponent Class ซึ่งเป็น JavaScript Class ธรรมดาที่มี Member, Methods ทั่วไปแต่บนหัว Class เราไปแปะ @Component</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*AernyhX6S0UPboeNh4wsjA.png" /><figcaption><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.component.ts">https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.component.ts</a></figcaption></figure><p>เพื่อเพิ่มความสามารถ Class แล้วบอกว่า Class นี้คือ Component ที่มีรายละเอียด selector, HTML, SCSS ตามที่ระบุ<br>และจริงเราสามารถเขียน Decorator เองได้เช่น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GjMMZ3l1F-jN7-36k9M20w.png" /><figcaption><a href="https://itnext.io/custom-decorators-in-angular-c54da873b3b3">https://itnext.io/custom-decorators-in-angular-c54da873b3b3</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*ucEyo8GgQOTpU-R053kPXw.png" /><figcaption><a href="https://itnext.io/custom-decorators-in-angular-c54da873b3b3">https://itnext.io/custom-decorators-in-angular-c54da873b3b3</a></figcaption></figure><p>เขียน Decorator แล้วแปะเพื่อให้ Function รันนอก Zone</p><p><strong>Type System (TypeScript)</strong></p><p>จากที่เคยได้กล่าวไว้ในย่อหน้าข้างบน Type System ช่วยให้เราทำงานได้มีประสิทธิภาพมากขึ้น ลดความผิดพลาด ดักจับข้อผิดพลาด ลดเวลาการสื่อสาร Refactor, Go to Definition ได้อย่างสะดวกสบายซึ่งเป็นเรื่องที่คุ้นชินกันอยู่แล้วใน Enterprise ที่ใช้ <strong>.NET C#</strong> หรือ <strong>Java Developer </strong>เพราะพลังของ IDE</p><p>จึงเป็นเรื่องง่ายขึ้นที่จะ Transfer Backend .NET C# หรือ Java Developer มาเป็น Angular Developer เพราะแนวคิดคล้ายๆกัน</p><p>อย่างไรก็ดีต้องเสริมความรู้ JavaScript หรือ TypeScript เพราะตัวมันเขียนได้หลายแบบ (<strong>Multi-paradigm) </strong>เช่นเราสามารถใช้ <strong>Functional Programming </strong>(<strong>Declarative — บอกว่าเราต้องการอะไรโดยไม่สนใจว่าทำยังไง</strong>) เข้าไปแก้ปัญหาบางอย่าง ทำให้อ่านโค๊ดได้ง่ายกว่า (map, filter, reduce) แทนการเขียนโค๊ดแบบ <strong>Procedural Programming</strong> (<strong>Imperative — บอกวิธีการเอง step by step เพื่อได้สิ่งที่ต้องการ)</strong>, บางส่วนออกแบบเป็น Class ใช้ (<strong>Object Oriented Programming</strong>) เพื่อซ่อนความสามารถบางอย่าง (<strong>Encapsulation</strong>) และให้ใช้ผ่าน Public API เท่านั้น</p><blockquote>แต่ละแนวคิดมีข้อดีข้อเสียของมัน ต้องเลือกให้เหมาะกับงาน</blockquote><h3>Angular CLI</h3><p>สุดยอดเครื่องมือของ Angular ที่ช่วยให้</p><ul><li>สร้าง Project ผ่านคำสั่ง <a href="https://angular.io/cli/new">ng new</a></li><li>สร้าง(Scaffolding) Component, Module, Service, Pipes, Service Worker และอื่นๆ ผ่านคำสั่ง <a href="https://angular.io/cli/generate3">ng generate</a></li><li>เพิ่ม Library ผ่านคำสั่ง <a href="https://angular.io/cli/add">ng add</a> โดยแก้ไข Code เราให้เรียบร้อยแทบไม่ต้อง Configure เพิ่ม</li><li>สั่ง Linter <a href="https://angular.io/cli/lint">ng lint</a></li><li>สั่ง Test <a href="https://angular.io/cli/test">ng test</a></li><li>ใช้ในการ Build, Serve ผ่านคำสั่ง <a href="https://angular.io/cli/build">ng build</a> , <a href="https://angular.io/cli/serve">ng serve</a> โดยตัวมัน Abstract (ละไว้ในฐานที่เข้าใจ) ความซับซ้อนของ Webpack ไว้ให้</li><li>Deploy Angular Application เข้าไปยัง Hosting ต่างๆเช่น (<a href="https://www.npmjs.com/package/@jefiozie/ngx-aws-deploy">AWS</a>, <a href="https://www.npmjs.com/package/angular-cli-ghpages">Github Pages</a>, <a href="https://www.npmjs.com/package/@zeit/ng-deploy">Vercel</a>, <a href="https://www.npmjs.com/package/@azure/ng-deploy">Azure</a>, <a href="https://github.com/angular/angularfire/blob/master/docs/deploy/getting-started.md">Firebase Hosting</a></li><li>อัพเกรด Version ของ Angualr Apps ผ่านคำสั่ง <a href="https://angular.io/cli/update">ng update</a><br>โดยปัจจุบันอัพเดทง่ายและรวดเร็วขึ้นมากเมื่อเปรียบเทียบกับเมื่อก่อน โดยรูปด้านล่างแสดงถึงการใช้เวลาอัพเกรด Version ใน Angular Application ของสายการบิน <a href="https://www.airfranceklm.com/en">Air France KLM</a> พบว่าเมื่อก่อนใช้เวลาเป็นเดือนแต่เมื่อ Version 7 ใช้เวลาเป็นวัน และ Version ปัจจุบัน 10 ไป 11 ใช้เวลาเป็นหลักชั่วโมง(ขึ้นอยู่กับความซับซ้อนของโปรเจค)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Ps5VvzALO2ZKYwTe" /></figure><p>อ่านต่อเพิ่มเติมได้ที่ <a href="https://medium.com/airfrance-klm/how-we-upgraded-a-website-with-half-a-billion-annual-users-to-angular-7-in-less-then-a-day-71de33a1108e">How we upgraded a website with half a billion annual users to Angular 7 in less than a day | by Mart Ganzevles | airfrance-klm | Medium</a></p><h3>มีใครใช้ Angular บ้าง</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bG7unMoI0ztEbQ29xIBHJQ.png" /><figcaption>ng-conf enterprise 2020 — <a href="https://www.youtube.com/watch?v=FsNTuzBfLxU">https://www.youtube.com/watch?v=FsNTuzBfLxU</a></figcaption></figure><p>แน่นอนคนสร้างก็ต้องใช้เองสิ Google ไง<br>จากรูปด้านบนใน Google เองนั้นใช้ Angular ในการสร้าง Web Application มากถึง 2600+ apps และนี่ยังหมายถึงการการันตีเวลาออกเวอร์ชั่นใหม่นั้นจะต้องทำให้ 2600+ apps ยังทำงานได้ปกติเปรียบเสมือนเป็น Test Suite ชั้นดีเลย<br>สามารถดูรายละเอียดเพิ่มเติมได้ที่ <a href="https://madewithangular.com/categories/google/">https://madewithangular.com/categories/google/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vaHrseUPIYSz1AHNxMUg2w.png" /></figure><p>แล้วถามว่ามี Product ดังๆหรือบริษัทอื่นที่เชื่อถือ Angular แล้วนำมันไปใช้สร้าง Web Application มีตัวอย่างบริษัทดังนี้</p><ul><li>Firebase, Google Cloud Platform</li><li>Microsoft มี Xbox และ Office Home ที่ใช้ Angular</li><li>Playstation ใช้ Angular &amp; NgRx ทำ Internal Tools <a href="https://twitter.com/kyledcannon/status/1165808928149491713">https://twitter.com/kyledcannon/status/1165808928149491713</a></li><li>American Airlines มีคนไทยทำงานอยู่ด้วย</li><li>VMWare สร้าง Clarity Design System <a href="https://clarity.design/">https://clarity.design</a> ใช้ในองค์กร</li><li>Deusche Bank สร้าง Design System และทำ Portal <a href="https://developer.db.com/">https://developer.db.com</a></li><li>Citibank สร้าง Design System ใช้เอง</li><li>Delta</li><li>Capital One <a href="https://medium.com/capital-one-tech/tagged/angular">Angular — Capital One Tech — Medium</a></li><li>Alibaba, Thoughtwork at China <a href="https://ng.ant.design/docs/introduce/en#companies-using-ng-zorro-antd">NG-ZORRO — Angular UI component library (ant.design)</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skt6h8ZL1WLNTQvN6pTJHw.png" /><figcaption><a href="https://angularthailand.github.io/who-use-angular-in-thailand">https://angularthailand.github.io/who-use-angular-in-thailand</a></figcaption></figure><p>แล้วในประเทศไทยหละมีบริษัทอะไรบ้าง</p><ul><li>Allianz Technology Thailand — <a href="https://www.facebook.com/Allianz-Technology-in-Thailand-526748361075590/">Allianz Technology in Thailand | Facebook</a><br> สร้าง UI Library (Design System) <a href="https://aposin.github.io/ng-aquila/welcome">Aquila Components (aposin.github.io)</a></li><li>Seven Peaks Software — <a href="https://sevenpeakssoftware.com/">Software Development &amp; UX UI Design services — Seven Peaks Software</a></li><li>FlowAccount — <a href="https://flowaccount.com/">โปรแกรมบัญชี ออนไลน์ สำหรับนักธุรกิจยุคใหม่ (flowaccount.com)</a></li><li>ScoutOut — <a href="https://scoutout.co/">สเกาท์เอาท์ | ระบบหาคน คัดกรอง และ ATS ในแพลตฟอร์มเดียว (scoutout.co)</a></li><li>KBTG — <a href="https://www.kbtg.tech/">KASIKORN Business — Technology Group (kbtg.tech)</a></li><li>Builk One — <a href="https://www.builk.one/">BUILK ONE GROUP — BUILK ONE GROUP</a></li><li>Exzy — <a href="https://www.facebook.com/ExzyTech/">EXZY Company Limited | Facebook</a></li><li>Krungsri Auto — <a href="https://www.krungsriauto.com/auto/home">กรุงศรี ออโต้ (krungsriauto.com)</a></li><li>ODDS — <a href="https://www.facebook.com/oddsteam/">ODDS (facebook.com)</a></li><li>ITOPPLUS — <a href="https://www.itopplus.com/new2020/">บริษัทรับทำการตลาดออนไลน์ E-Marketing ครบวงจร|ITOPPLUS</a></li><li>RIS Central Group — <a href="https://www.facebook.com/CentralGroupIT/">RIS Central Group (facebook.com)</a></li><li>H-LAB — <a href="https://www.hlabconsulting.com/">H LAB | Re-Engineering the Healthcare System (hlabconsulting.com)</a></li><li><a href="https://www.xn--12c1bik6bbd8ab6hd1b5jc6jta.com/">เราเที่ยวด้วยกัน | หน้าแรก</a></li><li>และอื่นๆอีกมากมาย</li></ul><p>สิ่งที่น่าสังเกตคือส่วนใหญ่บริษัทที่ใช้จะเป็นองค์กรขนาดใหญ่เช่นธนาคาร (Finance), สายการบิน(Airline), ประกัน(Insurance) ซึ่งผมมีสมมุติฐานได้ว่าบริษัทเหล่านี้ไม่สามารถรับความเสี่ยงของการเปลี่ยนแปลงของเทคโนโลยีได้มากเพราะถ้าหากเกิดปัญหาแล้วความเสียหายที่เกิดทางธุรกิจนั้นสูงกว่า(เรื่องเงินทองหรือชีวิตคน) <br>Angular เป็น Framework ที่เครื่องมือย่อยๆ (Library) ถูกดูแลโดย Google เอง ทำให้ความเสี่ยงต่ำ</p><h3>Angular จึงเหมาะกับองค์กรขนาดใหญ่ (Enterprise) ที่ต้องลดความเสี่ยงจากการเปลี่ยนแปลงของเทคโนโลยีในโลก JavaScript (เปลี่ยนแปลงอยู่ทุกวี่ทุกวัน)</h3><p>สนใจให้บริษัทของท่านอยู่ใน Website ด้านบนท่านสามารถส่ง Pull Request ได้มาที่ <a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/README.md">AngularThailand/who-use-angular-in-thailand (github.com)</a></p><h3>แล้ว Angular ไม่เหมาะกับบริษัทขนาดเล็กหรือกลาง (SMEs) หรอ?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*XloBJGXvWvk3fcqn" /><figcaption><a href="https://unsplash.com/photos/SJm90SvVaWU">https://unsplash.com/photos/SJm90SvVaWU</a></figcaption></figure><p>บริษัทขนาดเล็กและกลาง (SMEs) สามารถใช้ประโยชน์ของ Angular ได้เหมือนกันในการที่ทำ Software ที่มีความคงทน ใช้ได้ในระยะยาว 2–10 ปี (ถ้า Google Cloud Platform ยังอยู่ Angular ก็ยังอยู่เช่นกัน)</p><p>คงไม่มีใครอยากทำธุรกิจหรือทำ Software ไม่นานแล้วทิ้งขว้าง เราคงอยากให้ธุรกิจหรือ Web Application ของเราทำงานไปได้นาน สร้างรายได้สำหรับจ่ายเงินเดือนพนักงานทุกคน และสร้างกำไรคืนให้กับบริษัทและนักลงทุน</p><p>แล้วโปรเจคขนาดเล็กทำใช้แค่ 1 วัน — 5 เดือนหละเช่น</p><ul><li>ทำ MVP ในงาน Hackathon</li><li>เราเที่ยวด้วยกัน(<a href="https://people.xn--12c1bik6bbd8ab6hd1b5jc6jta.com/">เราเที่ยวด้วยกัน.com)</a></li></ul><blockquote>ความสำคัญของโปรเจคขนาดเล็กคือความเร็วในการพัฒนา</blockquote><p>Angular เป็นหนึ่งตัวเลือกที่ดีด้วยคุณสมบัติของการเป็น Framework ที่ของครบไม่ต้องคิดหรือเลือกเยอะ Setup มาให้แล้วตั้งแต่สร้างโปรเจค (ng new) ยัน Deploy (ng deploy) ลดเวลาการสื่อสาร</p><p>อย่างไรก็ดีมักมีคนตั้งข้อถกเถียงว่า Angular ใช้เวลาเรียนรู้สูง (Learning Curve สูง) เพราะเป็น Framework มีเครื่องมือ, แนวคิด (Concept) เยอะ ซึ่งผมมองว่าถึงคุณจะใช้ Library เล็กๆเช่น React คุณก็ต้องเรียนรู้แนวคิดนั้นๆเหมือนกันไม่ว่าจะเป็น Functional Programming, Virtual DOM, JSX, Hook, หรือ Library Form (Formik), Router (React Router) คุณต้องเข้าใจมันอยู่ดี</p><p><strong>เรียนรู้(แนวคิดหรือเครื่องมือ)เท่าที่ใช้ซิ</strong></p><p>เช่นคุณยังไม่เข้าใจ RxJS แปลงมันเป็น .toPromise() (<a href="https://indepth.dev/posts/1287/rxjs-heads-up-topromise-is-being-deprecated">ในอนาคตแก้เป็น lastValueFrom(), firstValueFrom() แล้ว</a>) หรือคุณเข้าไม่เข้าใจ ReactiveForms ก็ใช้ Template Driven Form ไปก่อน [(ngModel)] แต่อย่าลืมไปว่าคุณ Lost ความสามารถของเครื่องมือไป</p><blockquote>แต่ละแนวคิดมีข้อดีข้อเสียของมัน ต้องเลือกให้เหมาะกับงาน</blockquote><h3>แล้ว Angular ไม่เหมาะกับงานแบบไหน</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4wIajLv_hDMCEGDL.jpg" /><figcaption><a href="https://upload.wikimedia.org/wikipedia/commons/a/a7/JCB_3CX_backhoe_loader%2C_Florida%2C_backhoe_trick_9.jpg">https://upload.wikimedia.org/wikipedia/commons/a/a7/JCB_3CX_backhoe_loader%2C_Florida%2C_backhoe_trick_9.jpg</a></figcaption></figure><p>ไม่ใช่ทุกเครื่องมือที่เหมาะกับทุกงาน (One size fit all) เราคงไม่เอารถ Backhole ไปขนสินค้าส่งของ เราคงต้องใช้รถจักรยานยนต์หรือรถบรรทุกแทนไปตามความเหมาะสม เราคงใช้รถ Backhole ขุดดิน ทุบถนน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EQMJCKzTRHlhdCIwktdP7A.png" /><figcaption>ng-conf 2019 Day 1 Keynote — <a href="https://youtu.be/JX5GGu_7JKc?t=41">https://youtu.be/JX5GGu_7JKc?t=41</a></figcaption></figure><p>กลับมาที่รูปเดิม อย่างที่รู้กันว่าแทบไม่มี Angular Web Application ที่มี User ล้านคนขึ้นไปใช้ แล้วคำถามคือคุณสมบัติของแอพที่มีผู้ใช้จำนวนมากมีเหมือนกันคืออะไรกันนะ? คำตอบคือ</p><ul><li>โหลด<strong>ตอนแรก</strong>เร็ว</li></ul><p>เว็บอะไรบ้างที่ต้องโหลดตอนแรกเร็วเช่นเว็บข่าว, E-Commerce</p><p>แล้วอะไรทำให้โหลด<strong>ตอนแรก</strong>เร็วบ้าง แน่นอนไฟล์ HTML, CSS, และ JavaScript (Bundle Size) ยิ่งใหญ่ ยิ่งต้องรอโหลดนาน นี่ยังไม่รวมเวลาตอน Parse อีกกว่า User จะได้ใช้ Application (Time-to-interactive) ซึ่งอันนี้เป็น<strong>ข้อจำกัด</strong>ของ Client-Side Rendering (ให้ Browser Render) วิธีการแก้คือลดขนาดของไฟล์ HTML, CSS, JavaScript ซึ่งหลักๆจะเป็น JavaScript มากกว่า (ใช้ Service Worker, Browser Caching เพื่อไม่ให้โหลดใหม่, CDN ยิ่งใกล้ยิ่งเร็ว อันนั้นเป็นอีกประเด็น) <br>ซึ่งด้วยความที่ Angular มีเครื่องมือมาครบ มีของให้ใช้ไม่ต้องเขียนเอง<br>ยกตัวอย่างเช่น <br>เรามี <a href="https://angular.io/api/common/http/HttpClient">HttpClient</a> ใน Angular ที่เป็น Abstraction หนึ่งสำหรับการส่ง XMLHttpRequest ช่วยให้เรา Configuration params, XSRF Token, ใช้ความสามารถร่วมกับ RxJS</p><p>เปรียบเทียบกับเราใช้ native <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest">XMLHttpRequest</a> (xhr)xhr.open(&#39;method, url[, async[, user[, password]]]&#39;)​ ซึ่งเราต้องเข้าใจและเขียนโค๊ดเยอะ<br>หรือใช้ natvie <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">fetch</a> เล็กดี โค๊ดน้อย แต่เรามีข้อจำกัดคือไม่มี Upload Progress<br>หรือใช้ Library<a href="https://github.com/axios/axios">axios</a> ซึ่ง wrap xhr ซึ่งเขียนน้อยกว่า native xhr แต่ไม่ได้ใช้ความสามารถของ RxJS เช่น debounceTime, Type Ahead (switchMap) ถ้าจะทำต้องเขียนเองอีก</p><p>สุดท้ายแล้วเราต้อง<strong>ชั่งน้ำหนัก</strong>(Trade-off) เองว่าเราเขียนโค๊ดเองเราควบคุมปริมาณโค๊ดที่เราเขียนได้เพราะเรารู้ว่าใช้แค่ไหน Customize เองได้ แต่แลกมาด้วยเวลา ที่เราต้องเขียนเพิ่มเองและต้องเขียนเป็นด้วย <br>แล้วบางกรณีคือเขียนเองเกือบทุก use-case เท่ากับว่า ทำ Library ขึ้นมาเองเลย<br>แล้วทำไมเราไม่ใช้เครื่องมือที่เค้าให้มาอยู่แล้วหละ? จัดการ Router เองคงไม่สนุก, ทำ Dynamic Reactive Form Validation เองคงเหนื่อย</p><p>แต่ถ้า Library ถูกเขียนให้ดีพอที่ทำให้ Bundler, Minifier รู้ว่าส่วนนี้ไม่ได้ถูกเรียกให้เอาออกไป เราก็จะได้ใช้ข้อดีข้อทั้งสองด้านคือเขียนน้อยและ JavaScript เล็กโหลดไม่นาน</p><p>มีเทคนิคอื่นที่ช่วยให้โหลดเร็วมากขึ้นคือ<br>Lazy-loading Feature Moduleโหลดเฉพาะสิ่งจำเป็นตอนแรก อะไรไม่จำเป็นเอาไว้โหลดทีหลัง</p><p>การทำ <strong>Server Side Rendering (SSR) with Rehydration</strong> โดยใช้ <br><strong>Angular Universal</strong> ช่วยได้เช่นกันเพื่อให้ User เห็น <strong>First Contentful Paint (FCP) </strong>ก่อน(ได้แค่เห็น) แต่สุดท้ายแล้ว <strong>Time-to-Interactive (TTI)</strong> นานขึ้นไปอีก ถ้าเทียบกับการใช้ Angular ธรรมดา <strong>(Client-Side-Rendering)</strong> เพราะต้องรอทั้ง Server Side Rendering และ Client Side Rendering</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lnQ50XoC1eaKwigc.png" /><figcaption><a href="https://developers.google.com/web/updates/2019/02/rendering-on-the-web#rehydration-issues">https://developers.google.com/web/updates/2019/02/rendering-on-the-web#rehydration-issues</a></figcaption></figure><ul><li>ค้นหาแล้วเจอเลย (SEO — Search Engine Optimization )</li></ul><p>เว็บอะไรบ้างต้องค้นหาใน Search Engine แล้วเจอเป็นเว็บแรกอยู่ข้างบนๆ ซึ่งเหมือนเดิมส่วนใหญ่จะเป็นเว็บข่าว, เว็บซื้อขาย-ของ(E-Commerce), เว็บดูหนัง, Website ให้รายละเอียดทั่วไป</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DOQYdXm_LA_xp--n.png" /><figcaption><a href="https://developers.google.com/web/updates/2019/02/rendering-on-the-web#wrapup">https://developers.google.com/web/updates/2019/02/rendering-on-the-web#wrapup</a></figcaption></figure><p>แล้วอะไรบ้างที่ทำให้<strong>ค้นหาแล้วเจอเลย (SEO) </strong>มีหลายปัจจัยที่มีผล (Ex. Backlink, Google PageRank Algorithm — Makrov Chains Model)<br>แต่เราจะพูดในเชิง Technical Frontend เป็นหลัก</p><ul><li>โหลด<strong>ตอนแรกเร็ว</strong> (เห็น HTML DOM ไวๆ) ซึ่งวิธีแก้คือตามที่กล่าวไว้แล้ว</li></ul><p>ถึงแม้ว่า Google บอกว่าตอนนี้ Google Bot ใช้ Chrome Version ล่าสุดซึ่ง Run JavaScript ได้แล้วได้แล้วตั้งแต่เดือนพฤษภาคมปีที่แล้วในงาน Google I/O 2019<br><a href="https://developers.google.com/search/blog/2019/05/the-new-evergreen-googlebot">The new evergreen Googlebot | Google Search Central Blog</a></p><p>แต่ยังมีข้อจำกัดบางอย่าง อ่านรายละเอียดเพิ่มเติมได้ที่ <br><a href="https://developers.google.com/search/docs/guides/fix-search-javascript">Fix Search-related JavaScript problems | Google Search Central</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qNhsfXXTkMYM8O_q.png" /><figcaption><a href="https://web.dev/javascript-and-google-search-io-2019/#learn-how-googlebot-works">Making JavaScript and Google Search work together (web.dev)</a></figcaption></figure><p>ถ้าให้ดีที่สุดคือ Google Bot ควรจะไม่รันหรือรัน JavaScript น้อยมากๆเพื่อให้ได้มาซึ่ง Rendered HTML</p><p><em>Another example would be requiring JavaScript to render the links can lead to a slower discovery of these links. — web.dev</em></p><blockquote>อะไรที่มัน staticได้ก็ให้มัน staticไป</blockquote><h3>Server Side Rendering (SSR) with Rehydration</h3><p>เป็นหนึ่งในเทคนิคที่เราสามารถ<strong>ใช้ความรู้เดิมจาก</strong>การทำ Client Side Rendering บวกกับ SSR เพิ่มเข้าไป<br>ให้ Server Render HTML พร้อมใช้แล้วส่งไปยัง Browser ที่ขอมาซึ่ง User หรือ Google Bot จะเห็น HTML บนจอ แต่ระหว่างนั้นโหลด JavaScript ตัว Client Side เพื่อให้ User สามารถใช้งาน Application ได้ทั้งหมดเมื่อโหลดเสร็จ</p><p>ในมุมมองผมทำ Server Side Rendering (SSR) with Rehydration ใช้ Next.js ดีกว่าเครื่องมือเรื่อง SSR ครบเช่น Image Optimization, AMP Support, Localization, sitemap และอีกทั้ง Collaborate กับ Chrome Team อย่างจริงจัง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*EfIbFJOzb7Z3QmIh4wpH0g.png" /><figcaption><a href="https://github.com/angular/universal">angular/universal: Server-side rendering and Prerendering for Angular (github.com)</a></figcaption></figure><p>ถึงแม้ว่า Angular มี Official Library <a href="https://angular.io/guide/universal">Angular Universal</a> สำหรับทำ SSR ทำงานได้ตามปกติ แต่ความเห็นส่วนตัวของผมคือมันยังไม่สุด เครื่องมือไม่สู้ SSR ตัวอื่นๆ, ใช้ 3rd Party Library ที่ Access DOM ตรงอาจจะมีปัญหาได้, ต้องมานั่ง Handle isPlatformBrowser หรือisPlatformServerต้องระวังมากๆในการ Access Native DOM และ Developer Experience (DX)ไม่ค่อยดี หลายคนบ่นเหมือนกัน</p><p>สรุปคือผมแนะนำว่าใช้ Tools อื่นดีกว่าสำหรับ Server Side Rendering (SSR) with Rehydration (เรื่องนี้ใครไม่เห็นด้วย Comment โต้เถียงให้เหตุผลได้เลยครับ)</p><h3>Prerendering</h3><p>เป็นหนึ่งในเทคนิคที่เราสามารถ<strong>ใช้ความรู้เดิมจาก</strong>การทำ Client Side Rendering แล้วแปลงมันเป็น Static HTML พร้อมใช้เลยตั้งแต่ตอน Build แล้วไปวาง Static File นี้บน Hosting โดยที่ Browser<strong> แทบไม่ต้องรัน</strong> JavaScript เพื่อให้ได้ซึ่ง HTML (ลดเวลา)</p><p>แนะนำว่าทำ Prerendering ใช้ Gastby.js, Eleventy (Google ใช้เช่น <a href="https://web.dev/">web.dev</a>, <a href="https://developer.chrome.com/">Chrome Developers</a>) เครื่องมือครบกว่า</p><p>ใน Angular Ecosystem พอมี Static Site Generator สำหรับทำ Prerendering อยู่ชื่อว่า Scully — <a href="https://github.com/scullyio/scully">Static Site Generator for Angular</a> มันยังใหม่มากเริ่มมีเครื่องมือที่คนสร้างขึ้นแล้วแต่เครื่องมือยังไม่เยอะเท่า Gastby.js, Eleventy <br>อย่างไรก็ดีในไทยมีคนใช้ Scully ใน Production แล้ว (<a href="https://github.com/flowaccount/nx-plugins">flowaccount/nx-plugins: Nx plugins built by FlowAccount team, helps deploy systems to the cloud (github.com)</a></p><p>เราไม่จำเป็นที่จะต้องใช้ Angular หรือ Tools อื่น เช่น Next.js ในการที่จะทำ Web Application หรือ Website <strong>ทั้งหมด ทุกส่วน</strong><br>เราสามารถใช้ <strong>Next.js (SSR) </strong>หรือ <strong>Eleventy (Prerendering) </strong>ทำหน้า Landing Page เพื่อความเร็วในการโหลดหน้าแรกและ SEO <br>แล้วพัฒนา Web Application ด้วย <strong>Angular</strong> ในส่วนหลัง User Login เพราะเราไม่ได้ต้องการ <strong>SEO </strong>หรือเรา<strong>รับได้ที่มันจะโหลดเร็วไม่เท่า Server Side Rendering </strong>และรีดความสามารถของเครื่องมือที่ครบใน Angular</p><p>ปัจจุบันมี Tools สำหรับจัดการการสร้าง Apps หลายๆแอพโดยต่างเทคโนโลยีเช่นมีทั้ง Angular และ Next.js ใน Repository เดียวกันชื่อว่า <a href="https://nx.dev/angular.">Nx — Extensible Dev Tools for Monorepos</a> ช่วยเราได้</p><blockquote>ผมยินดีมากที่ทุกท่านจะใช้บทความนี้ในการโน้มนาว CTO, Tech Lead, Senior Engineer ในการพิจารณาเลือกใช้เครื่องมือซึ่งคือ Angular ตามโจทย์หรือปัญหาของธุรกิจของท่าน</blockquote><p>ก่อนจากกันไปของฝากไว้ว่า</p><blockquote>แต่ละแนวคิดมีข้อดีข้อเสียของมัน ต้องเลือกให้เหมาะกับงาน</blockquote><p><strong>ประวัติของผู้เขียน </strong><br>Siwat Kaolueng เป็นที่ปรึกษาเรื่อง Web และ Angular ให้กับองค์กรขนาดใหญ่ไม่ว่าจะเป็นบริษัทรับทำการตลาด, บริษัทพลังงานชื่อดัง<br>โดยความตั้งใจคือส่งมอบวิธีการ แนวคิด เครื่องมือ และลงมือปฏิบัติร่วมกับทีมพัฒนา เพื่อให้ Web Application <strong>สร้างได้เร็ว ดูแลต่อง่าย และใช้งานได้อย่างมีประสิทธิภาพ</strong></p><p>สนใจให้ขอคำปรึกษา(Consulting) หรือพัฒนา Skill คนในทีม (Training) ติดต่อได้ที่ <a href="/service/mailto:siwat.kaolueng@gmail.com"><strong>siwat.kaolueng@gmail.com</strong></a> หรือ<strong> </strong><a href="https://www.facebook.com/siwat.kaolueng"><strong>Facebook JaMe Siwat Kaolueng</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64a5e33220a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[มีอะไรใหม่ใน Angular 11 และอะไรกำลังจะมา (What’s new, What’s next in Angular 11)]]></title>
            <link>https://perjerz.medium.com/%E0%B8%A1%E0%B8%B5%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B9%83%E0%B8%AB%E0%B8%A1%E0%B9%88%E0%B9%83%E0%B8%99-angular-11-%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3%E0%B8%81%E0%B8%B3%E0%B8%A5%E0%B8%B1%E0%B8%87%E0%B8%88%E0%B8%B0%E0%B8%A1%E0%B8%B2-whats-new-what-s-next-in-angular-11-256d9fe063fc?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/256d9fe063fc</guid>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 03:41:24 GMT</pubDate>
            <atom:updated>2020-12-04T11:46:25.669Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Original Link: </strong><a href="https://perjerz.netlify.com/post/th-what-new-in-angular-11">https://perjerz.netlify.com/post/th-what-new-in-angular-11</a> (soon)</blockquote><p>ในบทความนี้จะบอกคุณเกี่ยวกับ</p><ul><li>การออก Version ใหม่ใน Angular</li><li>ของใหม่ใน Angular 11 (New) ที่น่าสนใจ</li><li>ของที่กำลังจะมา (Coming soon) ที่น่าสนใจ</li></ul><p>มาเริ่มกันเลย</p><h3>การออก Version ใหม่ใน Angular</h3><p>ขณะนี้เป็นเวลา 4 ปีแล้วครับที่ Angular อยู่กับเรามาและในวันที่ 14 กันยายนเป็นวันคล้ายเกิดของ Angular</p><h3>แฮปปี้เบิร์ดเดย์ย้อนหลังนะแองกูล่า <a href="https://emojipedia.org/a-button-blood-type/#:~:text=Emoji%20Meaning,symbol%20representing%20Blood%20Type%20A.&amp;text=A%20Button%20(Blood%20Type)%20was,to%20Emoji%201.0%20in%202015.">🅰️</a>🎂<a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=&amp;ved=2ahUKEwi1nf6E_JPtAhUU62EKHTb1BuEQFjATegQIFBAC&amp;url=https%3A%2F%2Femojipedia.org%2Fparty-popper%2F%23%3A~%3Atext%3DEmoji%2520Meaning%26text%3DLike%2520%25F0%259F%258E%258A%2520Confetti%2520Ball%252C%2520commonly%2Cto%2520Emoji%25201.0%2520in%25202015.&amp;usg=AOvVaw1KhOVs9hJfoCqKmUIjASwq">🎉</a><a href="https://emojipedia.org/partying-face/">🥳</a></h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FncBm8g9Ptag%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DncBm8g9Ptag&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FncBm8g9Ptag%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/61263a7c90f2af92eb0de9feef8ac4a2/href">https://medium.com/media/61263a7c90f2af92eb0de9feef8ac4a2/href</a></iframe><p><strong>Angular 2.0 </strong>ถูก Release ในวันที่ 14 กันยายน 2014 โดยการ Release ถูกแบ่งเป็น 3 ส่วนคือ major.minor.patchเช่น เวอร์ชั่น 7.2.11 หมายถึง</p><ul><li>Major Version 7 — หมายถึงการเปลี่ยน Version ที่มีฟีเจอร์ใหม่ โดยที่พวกเราต้องรัน Script บางอย่าง, แก้ Code, ทดสอบ(Test) และเรียนรู้ API ใหม่</li><li>Minor Major 2 — หมายถึงการเปลี่ยน Version ที่มีฟีเจอร์ใหม่ขนาดเล็กถูกพัฒนาเพิ่มเข้าไปมี Backward Compatable แก้ Code เล็กน้อยเพื่อใช้ API ใหม่</li><li>Patch level 11 — หมายถึงการเปลี่ยน Version ที่แค่แก้บัค ไม่ต้องแก้ไข Code</li></ul><h3>Preview releases</h3><p>Angular จะปล่อย Preview อะไรที่กำลังจะมาโดยแบ่งเป็น 2 ประเภทคือ Next และ Release Candidates (rc) สำหรับ Major และ Minor Release โดย</p><ul><li>Next — อยู่ระหว่างการพัฒนาและทดสอบโดย tag ต่อท้ายด้วย-next เช่น 8.1.0-next.0</li><li>Release candidate — Feature สมบูรณ์อยู่ในช่วงทดสอบสุดท้ายโดย tag ต่อท้ายด้วย-rc เช่น8.1.0-rc.0</li></ul><p>Document ล่าสุดของ Versionnext หรือrc อยู่ที่ <a href="https://next.angular.io/">next.angular.io</a>.</p><h3>Release Cycle</h3><ul><li>ทุก 6 เดือน Major Version จะถูกอัพเดท</li><li>มี 1–3 Minor Version สำหรับ Major Release</li><li>Patch release และ pre-release (next or rc) ถูกปล่อยเกือบทุกสัปดาห์</li></ul><h3>Support policy and schedule</h3><p>มาพูดถึงการ Support แก้บัคต่างๆกันบ้าง</p><p>ทุก Major release ถูกดูแลเป็นเวลา 18 เดือน</p><ul><li>6 เดือนแรก จะเป็น <em>active support </em>จะเป็นการออก updates and patches ปกติ</li><li>12 เดือนต่อมาจะเป็น <em>long-term support (LTS) </em>โดยแก้บัคเฉพาะช่องโหว่ความปลอดภัยหรือ Regression ที่เกิดจาก 3rd Party เช่น Browser ออก Version ใหม่</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*76p8os4oOVVXNjaDQ-gOjQ.png" /><figcaption><a href="https://angular.io/guide/releases#support-policy-and-schedule">Angular — Angular versioning and releases</a></figcaption></figure><p>Angular versions ^4.0.0, ^5.0.0, ^6.0.0 and ^7.0.0 ไม่ได้ถูก Support แล้ว</p><h4>จากตารางจะเห็นได้ว่า Version 8 จะหมด LTS ในวันที่ 28 พฤศจิกายนี้ต้องรีบอัพกันแล้วนะครับ ไม่ต้องพูดถึง 4,5,6,7 หมด LTS ไปนานแล้ว</h4><h4>ในขณะที่ทุกท่านกำลังเขียนโค๊ดกันอยู่ Hacker ก็ทำงานอยู่เหมือกันครับ คือหาช่องโหว่ ซึ่ง Hacker อาจเจอช่องโหว่ใน Dependency เก่าๆที่ Angular ใช้แล้วโจมตีทำให้ Web Application หรือธุรกิจท่านเสียหายได้</h4><p>อ่านข้อมูลเพิ่มเติมได้ที่ <a href="https://angular.io/guide/releases">Angular — Angular versioning and releases</a></p><h3>ของใหม่ใน Angular 11 (New)</h3><h3><strong>TypeScript</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aUuP1qy0nJ0cj4o8tRJJtA.png" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html</a></figcaption></figure><p><strong>TypeScript 4.0 </strong>เวอร์ชั่นเกือบล่าสุดมาแล้ว Version 4.0 นี้มีฟีเจอร์ที่น่าสนใจเช่น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*IdFPaGOzhdbCkYBbCCuCiw.png" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4%E2%80%930.html#variadic-tuple-types">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4–0.html#variadic-tuple-types</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*IdFPaGOzhdbCkYBbCCuCiw.png" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4%E2%80%930.html#variadic-tuple-types">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4–0.html#variadic-tuple-types</a></figcaption></figure><ul><li><strong>Variadic Tuple Types</strong> (Variadic แปลได้ประมาณว่ารับได้หลายตัวๆ)<br><a href="https://en.wikipedia.org/wiki/Variadic">Variadic — Wikipedia</a> กล่าวคือตอนนี้ ใช้ Spread (…) กับ Generic ได้<br>ที่เมื่อก่อนต้องเขียน Overload กันเหนื่อย</li><li><strong>Labeled Tuple Elements</strong> ตั้งชื่อใน Tuple ได้</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eFbxFSZhY6KE96YO.gif" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements</a></figcaption></figure><ul><li><strong>unknown on catch Clause Bindings</strong><br>ทำให้ e ใน catch เป็น unknown แทน any เพื่อสร้างความเข้มงวดโดยให้เราไป type narrowing ใน runtime</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*MDMziZzLcAKefgtFQFeQiw.png" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#unknown-on-catch-clause-bindings</a></figcaption></figure><ul><li><strong>Short-Circuiting Assignment Operators </strong><strong>&amp;&amp;=, </strong><strong>||=, and </strong><strong>??=</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*cJuASAE3LXKyyCVwVXLd0w.png" /><figcaption><a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#short-circuiting-assignment-operators">https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#short-circuiting-assignment-operators</a></figcaption></figure><p>เหมือน += -=</p><ul><li><strong>/** </strong><a href="http://twitter.com/deprecated"><strong>@deprecated</strong></a><strong> */ Support</strong><br>support /** @deprecated * JSDoc comment แล้วขีดฆ่าให้ด้วย</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PdbYXMV4-PAW1SSk.png" /></figure><ul><li><strong>Convert to Optional Chaining</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PDc3zpQuh9O3x2DU.gif" /><figcaption><a href="https://typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#convert-to-optional-chaining">https://typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#convert-to-optional-chaining</a></figcaption></figure><p>และฟีเจอร์อื่นๆ<br><strong>อ่านต่อได้ที่</strong> <a href="https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html">TypeScript: Documentation — TypeScript 4.0 (typescriptlang.org)</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gS3zIU3GNztBFCIIZNcmfQ.png" /><figcaption><a href="https://github.com/angular/angular/pull/39571#pullrequestreview-538074021">https://github.com/angular/angular/pull/39571#pullrequestreview-538074021</a></figcaption></figure><p>ส่วน TypeScript 4.1 เพิ่ง merge ไปสดๆร้อนๆ รอออ Release Version ต่อไป</p><h3>Angular CLI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rXXfLzj2WbnLADbHnNKMkQ.png" /></figure><ul><li>Angular Team เคลมว่า build ngcc ทุกครั้งที่เรา npm install (แปลง Code Libray ViewEngine เป็น Ivy Compatable) ได้เร็วขึ้น 2–4x faster และ Compile เร็วขึ้นด้วยความสามารถของ TypeScript 4.0</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bw5k5XE3PEKmkUZUx0in-A.png" /><figcaption><a href="https://blog.angular.io/version-11-of-angular-now-available-74721b7952f7">Version 11 of Angular Now Available | by Mark Techson | Nov, 2020 | Angular Blog</a></figcaption></figure><ul><li>ตอน ng serve port ถูกใช้แล้วหรอ? ปัญหานี้จะหมดไปเพราะ Angular CLI จะถามว่าใช้ port อื่นแทนไหม</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b9MT4nmqWhFYvhVbhXdBlQ.png" /><figcaption><a href="https://twitter.com/manekinekko/status/1327733156838043648/photo/1">https://twitter.com/manekinekko/status/1327733156838043648/photo/1</a></figcaption></figure><ul><li>หลัง ng build เสร็จรายงานผลลัพธ์ของ Chunks ไฟล์แบ่งประเภท จัดตารางให้อ่านง่ายขึ้น</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hEenu5a2BW9dJkep_ck0-A.png" /></figure><h3>Lint</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7ADs7aWzO1C9X04Sck2iw.png" /></figure><ul><li><strong>Lint, Linter</strong> — static code analysis tool used to flag programming errors, bugs, stylistic errors, and suspicious constructs — Wikipedia ง่ายคือเป็นเครื่องมือไว้หา error ใน code เพราะมนุษย์ทำงานผิดพลาดได้<br>ใช้คอมพิวเตอร์หรือโปรแกมหาความผิดพลาดให้เราดีกว่าซึ่ง Angular Team กำลังจะเลิกใช้ TSLint</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oEzyq6rb66Dpel_QZWNjIA.png" /><figcaption><a href="https://github.com/palantir/tslint/issues/4534">https://github.com/palantir/tslint/issues/4534</a></figcaption></figure><p>ซึ่ง TSLint จะ deprecated แบบสุดแล้วธันวาคมนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a9xwwO7E8Gl09TzYwwN1Fw.png" /><figcaption><a href="https://github.com/angular/angular-cli/issues/13732#issuecomment-719724640">https://github.com/angular/angular-cli/issues/13732#issuecomment-719724640</a></figcaption></figure><ul><li>ในอนาคตดูเหมือนว่า Angular Team จะไม่ Default ลง Linter มาให้โดยให้ User ไปเลือกลง Lint ใช้เอง แต่ตอนนี้แนะนำให้ไปใช้ @angular/eslint<br><a href="https://github.com/angular-eslint/angular-eslint">angular-eslint/angular-eslint: Monorepo for all the tooling related to using ESLint with Angular (github.com)</a></li></ul><h3>Hot Module Replacement(HMR)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UVui2NqApQVI9CT-AsKIAg.png" /></figure><p>แก้โค๊ดเท่าไหน Build ใหม่แค่ Component นั้นๆ ใน Development หลายคนน่าจะเบื่อเวลาเราแก้ Code แล้วต้องรอให้ CLI Build Project ขึ้นมาแล้วหน้าจอก็จะ Refresh (Live Reload) จะเห็นภาพชัดมากๆในโปรเจคขนาดใหญ่ที่ Build นานมาก (ทำ Lazy Load ช่วยได้เช่นกัน) แต่ด้วยเทคโนโลยี Hot Module Replacement จะช่วยให้คุณไม่ต้องเสียเวลารอ Refresh ทั้งหน้า โดยที่ตรงที่คุณแก้จะถูกแก้ไขแค่ส่วนนั้น</p><p>ดูตัวอย่างได้ที่ <a href="https://www.youtube.com/watch?v=CMdNSYlEpZ0">Using HMR in Angular 11 — YouTube</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AG7FVGp9S3hOLV9b3QIYgA.png" /><figcaption><a href="https://medium.com/echohub/implementation-of-hmr-hot-module-replacement-to-angular-project-f7bca523bd16">https://medium.com/echohub/implementation-of-hmr-hot-module-replacement-to-angular-project-f7bca523bd16</a></figcaption></figure><p>โดยที่สมัยก่อนถ้าหากคุณจะใช้ HMR รูปภาพด้านบนคือ Code ที่คุณต้องเพิ่มและแก้ลงไปเพื่อใช้งาน HMR ซึ่งก็ทำให้หลายๆคนขี้เกียจ Setup (หนึ่งในนั้นคือผม)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OwU371UiblfnlWk1cI7meQ.png" /></figure><p>ด้วยพลังแห่ง Angular CLI 11 เพียงใช้คำสั่งด้านบนปสามารถใช้ HMR ได้เลย</p><h3>Trusted Type</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OeFhcnY-6xGRAYOKwVsH1Q.png" /><figcaption><a href="https://web.dev/trusted-types/">https://web.dev/trusted-types/</a></figcaption></figure><p>Trusted Type คือเครื่องมือที่จะมาช่วยป้องกันดักจับ DOM XSS (DOM Cross-site scripting) ซึ่ง DOM XSS คือช่องโหว่ความปลอดภัยติด OWASP 10 ที่เกิดขึ้นจากการที่ User ที่ใช้ Browser ส่งค่าอะไรบางอย่าง (ข้อความ input, URL จาก fragment #) เข้ามาที่ Browser เพื่อ Parse (เช่นeval()function เค้าถึงไม่แนะนำให้ใช้กัน, set .innerHTML)แล้ว Browser มันไปรัน JavaScript ที่ไม่พึงประสงค์ได้</p><p>ยกตัวอย่างเช่น เราสร้าง What You See Is What You Get (<strong>WYSIWYG)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*TmXQSrlSKoUbdu_f.png" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:Content_full.png">File:Content full.png — Wikimedia Commons</a></figcaption></figure><p>แล้วมี Hacker ส่งข้อความมาให้เรา บอกให้เราไปสร้างบทความนี้ให้หน่อย ซึ่งส่วนใหญ่ข้อความจะเป็น HTML เพราะใส่สีจัดตัวหนาได้ ข้อความนั้นยาวมาก เราไม่ได้ดูละเอียด โดยที่เค้าแอบฝัง Script บางอย่างลงไป &lt;script&gt;send me your all local storages&lt;/script&gt; ซึ่งเราก็กดปุ่มสร้างบทความ ซึ่งระบบนั้นอาจจะมีการ Preview ข้อความนั้นขึ้นมาโดยการ Parse HTML นั้นด้วยคำสั่ง .innerHTML = ข้อความมะกี๊ที่มี script แฝง โดยปราศจากการ <strong>Sanitization </strong>นำ script พวกนั้นออกก่อน<br>LocalStorage ของเราก็จะถูกส่งมาให้ Hacker นั้นทันที หรือถ้าแย่กว่านั้นระบบนี้เก็บข้อความนี้ไว้ใน Database โดยที่ไม่ได้ Sanitize แล้วมี User คนอื่นเข้ามาดูบทความนี้โดยที่หน้าแสดงบทความก็ยังคงต้องใช้ innerHTML = ข้อความนั้น ก็โดนขโมย LocalStorage เหมือนกัน</p><p>แล้ว Trusted Type เข้ามาช่วยยังไง กล่าวคือเมื่อ Browser เปิดฟีเจอร์นี้ Developer จะ<strong>ไม่สามารถ</strong>anElement.innerHTML = &#39;ข้อความนั้นแล&#39;; ได้ตรงๆอีก Browser จะฟ้อง Error</p><p>สิ่งที่ต้องทำก็คือไปครอบข้อความนั้นผ่าน Trusted Type ก่อนถึงจะสามารถใช้ข้อความนั้นได้ พูดง่ายคือใช้ Type System ป้องกัน XSS เข้าไป</p><pre>if (window.trustedTypes &amp;&amp; trustedTypes.createPolicy) { // Feature testing<br>  const escapeHTMLPolicy = trustedTypes.createPolicy(&#39;myEscapePolicy&#39;, {<br>    createHTML: string =&gt; string.replace(/\&lt;/g, &#39;&amp;lt;&#39;)<br>  });<br>}</pre><pre>const trustedHTML = escapeHTMLPolicy.createHTML(&#39;ข้อความที่มี Script&#39;);<br>console.log(escaped instanceof TrustedHTML);  // true<br>el.innerHTML = trustedHTML;  // &#39;&amp;lt;img src=x onerror=alert(1)&gt;&#39; // ผ่าน</pre><p>โดยที่ Trusted Type นั้น Support Chrome 83+ Version เก่ากว่านั้นต้องใช้ polyfills</p><p>สามารถติดตามสถานะได้ภาพด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POzqvO1oFmeKhJSCaHZyiQ.png" /><figcaption><a href="https://github.com/angular/angular/pull/39222">https://github.com/angular/angular/pull/39222</a></figcaption></figure><p>ปกติเวลาเรา binding เช่น [href], [innerHTML]=, interpolation {{}} Angular จะ escape หรือ sanitize ให้อยู่แล้ว แต่มี</p><blockquote>กรณีที่เราบอกเฮ้นาย Angular <strong>ไว้ใจ</strong>ค่าที่เราส่งไปได้ไม่ต้อง Sanitize นะ</blockquote><pre>abstract class <a href="https://angular.io/api/platform-browser/DomSanitizer">DomSanitizer</a> implements <a href="https://angular.io/api/core/Sanitizer">Sanitizer</a> {   <br><a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustHtml">abstract <strong>bypassSecurityTrustHtml</strong>(value: string): SafeHtml</a>   <br><a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustStyle">abstract <strong>bypassSecurityTrustStyle</strong>(value: string): SafeStyle</a>     <a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustScript">abstract <strong>bypassSecurityTrustScript</strong>(value: string): SafeScript</a>   <a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustUrl">abstract <strong>bypassSecurityTrustUrl</strong>(value: string): SafeUrl</a>   <br><a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustResourceUrl">abstract <strong>bypassSecurityTrustResourceUrl</strong>(value: string): SafeResourceUrl</a> <br>}</pre><p>เช่นกรณีก่อน upload รูป เราต้องการ Preview รูปนั้นก่อนซึ่งต้อง this.previewImage = URL.createObjectURL(event.target.files[0]); แล้วเราจะได้ blob:http//somewhere.com/abcdefg ที่ต้องไป binding กับ &lt;img src=previewImage /&gt; ซึ่งถ้าเราไม่ <a href="https://angular.io/api/platform-browser/DomSanitizer#bypassSecurityTrustResourceUrl"><strong>bypassSecurityTrustResourceUrl</strong></a><strong> <br></strong>Angular จะงงมันคืออะไรไอไม่เข้าใจต้องเป็น SafeResourceURL (extends จาก SafeValue) ใน console log มันจะแจ้ง</p><p>WARNING: sanitizing unsafe URL value blob:<a href="https://angular-blob-to-safe-url.stackblitz.io/a3b12df3-a1fe-4672-9f35-b3a857589dcc">https://angular-blob-to-safe-url.stackblitz.io/a3b12df3-a1fe-4672-9f35-b3a857589dcc</a> (see <a href="http://g.co/ng/security#xss">http://g.co/ng/security#xss</a>)</p><p>แล้วถ้าไปดู image src จะพบว่ายังเป็น unsafe:blob:<a href="https://angular-blob-to-safe-url.stackblitz.io/a3b12df3-a1fe-4672-9f35-b3a857589dcc">https://angular-blob-to-safe-url.stackblitz.io/a3b12df3-a1fe-4672-9f35-b3a857589dcc</a> (see <a href="http://g.co/ng/security#xss">http://g.co/ng/security#xss</a>) ทำให้รูปไม่ขึ้น</p><blockquote>ตัวอย่าง<br><a href="https://stackblitz.com/edit/angular-blob-to-safe-url-n3k768?file=src%2Fapp%2Fapp.component.ts">angular-blob-to-safe-url-n3k768 — StackBlitz</a></blockquote><p>สรุปแล้ว Angular ไปเกี่ยวไงกับ Trusted Type ผมเข้าไปอ่าน Source code แล้วพบว่าหลังจาก Sanitize เสร็จแล้วจะทำการ wrap Trusted Type ซึ่งถ้าวันนึง Browser เปิด Trusted Type default เราก็ไม่แทบต้องทำอะไร ใช้งานได้ปกติ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bO-J7xoELpovTS5U6BHpQw.png" /><figcaption><a href="https://github.com/angular/angular/blob/2ae3fa009e60f627112ed4108a831d176fb384fd/packages/core/src/sanitization/sanitization.ts#L43">angular/sanitization.ts at 2ae3fa009e60f627112ed4108a831d176fb384fd · angular/angular (github.com)</a></figcaption></figure><p>อ่านรายละเอียดเพิ่มเติมได้ที่ <a href="https://angular.io/guide/security">Angular — Security</a></p><h3>ของที่กำลังจะมา (Coming Soon)</h3><h3>Angular DevTools</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BaKjyChSGBt36jlMCBMW_w.png" /><figcaption><a href="https://youtu.be/fM0BjroWGws?t=20344">https://youtu.be/fM0BjroWGws?t=20344</a></figcaption></figure><p>Chrome Extension ใน Chrome Dev Tools พัฒนาโดยทีม Rangle กับ Angular Team โดย Minko Gechev (Software Engineer at Google) ออกมา Sneak Peek ให้ดูในงาน NG Rome ซึงรายละเอียดที่เปิดเผยออกมาคือมันถูกพัฒนาต่อยอดมาจาก <a href="https://augury.rangle.io/">Angular Augury (rangle.io)</a> ที่เอาไว้ debug Angular ซึ่งอัพเดทล่าสุดเมื่อธันวาคม 2019 ผมเคยใช้แล้วรู้สึกเฉยๆ ดูในโค๊ดเอาเองดีกว่า แต่คิดว่าก็เหมาะไว้ดูภาพรวม Project ได้ ซึ่งตัว Angular DevTools ที่ออกใหม่นี้ความเจ๋งที่เพิ่มเข้าไปคือสามารถ Profiling ดู Change Detection Cycle ได้เหมาะกับ App ที่ต้องการ Optimize Performance <br>ตอนนี้อยู่ใน Stage Prototype ยังไม่ได้กำหนดวันปล่อยของ รอต่อไป</p><h3>Experimental Webpack 5 Support</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8KPji_9pD6_qC1pkdqtRhA.png" /></figure><p>เปิดให้ลองใช้ Webpack 5 ได้เป็นแบบ Opt-in วิธีการคือใส่คำสั่งนี้ลงใน package.json</p><pre>&quot;resolutions&quot;: {<br>     &quot;webpack&quot;: &quot;5.4.0&quot;<br>}</pre><p>ถ้าใช้ yarn ก็ใส่คำสั่ง yarnแล้ว ng build --prodได้เลย</p><p>ถ้าใช้ npm ต้องลง npm-force-resolutions เพื่อล็อค Version Transitive Dependency (Dependency ของ Dependency) ที่เราระบุใน Resolutions</p><pre>npm install -D npm-force-resolutions</pre><p>แล้วใส่คำสั่งข้างล่างลงใน package.json แล้ว npm iจะใช้ได้</p><pre>...<br>&quot;preinstall&quot;: &quot;npx npm-force-resolutions&quot;,<br>...</pre><p>Webpack 5 เคลมตัวเองว่าดีขึ้นยังไงบ้าง</p><ul><li>Build เร็วขึ้นด้วย persistent caching</li><li>ปรับปรุง long term caching ด้วย algorithms/defaults ที่ดีขึ้น</li><li>ปรับปรุง tree shaking/better code generation ให้ดีขึ้น</li><li>ปรับปรุงให้เข้ากันได้ดีกับ Web platform</li></ul><p>แต่ก็มีประเด็นอยู่</p><p>สมัยก่อน Webpack สามารถรัน Node.js Module ใน Browser ได้ด้วยพลังแห่ง polyfills แต่เพราะ Ecosystem พัฒนาไป หลาย Module ถูกเขียนเพื่อสำหรับ Web แล้ว (ESM) Webpack 5 เลย poloyfills เพื่อลด bundle size ซึ่งทำให้บาง Module ที่อาจใช้ Node.js Module อยู่ใน Web หรือ Angular ใช้งานไม่ได้ นั้นจงเป็นเหตุผลที่ทีม Angular เปิด Webpack 5 เป็น Opt-in และ Angular Team ไม่แนะนำให้รัน Webpack 5 ใน Production</p><p>และนี่ก็คือสิ่งที่เกิดขึ้นตอน Build Angular Project แบบเปล่าไม่ได้ลงอะไรเพิ่ม (ng new) ด้วย</p><h3>Webpack 5 ใน Windows 10</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCt1_UafJDQwYNUQUOKJSQ.png" /></figure><h3>Webpack 4.44.2ใน OSX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ewIOGgsk4AWhCwZGU6UKmw.png" /><figcaption>Build ด้วย Webpack 4.44.2</figcaption></figure><h3>Webpack 5.4.0 ใน OSX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J_4wF8TcowbP5dnTdUUb1Q.png" /><figcaption>Build ด้วย Webpack 5.4.0</figcaption></figure><p>ใหญ่ขึ้น 23.65 kB ซะงั้น ?</p><p>รอไปก่อนครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4FosQtd4hHQX40wT-dxbYA.png" /><figcaption><a href="https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-module-federation-in-webpack-5/">The Microfrontend Revolution: Module Federation in Webpack 5 — ANGULARarchitects</a></figcaption></figure><h3>Module Federation</h3><p>เป็นอานิสงค์จาก Webpack 5 ที่สามารถให้เราใช้ฟีเจอร์นี้ได้ คำถามแล้วมันคืออะไรหละ</p><p>Module Federation คือการบอกว่าบางจุดใน Application เรานั้นยังมีจุดที่ยังไม่รู้ ณ เวลา Compile Time แต่เราจะโหลดอีก Module (เป็นอีกแอพย่อยหนึ่ง อาจจะมองว่า คล้ายๆแปะ iframe เข้ามา หรือหน้าแยกก็ได้) เข้ามา โดยที่ตอนโหลด Module เข้ามานั้น เราจะใช้ Dependency หรือ Library ร่วมกันที่มีอยู่แล้วใน Application หลักซึ่งทำให้ไม่ต้องโหลด Dependency ซ้ำซ้อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gaeJkytjWvqhD7hb0cePRw.png" /><figcaption><a href="https://github.com/angular-architects/module-federation-plugin/blob/main/packages/mf/README.md">https://github.com/angular-architects/module-federation-plugin/blob/main/packages/mf/README.md</a></figcaption></figure><p>ยกตัวอย่างเช่นจากรูปด้านบนเรามี Application run อยู่ที่ port 5000 แล้วในนั้นหน้าเรามี Application ย่อยที่อีกทีมพัฒนา port 3000(ทำ Microfrontend [แยกกันทำโดยอิสระจากกัน แต่ตอนรวมอาจจะมี Script บางอย่างเล็กน้อยเพื่อรวมกันได้])แล้วต้องการจะเอามาใส่ ซึ่งปกติใช้ iframe เราจะโหลด Bundle ซ้ำสองรอบทั้งของ Application หลักและ Application ย่อย แต่ Module Federation จะบอกให้เราระบุว่ามี Depedency ไหนบ้างที่ใช้ร่วมกันจะได้ไม่โหลดซ้ำซ้อน</p><p>อ่านรายละเอียดเพิ่มเติมได้ที่ <a href="https://www.angulararchitects.io/aktuelles/the-microfrontend-revolution-module-federation-in-webpack-5/">The Microfrontend Revolution: Module Federation in Webpack 5 — ANGULARarchitects</a></p><h3>Strictly Typed Reactive Forms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tv1OI2ODODycOlTz_VCfDw.png" /></figure><p>สิ่งนี้เป็นสิ่งที่ผมรอมานานแล้วกล่าวคือใช้ Type System มาลดความผิดพลาดในการสร้าง FormGroup, FormControl ได้เพราะตอนนี้เวลาเราจะเรียกใช้ FormControl จาก FormGroup เราใช้คำสั่ง form.get(&#39;key&#39;) ซึ่งมีโอกาสบ่อยมากที่เราพิมพ์ผิดใน key หรือ ตอนใช้ form.controls.key ใน template แล้ว Angular Language Service ยังไม่สามารถทำงานดักจับการพิมพ์ผิดของเราได้</p><p>ใน Angular Ecosystem พอจะมี Library ที่คนทำไว้อยู่บ้างแล้วเช่น</p><ul><li><a href="https://github.com/ngneat/reactive-forms">ngneat/reactive-forms: (Angular Reactive) Forms with Benefits 😉 (github.com)</a></li><li><a href="https://github.com/dirkluijk/ngx-typesafe-forms">dirkluijk/ngx-typesafe-forms: Because FormControl&lt;T&gt; is more awesome than FormControl! (github.com)</a></li></ul><p>แต่ความรู้สึกผมคือสิ่งนี้มันควรจะทำมาจาก Reactive Form เองไม่ต้องมีใครมาครอบมัน ผมเลยไม่ได้ใช้ Library ข้างนอก รอวันที่ Angular Team support และวันนั้นใกล้มาถึงแล้ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sAcLN_KLPi3QYoI5vpKubg.png" /><figcaption><a href="https://github.com/angular/angular/pull/38406">https://github.com/angular/angular/pull/38406</a></figcaption></figure><p>ติดตามสถานะได้จากลิงค์ด้านบน</p><h3>Optional NgModules</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PoDEkmQ8XDnLE4Pk0JhVzQ.png" /><figcaption><a href="https://github.com/angular/angular/issues/37904#issuecomment-731351748">https://github.com/angular/angular/issues/37904#issuecomment-731351748</a></figcaption></figure><p>NgModule เป็น Concept หนึ่งใน Angular ที่มือใหม่งงที่สุด ผมเคยงงมาก่อนเหมือนกัน มีหลายคนใน Ecosystem มีความเห็นว่าถกเถียงกันให้ NgModule ออกไป</p><p>ปัญหาของ NgModule คือทำหลายอย่างมากเกินไปกล่าวคือ</p><ul><li>บอก Compilation Scope ให้ Angular Compiler ซึ่งจำเป็นทั้งตอน Development และตอนเขียน Unit Testing เพื่อที่จะลอง Environment ทั้งหมดใน Component ว่าต้องการ Depedency อะไรบ้าง ต้อง Mock อะไรบ้าง (ซึ่งก็มีแนวคิดเอา Dependency ไปแปะใน Metadata ของ Component ชื่อว่า deps อ่านต่อได้ที่ <a href="https://github.com/angular/angular/pull/27481">feat(core): introduce local scope &amp; make NgModules optional in ivy by mgechev · Pull Request #27481 · angular/angular (github.com)</a> ซึ่งสำหรับผมว่าแยก Depedency ออกมาอีกไฟล์ที่นามสกุล .module.ts ดีกว่าไปรวมทุกอย่างใน .component.ts)</li><li>ใช้ในการ Code-Splitting หรือ Lazy Load Feature (แก้ด้วย component level code-splitting แทนได้อยู่ใน Roadmap)</li><li>Configure Dependency Injection (คิดว่า Angular Team ควรจัดการตรงนี้)</li><li>จัดกลุ่มของฟีเจอร์ (แก้ด้วยแนวคิด Workspace แทน แยก Apps, Library ออกจากกัน แทนได้)</li></ul><p>ส่วนตัวผมชอบแนวคิด NgModule ตัว NgModule เพิ่ม Declarative, Readability ในการบอกว่าใน Component นี้มี ใช้อะไรบ้างและให้ Component อื่นใช้อะไรบ้าง แต่แนวคิดนี้ต้องใช้ความขยันเล็กน้อยในการแยก 1 Component — 1 Module</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/879/1*UABjYETd4gYfikOtstw0kQ.png" /><figcaption><a href="https://twitter.com/mgechev/status/1330473521718435840">https://twitter.com/mgechev/status/1330473521718435840</a></figcaption></figure><p>ซึ่ง Angular Team บอกว่าในอนาคตคงมีทางออกทั้งสองฝั่งสำหรับคนที่ใช้ และไม่ใช้ NgModule</p><h3>Zone.js opt-out</h3><p>Zone.js คือสุดยอดความสะดวกสบายที่ทำให้ Angular Developer ไม่ต้องเขียนโค๊ดเพิ่มในการ Sync Angular &amp; DOM State เข้าด้วยกันผ่านการไปเรียก ChangeDetection (<a href="https://angular.io/api/core/ApplicationRef#tick">tick</a>) อีกที <br>Zone.js ไป Monkey Patching async method เช่น setTimeout/Promise/EventTarget/EventTask(change, input, blur, …)… <br>อ่านรายละเอียดเพิ่มเติมได้ที่ <br><a href="https://github.com/angular/angular/blob/master/packages/zone.js/STANDARD-APIS.md">angular/STANDARD-APIS.md at master · angular/angular (github.com)</a></p><p>ถ้าไม่มี Zone.js เราต้องคอย manual Sync Angular &amp; DOM (detectChange, tick) เอง โค๊ดเราจะเต็มไปด้วย detectChange, tick</p><p>ซึ่งการมี Zone.js ก็แลกมาด้วยกับ Bundle Size ของ Polyfills ที่ใหญ่ขึ้นเล็กน้อยและ Debug ยากขึ้นเพราะ Stack Trace มี Zone เข้ามาเกี่ยวข้อง</p><p>ซึ่งใน use case ทั่วไป ข้อมูลบนหน้าจอไม่เยอะมาก ไม่ซับซ้อน Zone.js ทำงานตามปกติ Sync state ให้เรา ผู้ใช้ไม่รู้สึกกระตุก แต่ใน use case ที่หน้าซับซ้อนเราก็อยากจะจัดการเองไม่อยากให้ Zone.js ซึ่งคือ JavaScript รันเพราะมัน Block UI</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XQDCapofvuQifGYX8n4SwA.png" /><figcaption><a href="https://angular.io/guide/zone#disabling-zone">Angular — NgZone</a></figcaption></figure><p>ทีม Angular ได้บอกวิธีปิด Zone.js ไว้แล้วแต่ความลำบากคือเราต้องจัดการ Change Detection ซึ่งทีม Angular กำลังออกแบบและเตรียมแผนให้กับคนที่จะออกจาก Zone.js ด้วยวิธีไม่ลำบากมาก ผมตั้งสมมุติฐานว่าใช้แนวคิด Reactive Push-base Architecture (RxJS, rx-state) แทนซึ่งก็ต้องไปเข้าใจ Reactive อยู่ดี</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EU_IdMrG4E_hy6_NOzVUmg.png" /><figcaption><a href="https://github.com/angular/angular/issues/38782#issue-697229614">Moving off of Zones and building to target ES2018. · Issue #38782 · angular/angular (github.com)</a></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jgMCE3VhT1EeGehTJFcgCA.png" /><figcaption><a href="https://github.com/angular/angular/issues/31730">angular with tsconfig target ES2017 async/await will not work with zone.js · Issue #31730 · angular/angular (github.com)</a></figcaption></figure><p>Zone.js ใน Angular มีปัญหาหนึ่งก็คือไม่สามารถขยับไป tsconfig build target ไป ES2017 ได้ (เพื่อใช้ความสามารถโดย Native Syntax ของ Browser) เพราะ native async/await ไม่สามารถถูก monkey patch ได้อย่างถูกต้อง เลยไปทำให้ RxJS ที่มีแผนจะขยับ target ไป ES2018 เพื่อลด Bundle Size และ Support AsyncIterable ไม่ได้ไปด้วย (ถ้า Angular จะใช้ RxJS version ใหม่) ตอนนี้ก็ได้แต่รอ</p><p>อ่านรายละเอียดเพิ่มเติมได้ที่ <a href="https://angular.io/guide/roadmap">Angular Roadmap</a></p><h3><strong>ประวัติของผู้เขียน</strong></h3><p>Siwat Kaolueng เป็นที่ปรึกษาเรื่อง Web และ Angular ให้กับองค์กรขนาดใหญ่ไม่ว่าจะเป็นบริษัทรับทำการตลาดและบริษัทพลังงานชื่อดัง<br>โดยความตั้งใจคือส่งมอบวิธีการ แนวคิด เครื่องมือ สถาปัตยกรรม และลงมือปฏิบัติร่วมกับทีมพัฒนา เพื่อให้ Web Application <strong>สร้างได้เร็ว ดูแลต่อง่าย และใช้งานได้อย่างมีประสิทธิภาพ</strong></p><p>สนใจให้ผมไปช่วยออกแบบสถาปัตยกรรม (Architecture) วิเคราะห์ แก้ปัญหา <strong>ทำ Web Application ที่ใช้ได้นานๆ</strong> หรือ<strong>พัฒนา Skill คนในทีม</strong>ติดต่อได้ที่ <a href="/service/mailto:siwat.kaolueng@gmail.com"><strong>siwat.kaolueng@gmail.com</strong></a> หรือ<strong> </strong><a href="https://www.facebook.com/siwat.kaolueng"><strong>Facebook JaMe Siwat Kaolueng</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=256d9fe063fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is NgModule?]]></title>
            <link>https://perjerz.medium.com/what-is-ngmodule-4178473e1f33?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/4178473e1f33</guid>
            <category><![CDATA[ngmodule]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Sun, 08 Dec 2019 15:48:08 GMT</pubDate>
            <atom:updated>2021-03-14T18:29:53.587Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*EWFPgTal8sBazVbN.png" /><figcaption>What is NgModule?</figcaption></figure><p>Orginal Blog: <a href="https://perjerz.netlify.com/post/en-what-is-ngmodule/">https://perjerz.netlify.com/post/en-what-is-ngmodule/</a></p><p>Welcome to Angular Fundamental Series 📚</p><p>The story behind this blog is that I saw the Chrome Dev Tools 🛠️error in my coworker’s screen. The error is</p><pre>Error: Template parse errors:<br>&#39;mat-tab&#39; is not a known element:<br>1. If &#39;mat-tab&#39; is an Angular component, then verify that it is part of this module.<br>2. If &#39;mat-tab&#39; is a Web Component then add &#39;CUSTOM_ELEMENTS_SCHEMA&#39; to the &#39;@NgModule.schemas&#39; of this component to suppress this message.</pre><p>“Did you forget to import MatTableModule into the feature module that you are developing?” I said.</p><p>After she checked, and she found that she didn’t import it. She then fixed it, and it works fine.</p><p>I keep this problem in my mind, and ask to my ex-coworker who often use Angular. “Do you really understand what <strong>NgModule</strong> is?”</p><p>He replied “I don’t really understand what <strong>NgModule</strong> is. I just know how to make it work.” 😱</p><p>Thus, I started this blog to clarify <strong>NgModule</strong>.</p><p>Let’s start.</p><h3>NgModule — Unit of Compilation &amp; Distribution</h3><p>NgModule is JavaScript Class enhanced behaviors with decorator namely<br><strong>@NgModule</strong>. <strong>@NgModule</strong> receives metadata object.</p><pre>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;</pre><pre><em>// @NgModule decorator with metadata object (declarations, imports, ...)</em><br>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p>What does <strong>NgModule</strong> do? NgModule receives metadata for</p><ol><li>Tell Angular Compiler how to compile Components, Templates, Directives, Pipes.</li><li>Define Components, Directives, Pipes to be public via metadata that is <strong>exports</strong> in order to let other modules access and exploit it.</li><li>Add Services or Providers for Dependency Injection in Component.</li></ol><p>Let’s see case 1,2 via the below example.</p><pre>@NgModule({<br>  imports: [<br>    CommonModule,<br>    FlexLayoutModule,<br>    BrowserAnimationsModule,<br>    MatCardModule,<br>    MatButtonModule,<br>    MatIconModule,<br>    MatProgressSpinnerModule,<br>  ],<br>  declarations: [<br>    CompanyCardComponent,<br>    TechToIconPipe,<br>    CompanyListComponent<br>  ],<br>  exports: [<br>    CompanyListComponent,<br>  ]<br>})<br>export class CompanyModule { }</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company.module.ts">CompanyModule’s full code</a></p><p>There are interesting metadatas — imports, declarations, exports.</p><p>However, the order will be exports, imports, and declarations respectively.</p><p><strong>exports</strong></p><p>Define Components, Directives, Pipes to be exported. After other modules import this module, it will understand this compilation scope.</p><p>For example, ModuleA import ModuleB, then everything being exported in ModuleB will be in compilation scope of ModuleA</p><p>Therefore, ModuleA can used exported Components, Directives, and Pipes in ModuleB.</p><p>The below example shows <strong>CompanyListComponent</strong> is exported in <strong>CompanyModule</strong></p><pre>@NgModule({<br>  ...,<br>  exports: [<br>    CompanyListComponent,<br>    <em>// XXXPipe,</em><br>    <em>// XXXDirective</em><br>  ]<br>})<br>export class CompanyModule { }</pre><p>Then, <strong>AppModule</strong> import <strong>CompanyModule</strong>.</p><pre>@NgModule({<br>  declarations: [<br>    AppComponent<br>  ]<br>  imports: [<br>    ...,<br>    CompanyModule,<br>    ...<br>  ],<br>  ...<br>})<br>export class AppModule { }</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.module.ts">AppModule’s full code</a></p><p><strong>AppComponent</strong> inside declarations understands <strong>CompanyListComponent</strong>. and it is able to use <strong>CompanyListComponent</strong> in its template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*g3hRLfbOHlFsNbFP.png" /></figure><p>Here is the example of <strong>AppComponent</strong> Template (app.component.html) uses &lt;angular-th-company-list&gt;&lt;/angular-th-company-list&gt; that is selector in <strong>CompanyListComponent</strong>.</p><pre>...<br>&lt;angular-th-company-list [companies]=&quot;companies$ | async&quot; [loaded]=&quot;loaded&quot;&gt;&lt;/angular-th-company-list&gt;<br>...</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.component.html">app.component.html’s full code</a></p><p><strong>imports</strong></p><p>imports other modules, then all Components, Pipes, Directives in that module will in the scope at Compile-time.</p><p>Providers registered in that Module can be used also at Run-time (Dependency Injection).</p><pre>@NgModule({<br>  imports: [<br>    CommonModule,<br>    FlexLayoutModule,<br>    BrowserAnimationsModule,<br>    MatCardModule,<br>    MatButtonModule,<br>    MatIconModule,<br>    MatProgressSpinnerModule,<br>    <em>// XXXModule</em><br>  ],<br>  declarations: [<br>    CompanyCardComponent, <em>// &lt;-- Here</em><br>    ...<br>  ],<br>  ...<br>})<br>export class CompanyModule { }</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company.module.ts#L24">CompanyModule’s full code</a></p><p>From above example, <strong>CompanyCardComponent</strong> (company-card.component.html) uses MatCard Component &lt;mat-card&gt;&lt;/mat-card&gt; and Directive fxLayoutAlign&lt;div fxLayoutAlign=&quot;center center&quot;&gt;</p><pre>&lt;mat-card fxLayout=&quot;column&quot; *ngIf=&quot;company&quot;&gt;<br>  ...<br>  &lt;div fxLayoutAlign=&quot;center center&quot; style=&quot;height: 300px&quot;&gt;<br>    ...<br>  &lt;/div&gt;<br>  ...<br>&lt;/mat-card&gt;</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-card/company-card.component.html#L1">company-card.component.html’s full code</a></p><p>To use mat-card (Component) and fxLayoutAlign (Directive), we have to tell Angular Compiler that we are going to use <strong>MatCardComponent</strong>, <strong>FxLayoutAlignDirective</strong>. In <strong>MatCardModule</strong> and <strong>FxLayoutModule</strong> have already exported it. Thus, we just imports <strong>MatCardModule</strong> and <strong>FlexLayoutModule</strong> to use it.</p><p>How’s about <strong>CommonModule</strong>? What does it actually do?</p><p><strong>CommonModule</strong> is important.</p><p><strong>CommonModule</strong> exports *ngIf, *ngFor, [ngClass], AsyncPipe (| async), CurrencyPipe (| currency) that why we can use all of it.</p><p><a href="https://angular.io/api/common/CommonModule">Read more about CommonModule</a></p><p>Other components such as <strong>MatButton, BrowserAnimationsModule, MatIcon, MatProgressBar</strong> have the same concept.</p><p>In order to use Angular form, <strong>FormsModule</strong> or <strong>ReactiveFormsModule</strong> has to be imported also.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*G7DjF4AERDxzUREl.png" /></figure><p><strong>declarations</strong></p><p>Define all Component, Directive, Pipe to tell Angular Compiler that we are going to use it. <strong>In this module scope only</strong></p><pre>@NgModule({<br>  ...<br>  declarations: [<br>    CompanyCardComponent,<br>    TechToIconPipe,<br>    CompanyListComponent,<br>    <em>// XXXDirective</em><br>  ],<br>  ...<br>})<br>export class CompanyModule { }</pre><p>From the above example,</p><p>Components (<strong>CompanyCardComponent, CompanyListComponent</strong>) and Pipes (<strong>TechToIconPipe</strong>) know each other because they are in the same compilation scope. Hence, they can use the others interchangably.</p><p><strong>CompanyCardComponent</strong> uses <strong>TechToIconPipe</strong> in the template.</p><pre>...<br>&lt;img *ngIf=&quot;tech | techToIcon as icon; else techText&quot;/&gt;<br>...</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-card/company-card.component.html#L24">company-card.component.html’s full code</a></p><p><strong>CompanyListComponent</strong> loops to create &lt;angular-th-company-card&gt;&lt;/angular-th-company-card&gt; via *ngFor in the template.</p><pre>...<br>&lt;angular-th-company-card *ngFor=&quot;let company of companies&quot; [company]=&quot;company&quot;&gt;&lt;/angular-th-company-card&gt;<br>...</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-list/company-list.component.html#L3">company-list.component.html’s full code</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/0*Bnn4723sfHaETC_H.png" /></figure><p><strong>providers</strong></p><p>After Angular Version 6.0, we can create Singleton Service by defining providedIn: &#39;root&#39; in metadata of @Injectable() to tell Angular register Service into Application Root. This process make compiler be able to Tree-shaking unused services.</p><pre>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class CompanyService {</pre><pre>  constructor(private http: HttpClient) { }<br>  getCompanies() {<br>    return this.http.get&lt;Company[]&gt;(&#39;/assets/data/companies.json&#39;).pipe(<br>      shareReplay(1));<br>  }<br>}</pre><p>Before Version 6.0, we registers services at module or component level.</p><pre>@NgModule({<br>  ...<br>  providers: [<br>    CompanyService,<br>    <em>// {</em><br>    <em>//   provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true</em><br>    <em>// },</em><br>  ],<br>  ...<br>})</pre><p><strong>forRoot, forChild, forFeature, forXXX, xxx is ModulewithProviders</strong></p><p>Everyone may notice forRoot, forChild, forFeature, and so on. What is it? 🤔</p><pre>@NgModule({<br>  imports: [RouterModule.forRoot(...)],<br>  exports: [RouterModule]<br>})<br>export class AppRoutingModule {}</pre><pre>@NgModule({<br>  imports: [RouterModule.forChild(...)],<br>  exports: [RouterModule]<br>})<br>export class CompanyRoutingModule { }</pre><pre>@NgModule({<br>  imports: [<br>    StoreModule.forFeature(...),<br>    TranslateModule.forChild(...),<br>    EffectsModule.forFeature(...)<br>  ],<br>})<br>export class ExamplesModule { }</pre><pre>@NgModule({<br>  imports: [<br>    AngularFireModule.initializeApp(...),<br>    StoreModule.forRoot(...),<br>    StoreRouterConnectingModule.forRoot(),<br>    EffectsModule.forRoot(...),<br>    StoreDevtoolsModule.instrument(...),<br>    TranslateModule.forRoot(...)<br>  ],<br>})<br>export class AppModule { }</pre><p>It seems like to configure something. Right? Let’s check the example via AngularFireModule 🔥.</p><pre>@NgModule({<br>  imports: [<br>    AngularFireModule.initializeApp({<br>      apiKey: &#39;perjerzKey&#39;,<br>      authDomain: &#39;perjerz.app&#39;,<br>      projectId: &#39;perjerzId&#39;,<br>      databaseURL: &#39;https://perjerz.firebaseio.com&#39;,<br>      storageBucket: &#39;perjerz.appspot.com&#39;,<br>      messagingSenderId: &#39;1212312121&#39;,<br>      appId: &#39;1150&#39;,<br>    }),<br>    ...<br>  ],<br>})<br>export class AppModule { }</pre><p>Yes, it was used to configure. ✅ We can configure value in tokens and services to use Dependency Injection in component. Component will be able to use that values.</p><p>Let’s see the example via Setup AngularFire. Angular 🅰️ App want to talk to Firebase 🔥. Therefore, we have to configure where is the our Firebase.</p><p>The code below is AngularFireModule code from @angular/fire. It passes parameters to config providers — FirebaseOptionsToken and FirebaseNameOrConfigToken.</p><pre>const FirebaseAppProvider = {<br>    provide: FirebaseApp,<br>    useFactory: _firebaseAppFactory,<br>    deps: [<br>        FirebaseOptionsToken,<br>        [new Optional(), FirebaseNameOrConfigToken]<br>    ]<br>};</pre><pre>@NgModule({<br>    providers: [ FirebaseAppProvider ],<br>})<br>export class AngularFireModule {<br>    static initializeApp(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) { <em>// Pass options, nameOrConfig values here &lt;----</em><br>        return {<br>            ngModule: AngularFireModule,<br>            providers: [<br>                { provide: FirebaseOptionsToken, useValue: options },<br>                { provide: FirebaseNameOrConfigToken, useValue: nameOrConfig }<br>            ]<br>        }<br>    }<br>}</pre><p><a href="https://github.com/angular/angularfire2/blob/master/src/core/firebase.app.module.ts#L58">AngularFireModule’s full code</a></p><p>When we use Firebase services such as AngularFireDatabase, AngularFireAuth, we can use it directly without specifing apiKey, authDomain, and databaseURL every times. It has already resolved values from tokens that we configure (register) in the module.</p><pre>@Injectable()<br>export class AppGuard implements CanActivate {<br>  constructor(<br>    private db: AngularFireDatabase,<br>    private auth: AngularFireAuth,<br>    private router: Router,<br>  ) { }<br>   canActivate(): Observable&lt;boolean | UrlTree&gt; {<br>    return this.auth.authState.pipe(switchMap(user =&gt; {<br>        return this.db.object(`...`).valueChanges().pipe(...)<br>      }<br>   }<br>}</pre><p>In addition, newcomers are able to read configuration at the module easily.</p><p><a href="https://angular.io/guide/dependency-injection">Read more about Dependency Injection at angular.io</a></p><p><strong>entryComponents</strong></p><p>Define components to tell Angular Compiler that we are going to use these components explicitly for creating component factories, dynamic loading at Run-time (Imperatively). Please don’t tree Shake these components out.</p><p>For components that we use in the template &lt;angular-th-company-card&gt;&lt;/angular-th-company-card&gt;, Angular compiler understand how it be used because of referenceing. Angular compiler is then able to inline instantiation. (Statically, Declaratively)</p><p>However <a href="https://angular.io/guide/dynamic-component-loader">Dynamic Component Loader</a> (Load Component at Runtime) needs entryComponents.</p><p>The clear example is <a href="https://material.angular.io/components/dialog/overview#configuring-dialog-content-via-code-entrycomponents-code-">MatDialog</a> (Material Dialog). We have to explicitly define MatDialog component in order to open the dialog.</p><pre>@NgModule({<br>  imports: [<br>    <em>// ...</em><br>    MatDialogModule<br>  ],</pre><pre>  declarations: [<br>    AppComponent,<br>    ExampleDialogComponent<br>  ],</pre><pre>  entryComponents: [<br>    ExampleDialogComponent <em>// Must add this Component, however for Ivy, it is not neccessary anymore</em><br>  ],</pre><pre>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p>Another example is loading Component in Routes (RouterModule). It uses component factory also because of dynamic loading at runtime. However, we don’t have to define components in entryComponents because RouterModule do it for us during compilation.</p><pre>const routes: Routes = [<br>  {<br>    path: &#39;a&#39;,<br>    component: ComponentA<br>  },<br>  {<br>    path: &#39;b&#39;,<br>    component: ComponentB<br>  }<br>];</pre><pre>@NgModule({<br>  imports: [<br>    RouterModule.forRoot(routes)<br>  ],<br>  exports: [RouterModule],<br>})<br>export class AppRoutingModule {}</pre><h3>However, we don’t need entryComponents anymore in Ivy. Check below link</h3><p><a href="https://github.com/angular/angular/pull/33205">refactor(core): deprecate entryComponents #33205</a></p><p>The another interesting story is when we declare and export ComponentA, ComponentB, and Component C in ModuleA, then we import ModuleA into AppModule. However, we don’t use ComponentA, ComponentB, ComponentC in templates or controllers. The Angular Compiler will not include these components in the bundle.</p><p>For example, we use CustomMatModule that declares and exports MatButton and MatCard. Even though we import this CustomMatModule, we don’t need to pay bundle size’s cost if we don’t reference or use them in the template or controllers.</p><h3>However, my best practice is that I do always import what I actually needs. It will be difficult to know what dependencies we are using when project is complicated if we import all modules.</h3><pre>@NgModule({<br>  imports: [<br>    MatButtonModule,<br>    MatCardModule,<br>    ...<br>  ],<br>  exports: [<br>    MatButtonModule,<br>    MatCardModule,<br>    ...<br>  ], <em>// Even though these are exported, we don&#39;t have to pay if we not using it</em><br>  declarations: []<br>})<br>export class CustomMatModule { }</pre><p><strong>bootstrap</strong></p><p>Define Component to start the App (Bootstrap) — Root Component or AppComponent Bootstrap Component will be automatically added into entryComponents.</p><p>Here is the example in AppModule.</p><pre>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p><strong>schemas</strong></p><p>Define Schema to allow compilation scope in NgModule. There are two values — <a href="https://github.com/angular/angular/blob/master/packages/core/src/metadata/schema.ts#L38">NO_ERRORS_SCHEMA</a> and <a href="https://github.com/angular/angular/blob/master/packages/core/src/metadata/schema.ts#L29">CUSTOM_ELEMENTS_SCHEMA</a>.</p><p><strong>NO_ERRORS_SCHEMA — Tell Angular Compiler to allow all elements and properties</strong></p><p>For <a href="https://vsavkin.com/three-ways-to-test-angular-2-components-dcea8e90bd8d">Shallow Testing</a>, we want to test Angular Template by ignoring dependencies of components (Don’t care template errors about what dependencies they need)</p><p>We can configure module to make Angular components behaving as simple DOMs.</p><p>The below example is to prepare ConversationsCmp for shallow testing. We just want to test that it renders texts correctly. However, the parent of texts is &lt;mat-card&gt;&lt;/mat-card&gt; or MatCardComponent. We don’t really care it. We just want to check there is right text inside.</p><p>When we create TestBed, we have to configure the module with schemas NO_ERRORS_SCHEMA to ignore the error from not importing MatCardModule. Angular Compiler will be clear about the scope of MatCardComponent and the test is passed.</p><pre>&lt;mat-card *ngFor=&quot;let c of conversations | async&quot; [routerLink]=&quot;[c.id]&quot;&gt;<br>  &lt;h3&gt;<br>    &lt;a [routerLink]=&quot;[c.id]&quot;&gt;{{c.title}}&lt;/a&gt;<br>  &lt;/h3&gt;<br>  &lt;p&gt;<br>    &lt;span class=&quot;light&quot;&gt;{{c.user.name}} [{{c.user.email}}]&lt;/span&gt;<br>  &lt;/p&gt;<br>&lt;/mat-card&gt;</pre><pre>@Component({templateUrl: &#39;conversations.html&#39;})<br>export class ConversationsCmp {<br>  folder: Observable&lt;string&gt;;<br>  conversations: Observable&lt;Conversation[]&gt;;</pre><pre>  constructor(route: ActivatedRoute) {<br>    this.folder = route.params.pluck&lt;string&gt;(&#39;folder&#39;);<br>    this.conversations = route.data.pluck&lt;Conversation[]&gt;(&#39;conversations&#39;);<br>  }<br>}</pre><pre>describe(&#39;ConversationsCmp&#39;, () =&gt; {<br>  let params: BehaviorSubject&lt;string&gt;;<br>  let data: BehaviorSubject&lt;any&gt;;</pre><pre>  beforeEach(async(() =&gt; {<br>    params = of({<br>      folder: &#39;inbox&#39;<br>    });</pre><pre>    data = of({<br>      conversations: [<br>        { id: 1, title: &#39;On the Genealogy of Morals by Nietzsche&#39;, user: {name: &#39;Kate&#39;, email: &#39;katez@example.com&#39;} },<br>        { id: 2, title: &#39;Ethics by Spinoza&#39;, user: {name: &#39;Corin&#39;, email: &#39;corin@example.com&#39;} }<br>      ]<br>    });</pre><pre>    TestBed.configureTestingModule({<br>      declarations: [ConversationsCmp],<br>      providers: [<br>        { provide: ActivatedRoute, useValue: {params, data} }<br>      ],<br>      <em>// Tell compiler to not show error for unknown elements and attributes</em><br>      schemas: [NO_ERRORS_SCHEMA]<br>    });<br>    TestBed.compileComponents();<br>  }));</pre><pre>  it(&#39;updates the list of conversations&#39;, () =&gt; {<br>    const f = TestBed.createComponent(ConversationsCmp);<br>    f.detectChanges();</pre><pre>    expect(f.debugElement.nativeElement).toHaveText(&#39;inbox&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;On the Genealogy of Morals&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;Ethics&#39;);</pre><pre>    params.next({<br>      folder: &#39;drafts&#39;<br>    });</pre><pre>    data.next({<br>      conversations: [<br>        { id: 3, title: &#39;Fear and Trembling by Kierkegaard&#39;, user: {name: &#39;Someone Else&#39;, email: &#39;someonelse@example.com&#39;} }<br>      ]<br>    });<br>    f.detectChanges();</pre><pre>    expect(f.debugElement.nativeElement).toHaveText(&#39;drafts&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;Fear and Trembling&#39;);<br>  });<br>});</pre><p><strong>CUSTOM_ELEMENTS_SCHEMA — Tell Angular Compiler to allow Non-Angular elements and properties with dash case. Dash case is convention of custom elements</strong></p><p>Angular always understands that Custom HTML Tag is Angular Component. When it encounter weird elements that out of scopes, the compiler then throw the error. To use custom elements, we have to enable Angular Compiler compiler to understand custom elements.</p><pre>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from &#39;@angular/core&#39;;<br>import { ReactiveFormsModule } from &#39;@angular/forms&#39;;</pre><pre>import { AppComponent } from &#39;./app.component&#39;;</pre><pre>@NgModule({<br>  declarations: [AppComponent],<br>  schemas: [CUSTOM_ELEMENTS_SCHEMA] <em>// &lt;-- Here!</em><br>  imports: [BrowserModule, ReactiveFormsModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p><a href="https://vaadin.com/tutorials/using-web-components-in-angular">Read more about Custom Element in Angular</a></p><h3>Summary of NgModule</h3><ol><li>Tell Angular Compiler how to compile Components, Templates, Directives, Pipes</li><li>Define Components, Directives, Pipes to be public via metadata that is <strong>exports</strong> in order to let other modules access and exploit it.</li><li>Add Services or Providers for Dependency Injection in Component.</li></ol><p>Before ending this blog, I have a quiz ⚡ for you.</p><p>Angular App 🅰️ has been splited into feature modules already.</p><p>CEO 😎 want telephone’s input 📞 in Angular App to be masked from 0999999999 to 099–999–999 <strong>For every telephone’s input in the App</strong></p><p>We then search for the libraries in Google, and we found <a href="https://github.com/JsDaddy/ngx-mask">ngx-mask</a>. 👨💻</p><p>We have already installed npm install --save ngx-mask.</p><p>ngx-mask Github has installation guide by importing Module like below.</p><pre>import { NgxMaskModule } from &#39;ngx-mask&#39;</pre><pre>export const options: Partial&lt;IConfig&gt; | (() =&gt; Partial&lt;IConfig&gt;);</pre><pre>@NgModule({<br>  (...)<br>  imports: [<br>    NgxMaskModule.forRoot(options)<br>  ]<br>  (...)<br>})</pre><p>My question is where should import NgxMaskModule, and how?</p><ol><li>import NgxMaskModule.forRoot(options) at AppModule</li><li>import NgxMaskModule.forRoot(options) at AppModule and all Feature Module</li><li>import NgxMaskModule.forRoot(options) at AppModule and import NgxMaskModule at Feature Module</li><li>import NgxMaskModule at AppModule and all Featured Module</li><li>import NgxMaskModule at AppModule and import NgxMaskModule.forRoot(options) all Feature Module</li><li>import NgxMaskModule at AppModule</li></ol><p>And developers will be able to use below codes without error.</p><pre>&lt;input type=&quot;text&quot; mask=&quot;000-000-000&quot;&gt;</pre><pre>&lt;span&gt;{{phone | mask: &#39;000-000-0000&#39;}}&lt;/span&gt;</pre><p>Please share 🔗 this blog for other Angular members.</p><p>See you next article 👋. Bye. 🙏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/0*rFQLaRgrcpuD80vm.png" /></figure><p>This article uses<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4178473e1f33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recap Keynote Angular Connect Day 1 (English)]]></title>
            <link>https://perjerz.medium.com/recap-keynote-angular-connect-day-1-english-2ca7f0cea5a0?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ca7f0cea5a0</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angularconnect]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Fri, 15 Nov 2019 17:03:12 GMT</pubDate>
            <atom:updated>2019-11-15T17:03:12.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F8CO_5Qdr_KeW811.jpg" /><figcaption>Image credit: <a href="https://twitter.com/ankitsharma_007/status/1174607831263252480"><strong>@ankitsharma_007</strong></a></figcaption></figure><p>Hello, I am Jame from Angular Thailand. I am going to summarize the biggest Angular conference in Europe — Angular Connect 2019 Day 1 Keynote.</p><p>Let’s begin.</p><p>Keynote Angular Connect Day 1</p><p>Stephen Fluin — Developer Advocate, Angular Team, Google @stephenfluin</p><p>Igor Minar Angular Team Lead, Google @IgorMinar</p><p>Stephen Fluin introduced it was two years now since Angular 2 was released with ballons on 14 September 2014. And now AngularConnect has fifth Anniversary. 🎉🎂 Hooley!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tqdlBIoe0_crbc4o.JPG" /></figure><p>There are 7 new Angular conferences being organized around the world. The my nearest Angular conference is NG-MY (Malaysia 🇲🇾). I was a first time speaker there. 🎤</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G_8vU9hhcg272FpX.JPG" /></figure><p>ngGirls is the female Angular Community. 💃 You can check the link. <a href="http://ng-girls.org/">http://ng-girls.org/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AFRVN0h_mFik-Obb.JPG" /></figure><p>Now, it’s a community turn to share their case studies. The first case study was Deutsche Bank.</p><p>Rene Kriest — Head of Development for Public Websites</p><p>Florian Kittel — Lead Developer for Public Websites</p><p>Deutsche Bank has 60 apps to maintain. They have their business components and web editor using drag &amp; drop in order to create the website. There are live preview, one-click deployment, and versioning with their tools.</p><p>It was made by Angular with CLI, Schematics to scaffold files, Workspace to manage themes, and NodeJS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cdeKizNaRKe8HijL.JPG" /></figure><p>It’s time for Alianz.</p><p>Jochen Supper</p><p>It was two years now that they create the Alianz UI Library. They have learned something from adopting Schematics.</p><ol><li>Steep Learning Curve — To adopt ng update command with library, they need to understand Abstract Syntax Tree (AST)</li><li>Even though they have Schematics for ng update, some teams still did update manually. Therefore, they need to notify and teach about ng update.</li><li>For teams that using ng update command, they are happy.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sZ-u0d_ACG_njmlo.JPG" /></figure><p>Next story is about two different text inputs with two use cases.</p><ol><li>Text Input for B2C customers with float label animation (left)</li><li>Text Input for employees, staffs (experts) without animation (Right)</li></ol><p>It use different markups, so they have to write different conventions in documents.</p><p>Developer teams have to read carefully. Some didn’t. How to fix this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jORE66AoUUST4GUs.JPG" /></figure><p>The answer is Injection Token to configure input type. In another words, using code to configure instead of follow document convention.</p><p>The solution is to let the team that is responsible for making employee apps import NxExpertModule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rCr1hqf27Fv4StzY.JPG" /></figure><p>To summarize, Alianz has been transformed from</p><ul><li>Manual Update to Automate with Schematics (ng update, ng add)</li><li>Configure by Convention to Configure by Code</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5TabdWzyNPGrazyF.JPG" /></figure><p>NativeScript (Building Cross-platform mobile app with Native UI)</p><p>by Stanimira Vlaeva</p><p>Recently, there was NativeScript Hackathon making app for NGO.</p><p><a href="http://ng-ns.org/">Read more</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ztx6LkszAJFv3SII.JPG" /></figure><p>Ionic (Bulding Cross-platfor App with WebView) Mike Harington</p><p>Long time ago, Ionic team has create their own tools (CLI), Router, and best practices.</p><p>However, they have realized it was the too much investment. Until Ionic 4 released, they have used Angular ways.</p><p>For example, they use @angular/cli, @angular/router instead of @ionic/app-scripts, Ionic Router.</p><p>They also follow Angular Best Practices. In addition, they have extended Angular such as</p><ol><li>Extending Angular Router to be IonRouterOutlet with page transition animation</li><li>Extend Angular CLI for provide additional information to build iOS &amp; Android</li><li>Extending schematics to overrdie default command — ng generate page</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qL3o9dk8Sr33xB_q.JPG" /></figure><p>Capacitor — New Cordova</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ktJEwgnPcGZC7a4x.JPG" /></figure><p>Angular has announced Angular for Designer tool — UI Bakery. <a href="https://uibakery.io/">https://uibakery.io/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kDQK5LEhV6VooU6V.JPG" /></figure><p>Last year, there were 600+ Angular projects in Google.</p><p>Now, there are 1500+ Angular projects.</p><p>Firebase and Google Cloud Platform also use Angular.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gc6krWkqqkc3JjJQ.JPG" /></figure><p>There are 105 Angular GDEs around the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rvu610SeSlO9_P7-.JPG" /></figure><p>Angular has opened Angular Collaborators program.</p><ul><li>Jia Li maintains zone.js</li><li>Joost maintains compiler ngcc</li><li>and so many cool collaborators</li></ul><p>Thanks to all collaborators. 🙏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*n5qU7CvBT_YjCLVn.JPG" /></figure><p>Next stories will be technical updates from Igor Minar.</p><p>The major release cycle of Angular is every 6 months. Last majaor release was on May for version 8.</p><p>The upcomming release is in November for version 9.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*21LGARNMS0WOnXaf.JPG" /></figure><p>Let’s talk about new feature so far.</p><p>Differential Loading is building apps with two bundles.</p><ul><li>Modern browsers with less polyfills</li><li>Legacy browsers with several polyfills.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wuBGgl_owGIhH8gO.JPG" /></figure><p>With differential loading, angular.io size has been decreased 41 Kb (10%)</p><p>For most of the webs with Angular 8, the size has been decreased for 7–20%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dqTm70J3uOAHG6rG.JPG" /></figure><p>Building two times is slow, therefore, in CLI 8.3, CLI builds once but using downlevel instead. We get 45% faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pG2D1n56RgY3eWrX.JPG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pQki6pismy6tbCtX.JPG" /></figure><p>ng deploy is to deploy Angular app to various hosts such as Firebase, Azure, Netlify, and Github Pages.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u9-EYVIPzcqyZMhe.JPG" /></figure><p>The Angular hello world app by ng new has been redesigned. It looks cool! 😎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YOcE6Z-Xqixhyj-_.JPG" /></figure><p>There are more features in Angular 8.</p><ul><li>Lazy loading with import() syntax to following web standard</li><li>Custom Builders for customize build steps</li><li>Web Worker Bundling</li><li>AngularJS $location support to do hybrid AngularJS and Angular with same router</li><li>Better IDE support</li><li>New tutorial — Tour of heros and E-commerce for beginners</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r9oCWrde65ZvKWdu.JPG" /></figure><p>Ivy makes debugging easier by using Console Tab in Chrome Dev Tools with ng.getComponent($0) command to access Component directly and call methods during runtime. Awesome 👍👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WnBl5Y0E776hkmds.JPG" /></figure><p>With Angular v9.0.0-next.6, the small, medium, large app sizes are -30%, +10%, -40% respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t_B7oHonWWZPz4cx.JPG" /></figure><p>Ivy runtime uses the Assembly concept that has instruction sets.</p><p>There are many Ivy Instructions. e.g.</p><ul><li>Ivy Instruction opening and ending tag — elementStart, elementEnd</li><li>Ivy Instruction adds hello text into tag — text</li><li>Ivy Instruction for text interpolotion {{name}} — textInterpolate</li></ul><p>Each feature and each instruction that we use are included in runtime. If not, it will be not included.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hqy_y902BAz-MA1A.JPG" /></figure><p>View Enginer or Render v2 uses data structures converting during runtime, so the runtime needs all features, and impossible to tree shake those features that we don’t use it.</p><p>Ivy can tree-shake the unused features, thus, the bundle size is smaller.</p><p>You can learn more in this Youtube video.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fisb5Ef6yI48%3Fstart%3D221%26feature%3Doembed%26start%3D221&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Disb5Ef6yI48&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fisb5Ef6yI48%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/52e410e9581592a52d4798b85f286a36/href">https://medium.com/media/52e410e9581592a52d4798b85f286a36/href</a></iframe><p>There are 150 ivy instructions. More Ivy instructions, more tree-shaking unused features.</p><p>Ivy will be default in Angular Version 9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0lEgqPGv2_DobWTB.JPG" /></figure><p>The majority of libraries in npm ecosystem are compiled to support View Engine.</p><p>Ivy has ngcc (Angular Compatibility Compiler) to convert View Engine libraries to Ivy code. <a href="https://github.com/angular/angular/blob/master/packages/compiler/design/architecture.md#ngcc-operation">Read more about ngcc spec</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G1Rx4aiHGT-iyNdZ.JPG" /></figure><p>Libraries compiled by Ivy work fine with Ivy apps. For View Engine libraries, they need to be recompiled with ngcc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*opatlu7rNowZxZ9V.JPG" /></figure><p>In version 9, building apps are Ivy by default but building libraries are still View Engine.</p><p>In Version 10, the instruction sets tend to be stable. Building libraries will be Ivy to use ngcc less.</p><p>In Version 11 ngcc will be just a backup for legacy libraries that still use View Engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iqxNJLAlFvO8vGAk.JPG" /></figure><p>The report told that 85% of 173 well-known libraries are compatible with Ivy.</p><p>You can see the result in Github. <a href="https://github.com/angular/ngcc-validation">https://github.com/angular/ngcc-validation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HrnwHtRgbddG09QH.JPG" /></figure><p>Everyone can opt-out Ivy until Version 10.</p><p>If you want to try Ivy, use this command.</p><p>ng update @angular/cli@next @angular/core@next</p><p>Ivy has enabled a lot of new features.</p><ul><li>Style Merging <a href="https://github.com/matsko/ivy-styling-demo">https://github.com/matsko/ivy-styling-demo</a></li><li>Component Lazy Loading <a href="https://github.com/IgorMinar/ivy-lazy-load-component">https://github.com/IgorMinar/ivy-lazy-load-component</a> leading to Progressive Rehydration</li></ul><p>Learn more about Progressive Rehydration by Youtube below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFiVw6zjgw24%3Fstart%3D1272%26feature%3Doembed%26start%3D1272&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFiVw6zjgw24&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFiVw6zjgw24%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f27bc1ab5fff24667ce5156397451bc/href">https://medium.com/media/9f27bc1ab5fff24667ce5156397451bc/href</a></iframe><p>Finally, there are new ecosystems.</p><ul><li>ng add for adding libraries</li><li>ng update for updating apps and libraries</li><li>Custom Builders such as ngx-build-plus</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-w3QQu0jbzOzE-_r.JPG" /></figure><p>End. What do you think about new updates from Angular?</p><p>Please share this blog for other Angular members.</p><p>See you next article. Bye. 👋</p><p>Original Link: <a href="https://perjerz.netlify.com/post/en-recap-keynote-angular-connect-day-1/">https://perjerz.netlify.com/post/en-recap-keynote-angular-connect-day-1/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/0*jRGDs3jOl51DN_Da.png" /></figure><p>This article uses<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ca7f0cea5a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is NgModule?]]></title>
            <link>https://perjerz.medium.com/what-is-ngmodule-4e3e0ad862aa?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e3e0ad862aa</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[perjerz]]></category>
            <category><![CDATA[ngmodule]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Wed, 13 Nov 2019 15:52:55 GMT</pubDate>
            <atom:updated>2020-12-01T18:28:46.239Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*FZeBwPJp7U-TcvGA.png" /><figcaption>What is NgModule?</figcaption></figure><h3>อะไรคือ NgModule กันนะ</h3><p>ลิงค์ต้นฉบับ <a href="https://perjerz.netlify.com/post/th-what-is-ngmodule/">https://perjerz.netlify.com/post/th-what-is-ngmodule/</a></p><p>สวัสดีครับขอต้อนรับเข้าสู่ Angular Fundamental Series 📚</p><p>ที่มาของบทความนี้เกิดจากผมได้มีโอกาสเข้าไปเขียนโค๊ดกับรุ่นน้องคนหนึ่ง ผมเห็น Error บน Chrome Dev Tools 🛠️ แจ้งประมาณว่า</p><pre>Error: Template parse errors:<br>&#39;mat-tab&#39; is not a known element:<br>1. If &#39;mat-tab&#39; is an Angular component, then verify that it is part of this module.<br>2. If &#39;mat-tab&#39; is a Web Component then add &#39;CUSTOM_ELEMENTS_SCHEMA&#39; to the &#39;@NgModule.schemas&#39; of this component to suppress this message.</pre><p>ผมบอกน้องไปว่า “น้องลืมใส่ import MatTabModule ใน Module ที่น้องกำลังใช้อยู่หรือเปล่า”</p><p>น้องคนนั้นก็เปิดไฟล์ Module นั้นแล้วก็พบว่า … ยังไม่ได้ใส่ MatTabModule เข้าไปที่ “imports” ใน “metadata” ของ <strong>NgModule</strong></p><p>หลังจากน้องทำการแก้ไขตามที่ผมบอก ระบบทำงานได้ตามปกติ</p><p>หลังจากนั้นผมเก็บความผิดพลาดนี้ไว้ แล้วจึงไปถามรุ่นพี่ใช้ Angular อยู่เป็นประจำว่า “เอาจริงๆพี่เข้าใจ <strong>NgModule</strong> ไหม”</p><p>พี่เขาตอบกลับมาว่า “ทุกวันนี้พี่ยังไม่เข้าใจมันเลยน้องเอ้ย” 😱</p><p>จึงเกิดเป็นบทความนี้เพื่ออธิบาย <strong>NgModule</strong> ทั้งภาพกว้างและเชึงลึก</p><p>มาเริ่มกันเลยดีกว่า</p><h3>NgModule — Unit of Compilation &amp; Distribution</h3><p>NgModule คือ JavaScript Class ที่ถูกเพิ่มความสามารถด้วย Decorator ที่มีชื่อว่า <strong>@NgModule</strong> โดยที่ <strong>@NgModule</strong> รับ metadata object</p><pre>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;<br>import { AppComponent } from &#39;./app.component&#39;;</pre><pre><em>// @NgModule decorator พร้อมด้วย metadata object (declarations, imports, ...)</em><br>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p>สิ่งสำคัญคือ <strong>NgModule</strong> มีไว้เพื่ออะไร NgModule ใช้ metadata เพื่อ</p><ol><li>อธิบายวิธีการ Compile Components, Templates, Directives, Pipes ให้กับ Angular Compiler</li><li>ระบุ Components, Directives, Pipes ให้เป็นสาธารณะ (Public) ผ่าน metadata ที่มีชื่อว่า <strong>exports</strong> เพื่อให้ Module อื่น ที่ import Module นี้เรียกใช้งานได้</li><li>เพิ่ม Services หรือ Providers เพื่อใช้ Dependency Injection ใน Component ได้</li></ol><p>เรามาดูเคส 1, 2 ผ่านตัวอย่างด้านล่างนี้กันดีกว่า</p><pre>@NgModule({<br>  imports: [<br>    CommonModule,<br>    FlexLayoutModule,<br>    BrowserAnimationsModule,<br>    MatCardModule,<br>    MatButtonModule,<br>    MatIconModule,<br>    MatProgressSpinnerModule,<br>  ],<br>  declarations: [<br>    CompanyCardComponent,<br>    TechToIconPipe,<br>    CompanyListComponent<br>  ],<br>  exports: [<br>    CompanyListComponent,<br>  ]<br>})<br>export class CompanyModule { }</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company.module.ts">CompanyModule ฉบับเต็ม</a></p><p>ในตัวอย่างนี้มี metadata ที่น่าสนใจคือ imports, declarations, exports</p><p>แต่จะขอเล่าจาก exports, imports, declarations ตามลำดับ</p><p><strong>exports</strong></p><p>ใช้ระบุ Components, Directives, Pipes เพื่อส่งออกให้เรียกใช้ใน Scope นั้นๆได้</p><p>ความหมายคือหาก ModuleA import ModuleB นี้เข้าไป ทุกสิ่งที่ exports ใน ModuleB จะไปอยู่ใน Scope ของการ Compile ModuleA</p><p>ทำให้ ModuleA รู้จักและสามารถเรียกใช้สิ่งที่ ModuleB export ได้</p><p>ตัวอย่าง <strong>CompanyListComponent</strong> ถูก exports ใน <strong>CompanyModule</strong></p><pre>@NgModule({<br>  ...,<br>  exports: [<br>    CompanyListComponent,<br>    <em>// XXXPipe,</em><br>    <em>// XXXDirective</em><br>  ]<br>})<br>export class CompanyModule { }</pre><p>และเมื่อ <strong>AppModule</strong> import <strong>CompanyModule</strong> เข้าไป</p><pre>@NgModule({<br>  declarations: [<br>    AppComponent<br>  ]<br>  imports: [<br>    ...,<br>    CompanyModule,<br>    ...<br>  ],<br>  ...<br>})<br>export class AppModule { }</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.module.ts">AppModule ฉบับเต็ม</a></p><p><strong>AppComponent</strong> ที่อยู่ใน declarations จึงรู้จักและสามารถเรียกใช้ <strong>CompanyListComponent</strong> ใน Template ได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/0*HxXV7QWcPv5r2iuW.png" /></figure><p>ด้านล่างเป็นตัวอย่างของการที่ <strong>AppComponent</strong> Template (app.component.html) เรียกใช้ &lt;angular-th-company-list&gt;&lt;/angular-th-company-list&gt; ซึ่งก็คือ selector ใน <strong>CompanyListComponent</strong></p><pre>...<br>&lt;angular-th-company-list [companies]=&quot;companies$ | async&quot; [loaded]=&quot;loaded&quot;&gt;&lt;/angular-th-company-list&gt;<br>...</pre><p>ซึ่งเรียกใช้ได้ตามปกติเพราะรู้จักแล้ว</p><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/app.component.html">app.component.html ฉบับเต็ม</a></p><p><strong>imports</strong></p><p>ใช้สำหรับ imports Module อื่นๆ เพื่อใช้สิ่งที่ Module นั้น exports ออกมาไม่ว่าจะเป็น Components, Pipes, Directives ณ Compile-time</p><p>รวมถึง Providers ที่ Module นั้น Register ไว้ก็สามารถใช้ได้ ณ Run-time (Dependency Injection)</p><pre>@NgModule({<br>  imports: [<br>    CommonModule,<br>    FlexLayoutModule,<br>    BrowserAnimationsModule,<br>    MatCardModule,<br>    MatButtonModule,<br>    MatIconModule,<br>    MatProgressSpinnerModule,<br>    <em>// XXXModule</em><br>  ],<br>  ...<br>})<br>export class CompanyModule { }</pre><p>จากตัวอย่างโค๊ดด้านบน <strong>CompanyCardComponent</strong> (company-card.component.html) ได้ใช้ &lt;mat-card&gt;&lt;/mat-card&gt; และ Directive fxLayoutAlign &lt;div fxLayoutAlign=&quot;center center&quot;&gt;</p><pre>&lt;mat-card fxLayout=&quot;column&quot; *ngIf=&quot;company&quot;&gt;<br>  ...<br>  &lt;div fxLayoutAlign=&quot;center center&quot; style=&quot;height: 300px&quot;&gt;<br>    ...<br>  &lt;/div&gt;<br>  ...<br>&lt;/mat-card&gt;</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-card/company-card.component.html#L1">company-card.component.html ฉบับเต็ม</a></p><p>การที่จะใช้สิ่งเหล่านี้ เราต้องบอก Angular Compiler ว่าเราใช้ <strong>MatCardComponent</strong>, <strong>FxLayoutAlignDirective</strong> ซึ่งใน <strong>MatCardModule</strong>, <strong>FxLayoutModule</strong> ได้ exports ไว้แล้ว ดังนั้นเราแค่ import <strong>MatCardModule</strong> และ <strong>FlexLayoutModule</strong> ก็สามารถใช้ได้</p><p>ทุกท่านอาจจะสงสัยว่า <strong>CommonModule</strong> มีไว้ทำอะไร <strong>CommonModule</strong> นั้นมีความสำคัญมาก <strong>CommonModule</strong> ทำให้เราสามารถใช้ *ngIf, *ngFor, [ngClass], AsyncPipe (| async), CurrencyPipe (| currency) และอื่นๆ เพราะตัวมันเอง exports สิ่งเหล่านี้ให้เราใช้</p><p><a href="https://angular.io/api/common/CommonModule">อ่าน CommonModule เพิ่มเติม</a></p><p>Components อื่นๆเช่น <strong>MatButton, BrowserAnimationsModule, MatIcon, MatProgressBar</strong> ใช้หลักการเหมือนกับข้างบน</p><p><strong>FormsModule, ReactiveFormsModule</strong> ถ้าจะใช้ต้อง import เข้ามาเช่นกัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/571/0*ejOwGE8OCBTALx9G.png" /></figure><p><strong>declarations</strong></p><p>ระบุ Component, Directive, Pipe ทั้งหมดเพื่อบอก Angular Compiler ว่าใช้ในการ Compile <strong>เฉพาะใน Scope ของ Module นี้เท่านั้น</strong></p><pre>@NgModule({<br>  ...<br>  declarations: [<br>    CompanyCardComponent,<br>    TechToIconPipe,<br>    CompanyListComponent,<br>    <em>// XXXDirective</em><br>  ],<br>  ...<br>})<br>export class CompanyModule { }</pre><p>จากตัวอย่างโค๊ดด้านบน สิ่งที่มันอธิบายคือ Component (<strong>CompanyCardComponent, CompanyListComponent</strong>) และ Pipes (<strong>TechToIconPipe</strong>) รู้จักกันสามารถเรียกใช้งานระหว่างกันได้ <strong>CompanyCardComponent</strong> เรียกใช้ <strong>TechToIconPipe</strong> ใน Template</p><pre>...<br>&lt;img *ngIf=&quot;tech | techToIcon as icon; else techText&quot;/&gt;<br>...</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-card/company-card.component.html#L24">company-card.component.html ฉบับเต็ม</a></p><p><strong>CompanyListComponent</strong> วนลูปสร้าง &lt;company-card&gt;&lt;/company-card&gt; ด้วย *ngFor ใน Template</p><pre>...<br>&lt;angular-th-company-card *ngFor=&quot;let company of companies&quot; [company]=&quot;company&quot;&gt;&lt;/angular-th-company-card&gt;<br>...</pre><p><a href="https://github.com/AngularThailand/who-use-angular-in-thailand/blob/master/apps/who-use-angular-in-thailand/src/app/company/company-list/company-list.component.html#L3">company-list.component.html ฉบับเต็ม</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/281/0*SoRi5DZGChBbcQq-.png" /></figure><p><strong>providers</strong></p><p>หลังจาก Angular Version 6.0 เราสามารถสร้าง Singleton Service ด้วยการใส่ providedIn: &#39;root&#39; ใน metadata ของ @Injectable() เพื่อบอก Angular ให้ Register Service นี้ที่ Application Root ซึ่งวิธีนี้ทำให้ Compiler สามารถ Tree-shaking Services ที่ไม่ได้ใช้ออก</p><pre>@Injectable({<br>  providedIn: &#39;root&#39;<br>})<br>export class CompanyService {</pre><pre>  constructor(private http: HttpClient) { }<br>  getCompanies() {<br>    return this.http.get&lt;Company[]&gt;(&#39;/assets/data/companies.json&#39;).pipe(<br>      shareReplay(1));<br>  }<br>}</pre><p>แต่ก่อนหน้า Version 6.0 ต้อง register ที่ระดับ Module (หรือ Component Level) ใน providers</p><pre>@NgModule({<br>  ...<br>  providers: [<br>    CompanyService,<br>    <em>// {</em><br>    <em>//   provide: HTTP_INTERCEPTORS, useClass: HttpInterceptorService, multi: true</em><br>    <em>// },</em><br>  ],<br>  ...<br>})</pre><p><strong>forRoot, forChild, forFeature, forXXX, xxx คือ ModulewithProviders</strong></p><p>ทุกท่านอาจจะเคยเห็น forRoot, forChild, forFeature และอื่นๆ มันคืออะไรกันนะ? 🤔</p><pre>@NgModule({<br>  imports: [RouterModule.forRoot(...)],<br>  exports: [RouterModule]<br>})<br>export class AppRoutingModule {}</pre><pre>@NgModule({<br>  imports: [RouterModule.forChild(...)],<br>  exports: [RouterModule]<br>})<br>export class CompanyRoutingModule { }</pre><pre>@NgModule({<br>  imports: [<br>    StoreModule.forFeature(...),<br>    TranslateModule.forChild(...),<br>    EffectsModule.forFeature(...)<br>  ],<br>})<br>export class ExamplesModule { }</pre><pre>@NgModule({<br>  imports: [<br>    AngularFireModule.initializeApp(...),<br>    StoreModule.forRoot(...),<br>    StoreRouterConnectingModule.forRoot(),<br>    EffectsModule.forRoot(...),<br>    StoreDevtoolsModule.instrument(...),<br>    TranslateModule.forRoot(...)<br>  ],<br>})<br>export class AppModule { }</pre><p>ดูแล้วมันเหมือนเอาไว้ Configure อะไรบางอย่างถูกต้องไหมครับ เรามาดูตัวอย่างจาก AngularFireModule ดีกว่า</p><pre>@NgModule({<br>  imports: [<br>    AngularFireModule.initializeApp({<br>      apiKey: &#39;perjerzKey&#39;,<br>      authDomain: &#39;perjerz.app&#39;,<br>      projectId: &#39;perjerzId&#39;,<br>      databaseURL: &#39;https://perjerz.firebaseio.com&#39;,<br>      storageBucket: &#39;perjerz.appspot.com&#39;,<br>      messagingSenderId: &#39;1212312121&#39;,<br>      appId: &#39;1150&#39;,<br>    }),<br>    ...<br>  ],<br>})<br>export class AppModule { }</pre><p>ถูกต้องแล้วครับ ✅ มันใช้สำหรับ Configure Value ใน Token, Service เพื่อตอนที่เราจะใช้ Dependency Injection ใน Component ได้ค่านั้นไปใช้</p><p>ตัวอย่างเช่นการ Setup AngularFire ทำให้ Angular App คุยกับ Firebase 🔥 เราจึงต้องจำเป็นระบุ Config</p><p>ด้านล่างเป็น Code AngularFireModule จาก @angular/fire จะเห็นได้ว่ามันรับค่าผ่าน parameters แล้วเอาไป config ให้กับ providers — FirebaseOptionsToken และ FirebaseNameOrConfigToken ไปใช้</p><pre>const FirebaseAppProvider = {<br>    provide: FirebaseApp,<br>    useFactory: _firebaseAppFactory,<br>    deps: [<br>        FirebaseOptionsToken,<br>        [new Optional(), FirebaseNameOrConfigToken]<br>    ]<br>};</pre><pre>@NgModule({<br>    providers: [ FirebaseAppProvider ],<br>})<br>export class AngularFireModule {<br>    static initializeApp(options: FirebaseOptions, nameOrConfig?: string | FirebaseAppConfig) {<br>        return {<br>            ngModule: AngularFireModule,<br>            providers: [<br>                { provide: FirebaseOptionsToken, useValue: options },<br>                { provide: FirebaseNameOrConfigToken, useValue: nameOrConfig }<br>            ]<br>        }<br>    }<br>}</pre><p><a href="https://github.com/angular/angularfire2/blob/master/src/core/firebase.app.module.ts#L58">AngularFireModule ฉบับเต็ม</a></p><p>แล้วเมื่อเราใช้ Service ของ Firebase เช่น AngularFireDatabase, AngularFireAuth เราจึงสามารถใช้มันได้เลยโดยไม่ต้องมาส่งค่า apiKey, authDomain, databaseURL ซ้ำอีกรอบเพราะมันจะไป Resolve Value จาก Token ที่ Configure (Register) ไว้ที่ Module แล้ว</p><pre>@Injectable()<br>export class AppGuard implements CanActivate {<br>  constructor(<br>    private db: AngularFireDatabase,<br>    private auth: AngularFireAuth,<br>    private router: Router,<br>  ) { }<br>   canActivate(): Observable&lt;boolean | UrlTree&gt; {<br>    return this.auth.authState.pipe(switchMap(user =&gt; {<br>        return this.db.object(`...`).valueChanges().pipe(...)<br>      }<br>   }<br>}</pre><p>จะเห็นได้ว่าคนใหม่เข้าโปรเจค ก็สามารถมาอ่าน Configure ที่ระบุไว้ตรง Module ได้เลย</p><p><a href="https://medium.com/devnote/%E0%B8%97%E0%B8%B3%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81%E0%B8%81%E0%B8%B1%E0%B8%9A-dependency-injection-%E0%B9%83%E0%B8%99-angular-880cbf483239">อ่านเรื่อง Dependency Injection ได้ที่ DevNote</a></p><p><strong>entryComponents</strong></p><p>ไว้ระบุ Component ที่จะต้อง Compile บอก Angular Compiler ว่าเราจะใช้ Component เหล่านี้แน่ๆ สร้าง Component Factory ทำ Dynamic Load ณ Run-time (Imperatively) ไม่ต้อง Tree Shake ลบ Component นี้ออกไป</p><p>โดยปกติแล้ว Component ที่เราใช้ใน Template &lt;company-card&gt;&lt;/company-card&gt; Compiler มันรู้ได้เลยจากการใช้ (Reference) จึงสามารถ Inline Instantiation ได้ (Statically, Declaratively)</p><p>แต่กลับกันในกรณีการทำ <a href="https://angular.io/guide/dynamic-component-loader">Dynamic Component Loader</a> (Load Component ตอน Runtime) ซึ่งต้องใช้ entryComponents</p><p>ตัวอย่างที่ชัดเจนเลยคือ <a href="https://material.angular.io/components/dialog/overview#configuring-dialog-content-via-code-entrycomponents-code-">MatDialog</a> (Material Dialog) ที่เราต้องระบุ Component ที่เราสร้างไว้สำหรับเปิด Dialog ขึ้นมา</p><pre>@NgModule({<br>  imports: [<br>    <em>// ...</em><br>    MatDialogModule<br>  ],</pre><pre>  declarations: [<br>    AppComponent,<br>    ExampleDialogComponent<br>  ],</pre><pre>  entryComponents: [<br>    ExampleDialogComponent <em>// ต้องระบุว่า Component นี้เข้าไป</em><br>  ],</pre><pre>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p>อีกกรณีหนึ่งคือการ Load Component ใน Routes (RouterModule) นั้นใช้ Component Factory เหมือนกันเพราะมัน Dynamic Load ณ Runtime เพียงแต่ว่าเราไม่ต้องระบุ Component ใน entryComponents เองเพราะ RouterModule แอบเพิ่มให้เองตอน Compile</p><pre>const routes: Routes = [<br>  {<br>    path: &#39;a&#39;,<br>    component: ComponentA<br>  },<br>  {<br>    path: &#39;b&#39;,<br>    component: ComponentB<br>  }<br>];</pre><pre>@NgModule({<br>  imports: [<br>    RouterModule.forRoot(routes)<br>  ],<br>  exports: [RouterModule],<br>})<br>export class AppRoutingModule {}</pre><p>มีอีกเรื่องหนึ่งที่น่าสนใจคือการที่ เราประกาศ Declarations และ Exports ComponentA, ComponentB, ComponentC ที่ ModuleA แล้วเรา Import ModuleA ใน AppModule แต่ปรากฏว่าใน Template เราไม่ได้มีการใช้ (Reference) สิ่งเหล่านั้น Angular Compiler จะถือว่าเราไม่ได้ใช้ จึงไม่รวมเข้าไปใน Bundle เพื่อทำให้มันเล็กลง ยกตัวอย่างเช่นกรณีของ Custom MatModule (Material Design Module) ที่ declarations และ exports ทุกอย่าง ถึงเราจะ import MatButtonModule, MatCardModule เข้าแต่เราไม่ได้ใช้ ใน Template ก็ไม่ต้องจ่าย Cost ของขนาด Bundle ที่ใหญ่ขึ้น</p><pre>@NgModule({<br>  imports: [<br>    MatToolbarModule,<br>    MatMenuModule,<br>    ...<br>  ],<br>  exports: [<br>    MatToolbarModule,<br>    MatMenuModule,<br>    ...<br>  ], <em>// ถึงแม้จะ export ออกไป ถ้าไม่ได้ใช้ก็ไม่ต้องจ่าย Bundle Size</em><br>  declarations: []<br>})<br>export class CustomMatModule { }</pre><p><strong>bootstrap</strong></p><p>ระบุ Component ที่เอาไว้สร้างตอนเริ่มรัน App (Bootstrap) โดยปกติคือ Root Component ซึ่งก็คือ AppComponent Bootstrap Component นั้นจะถูกเพิ่มเข้าไปใน entryComponents โดยอัตโนมัติ</p><p>ตัวอย่างที่ชัดเจนเลยคือ AppModule</p><pre>@NgModule({<br>  declarations: [AppComponent],<br>  imports: [BrowserModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p><strong>schemas</strong></p><p>ระบุ Schema ที่อนุญาตให้ใช้ใน Scope ของ NgModule โดยมีสองค่าที่ใช้ได้คือ <a href="https://github.com/angular/angular/blob/master/packages/core/src/metadata/schema.ts#L38">NO_ERRORS_SCHEMA</a> และ <a href="https://github.com/angular/angular/blob/master/packages/core/src/metadata/schema.ts#L29">CUSTOM_ELEMENTS_SCHEMA</a></p><p><strong>NO_ERRORS_SCHEMA — บอก Angular Compiler ว่าอนุญาตทุก Element ทุก Property เป็นอะไรก็ได้</strong></p><p>สำหรับการทำ <a href="https://vsavkin.com/three-ways-to-test-angular-2-components-dcea8e90bd8d">Shallow Testing</a> เราต้องการจะ Test Angular Template โดยละ Dependencies ไว้ในฐานที่เข้าใจ ของ Component (ไม่ต้องสนใจ Template Error ว่า Require อะไร) เราสามารถ Configure Module เพื่อบอก Angular Component บางตัวที่เราสร้างให้คิดซะว่าเป็นแค่ DOM ธรรมดา</p><p>ตัวอย่างด้านล่างคือมี Component ชื่อ ConversationsCmp ที่เราต้องการเทสว่า มัน Render ข้อความข้างในถูกต้องซึ่งใน template นั้นใช้ &lt;mat-card&gt;&lt;/mat-card&gt; หรือ MatCardComponent ซึ่งเราไม่ได้สนใจหน้าตาความสวยงามของมัน เราต้องการเช็คว่ามีข้อความข้างในและถูกต้องไหม</p><p>ตอนสร้าง TestBed เลย Configure Module โดยใส่ schemas NO_ERRORS_SCHEMA ไม่ต้องฟ้อง Error จากการไม่ import MatCardModule ให้ Angular Compiler เข้าใจ Scope ของ MatCardComponent ด้วย แล้วก็รันเทสตามปกติ</p><pre>&lt;mat-card *ngFor=&quot;let c of conversations | async&quot; [routerLink]=&quot;[c.id]&quot;&gt;<br>  &lt;h3&gt;<br>    &lt;a [routerLink]=&quot;[c.id]&quot;&gt;{{c.title}}&lt;/a&gt;<br>  &lt;/h3&gt;<br>  &lt;p&gt;<br>    &lt;span class=&quot;light&quot;&gt;{{c.user.name}} [{{c.user.email}}]&lt;/span&gt;<br>  &lt;/p&gt;<br>&lt;/mat-card&gt;</pre><pre>@Component({templateUrl: &#39;conversations.html&#39;})<br>export class ConversationsCmp {<br>  folder: Observable&lt;string&gt;;<br>  conversations: Observable&lt;Conversation[]&gt;;</pre><pre>  constructor(route: ActivatedRoute) {<br>    this.folder = route.params.pluck&lt;string&gt;(&#39;folder&#39;);<br>    this.conversations = route.data.pluck&lt;Conversation[]&gt;(&#39;conversations&#39;);<br>  }<br>}</pre><pre>describe(&#39;ConversationsCmp&#39;, () =&gt; {<br>  let params: BehaviorSubject&lt;string&gt;;<br>  let data: BehaviorSubject&lt;any&gt;;</pre><pre>  beforeEach(async(() =&gt; {<br>    params = of({<br>      folder: &#39;inbox&#39;<br>    });</pre><pre>    data = of({<br>      conversations: [<br>        { id: 1, title: &#39;On the Genealogy of Morals by Nietzsche&#39;, user: {name: &#39;Kate&#39;, email: &#39;katez@example.com&#39;} },<br>        { id: 2, title: &#39;Ethics by Spinoza&#39;, user: {name: &#39;Corin&#39;, email: &#39;corin@example.com&#39;} }<br>      ]<br>    });</pre><pre>    TestBed.configureTestingModule({<br>      declarations: [ConversationsCmp],<br>      providers: [<br>        { provide: ActivatedRoute, useValue: {params, data} }<br>      ],<br>      <em>// Tells the compiler not to error on unknown elements and attributes</em><br>      schemas: [NO_ERRORS_SCHEMA]<br>    });<br>    TestBed.compileComponents();<br>  }));</pre><pre>  it(&#39;updates the list of conversations&#39;, () =&gt; {<br>    const f = TestBed.createComponent(ConversationsCmp);<br>    f.detectChanges();</pre><pre>    expect(f.debugElement.nativeElement).toHaveText(&#39;inbox&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;On the Genealogy of Morals&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;Ethics&#39;);</pre><pre>    params.next({<br>      folder: &#39;drafts&#39;<br>    });</pre><pre>    data.next({<br>      conversations: [<br>        { id: 3, title: &#39;Fear and Trembling by Kierkegaard&#39;, user: {name: &#39;Someone Else&#39;, email: &#39;someonelse@example.com&#39;} }<br>      ]<br>    });<br>    f.detectChanges();</pre><pre>    expect(f.debugElement.nativeElement).toHaveText(&#39;drafts&#39;);<br>    expect(f.debugElement.nativeElement).toHaveText(&#39;Fear and Trembling&#39;);<br>  });<br>});</pre><p><strong>CUSTOM_ELEMENTS_SCHEMA — บอก Angular Compiler ว่าอนุญาต Non-Angular Elements และ Properties ด้วย Dash Case ซึ่ง Dash Case เป็น Convention ของ Custom Elements</strong></p><p>โดยปกติแล้ว Angular จะเข้าใจว่า Custom HTML Tag เป็น Angular Component หมดเวลาเจออะไรแปลกๆไม่รู้จักใน Scope ก็เด้ง error ในกรณีที่เราต้องการใช้ Custom Element เลยต้องบอกว่า Angular Compiler เราจะใช้ Custom Element นะไม่ต้อง งง จากนั้นมันจะ Compile ผ่าน</p><pre>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from &#39;@angular/core&#39;;<br>import { ReactiveFormsModule } from &#39;@angular/forms&#39;;</pre><pre>import { AppComponent } from &#39;./app.component&#39;;</pre><pre>@NgModule({<br>  declarations: [AppComponent],<br>  schemas: [CUSTOM_ELEMENTS_SCHEMA] <em>// &lt;-- บอกตรงนี้,</em><br>  imports: [BrowserModule, ReactiveFormsModule],<br>  providers: [],<br>  bootstrap: [AppComponent]<br>})<br>export class AppModule {}</pre><p><a href="https://vaadin.com/tutorials/using-web-components-in-angular">ศึกษาเรื่อง Custom Element ใน Angular ต่อ</a></p><h3>สรุป NgModule</h3><ol><li>อธิบายวิธีการ Compile Components, Templates, Directives, Pipes ให้กับ Angular Compiler</li><li>ระบุ Components, Directives, Pipes ให้เป็นสาธารณะ (Public) ผ่าน metadata ที่มีชื่อว่า <strong>exports</strong> เพื่อให้ Module อื่น ที่ import Module นี้เรียกใช้งานได้</li><li>เพิ่ม Services หรือ Providers เพื่อใช้ Dependency Injection ใน Component ได้</li></ol><p>ก่อนจบบทความนี้ไป ผมมีปริศนาฟ้าแลบ ⚡ ให้ทุกท่านทาย คำถามมีอยู่ว่า</p><p>ตอนนี้ Angular App 🅰️ ของเราได้ทำการแบ่ง Feature Module ไว้เรียบร้อยแล้ว</p><p>CEO 😎 ต้องการให้ Angular App ทำให้ช่องกรอกเบอร์โทรศัพท์ 📞 mask เบอร์จาก 0999999999 เป็น 099–999–999 <strong>เหมือนกันทุกช่อง input ใน App</strong></p><p>พวกเราเหล่า Developers 👨💻 จึง Search หา Library ใน Google แล้วพบตัวนึงที่มีชื่อว่า <a href="https://github.com/JsDaddy/ngx-mask">ngx-mask</a></p><p>โอเคเรา npm install --save ngx-mask เรียบร้อย</p><p>ใน ngx-mask github ได้แนะนำวิธีการ import Module ไว้ด้านล่าง</p><pre>import { NgxMaskModule } from &#39;ngx-mask&#39;</pre><pre>export const options: Partial&lt;IConfig&gt; | (() =&gt; Partial&lt;IConfig&gt;);</pre><pre>@NgModule({<br>  (...)<br>  imports: [<br>    NgxMaskModule.forRoot(options)<br>  ]<br>  (...)<br>})</pre><p>คำถามคือเราจะต้อง import NgxMaskModule ยังไงและที่ไหนบ้าง?</p><ol><li>import NgxMaskModule.forRoot(options) ที่ AppModule ที่เดียวจบใช้ได้ทั้ง App</li><li>import NgxMaskModule.forRoot(options) ที่ AppModule และ ทุก Feature Module ที่เราแบ่งไว้</li><li>import NgxMaskModule.forRoot(options) ที่ AppModule และ import NgxMaskModule ทุก Feature Module</li><li>import NgxMaskModule ที่ AppModule และ ทุก Featured Module</li><li>import NgxMaskModule ที่ AppModule และ import NgxMaskModule.forRoot(options) ทุก Feature Module</li><li>import NgxMaskModule ที่ AppModule ที่เดียวจบใช้ได้ทั้ง App</li></ol><p>แล้วถึงสามารถใช้โค๊ดด้านล่างได้</p><pre>&lt;input type=&quot;text&quot; mask=&quot;000-000-000&quot;&gt;</pre><pre>&lt;span&gt;{{phone | mask: &#39;000-000-0000&#39;}}&lt;/span&gt;</pre><p>แล้วจะมาเฉลยในบทความต่อไปของ NgModule 😈</p><p>จบไปแล้วสำหรับ NgModule เบื้องต้น 🔚 ยังมีอีกหลายเรื่องใน NgModule ที่คุยกันต่อได้เช่น 💬</p><ul><li>ลำดับการสร้างตอน Bootstrap App ของ NgModule</li><li>Feature Module คืออะไรกันนะ? 🤔</li><li>ประเภทของ Feature Module</li><li>Lazy-Loading Module คืออะไรกัน ❓</li><li>NgModule พื้นฐานเช่น RouterModule, HttpClientModule, FormsModule</li></ul><p>ฝากแชร์ 🔗 ต่อให้เพื่อนพี่น้อง ชาว Angular ได้อัพเดทกัน</p><p>แล้วเจอกันบทความหน้า 👋 สวัสดีครับ 🙏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/0*zydDlPe_WWUaZKek.png" /></figure><p>บทความนี้ใช้<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/">สัญญาอนุญาตของครีเอทีฟคอมมอนส์แบบ แสดงที่มา-ไม่ใช้เพื่อการค้า-อนุญาตแบบเดียวกัน 4.0 International</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e3e0ad862aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[สรุป Keynote Angular Connect 2019 วันแรก]]></title>
            <link>https://perjerz.medium.com/%E0%B8%AA%E0%B8%A3%E0%B8%B8%E0%B8%9B-keynote-angular-connect-2019-%E0%B8%A7%E0%B8%B1%E0%B8%99%E0%B9%81%E0%B8%A3%E0%B8%81-5d9b4cfd33e6?source=rss-6bc0d1386272------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d9b4cfd33e6</guid>
            <category><![CDATA[angularconnect]]></category>
            <category><![CDATA[perjerz]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Siwat Kaolueng]]></dc:creator>
            <pubDate>Wed, 13 Nov 2019 15:38:13 GMT</pubDate>
            <atom:updated>2019-11-13T15:46:26.624Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9zhgdfi_4fLLHDw_.jpg" /><figcaption>Image credit: <a href="https://twitter.com/ankitsharma_007/status/1174607831263252480"><strong>@ankitsharma_007</strong></a></figcaption></figure><p>สวัสดีครับผมเจมส์จาก Angular Thailand วันนี้ผมจะสรุป Keynote ของงาน Angular Conference ที่ยิ่งใหญ่ใน Europe ที่มีชื่อว่า Angular Connect ให้ทุกท่านได้อ่านกัน มาเริ่มกันเลย</p><p>Keynote Angular Connect Day 1</p><p>Stephen Fluin — Developer Advocate, Angular Team, Google @stephenfluin</p><p>Igor Minar Angular Team Lead, Google @IgorMinar</p><p>เปิดทอล์คโดย Stephen Fluin เล่าไปถึงวันเปิดตัว Angular 2 ที่ขนพร็อบบอลลูนจัดเต็ม ย้อนเวลาไป 14 กันยายน 2014 ครบรอบ 5 ปีของ AngularConnect และ 3 ปีนับตั้งแต่วันที่ปล่อย Angular 2 🎉🎂 เย้!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RQQIbOKyw2PluxfW.JPG" /></figure><p>มาต่อด้วย Angular Conference ที่เกิดขึ้นใหม่ทั่วโลกในปีนี้ ปีนี้มีเพิ่มขึ้น 7 Conferences ใกล้ประเทศไทยสุดเป็น NG-MY (Malaysia) ผมเพิ่งไปพูดมา</p><p>เป็น Conference ที่เทียบราคากับความรู้ที่ได้รับกับเพื่อน Angular แล้วถือว่าเกินคุ้มมากๆ เจอกันอีกแน่นอน NG-MY 2020 ขอเชิญชวนทุกท่านไปร่วมสนุกกันที่งานครับ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ALgtRpGVS3TWI9z_.JPG" /></figure><p>มาช่วยกันยกระดับ Angular Developers เมืองไทยด้วยการ ออกมาเขียนบทความ, จัด Meetup, เป็น Speakers แชร์ประสบการณ์ เพื่อเตรียมตัวสำหรับการจัด Angular Thailand Conference</p><p>ngGirls มี Angular Community และมี Workshop สำหรับผู้หญิงโดยเฉพาะ หากท่านสนใจ สามารถอ่านรายละเอียดได้ที่ <a href="http://ng-girls.org/">http://ng-girls.org/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-Oo8tc7mUtxiaZL0.JPG" /></figure><p>จากนั้น Stephen แนะนำเรื่องราวจาก Community มาแชร์ Case Study ต่างๆโดยเริ่มต้นที่ Deutsche Bank</p><p>Rene Kriest — Head of Development for Public Websites</p><p>Florian Kittel — Lead Developer for Public Websites</p><p>Deutsche Bank มี 60 Apps สร้าง Business Component และ สร้างเว็บ Editor ที่สามารถสร้างเว็บด้วยการ Drag &amp; Drop 😮 รวมถึงมี Live Preview, One-click Deployment, และ Versioning</p><p>ทุกอย่างถูกสร้างด้วย Angular &amp; NodeJS โดยใช้ Angular CLI, Schematics สร้างโค๊ด, Workspace จัดการ Themes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0DpE_YSG-u_LbqFD.JPG" /></figure><p>ต่อไปเป็นฝั่งของ Alianz</p><p>Jochen Supper ย้อนไปสองปีที่แล้วว่าเป็นจุดเริ่มต้นของการสร้าง UI Library ของ Alianz และได้รับบทเรียนจากการ Adopt Schematics</p><ol><li>มี Learning Curve การสร้างคำสั่ง ng update นั้นต้องเข้าใจเรื่อง Abstract Syntax Tree (AST)</li><li>ถึงแม้ว่าจะมี Schematics สำหรับ ng update แล้ว บางทีมใน Alianz ยังคงอัพเดท Manual จึงจำเป็นที่จะต้องแจ้งทีมและสอนการใช้งาน</li><li>ส่วนทีมที่ใช้ ng update ก็มีความสุขกันเพราะง่ายและสะดวก</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m9Ddc2smqcrlfBfp.JPG" /></figure><p>บทเรียนต่อมาคือ Alianz นั้นมี Text Input สองแบบที่ Support คนละ Use case</p><ol><li>สำหรับลูกค้า (B2C) ที่ใส่ Float Label Animation (ฝั่งซ้าย)</li><li>สำหรับพนักงานหรือเจ้าหน้าที่ (Expert) ที่ไม่ต้องการ Animation (ฝั่งขวา)</li></ol><p>ซึ่งใช้ markup คนละแบบ เลยต้องไปเขียน Convention แต่ละแบบใน Document ให้คนปฏิบัติตาม ทีมนักพัฒนาก็เลยต้องอ่านให้ละเอียด ซึ่งบางคนไม่ได้อ่านละเอียด จะมีวิธีที่ดีกว่านี้ไหม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BznOIweZbdzZtpB0.JPG" /></figure><p>คำตอบคือการใช้ Injection Token ที่มี Config แบบพนักงาน (Expert) กล่าวคือแก้ปัญหาด้วย Code แทนการ Follow ตาม Convention ใน Document</p><p>วิธีการง่ายๆคือสำหรับ Team ที่ทำ App ภายในให้พนักงาน ก็แค่ import NxExpertModule ที่มี Config</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HSb5wTW2_urqUoA1.JPG" /></figure><p>โดยสรุปแล้วสิ่งที่ Alianz เรียนรู้คือการเปลี่ยนจากการ Manual Update ไปเป็น Schematics (ng update, ng add) และ Convention ด้วย Document ไปเป็น Code แทน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c112-2517cDJvUNI.JPG" /></figure><p>ต่อไปเป็นตาของ NativeScript (สร้าง App Cross-platform แต่ได้ Native UI Concept เดียวกับ React Native) โดย Stanimira Vlaeva</p><p>เมื่อไม่นานมานี้ มี NativeScript Hackathon สร้าง App เพื่อช่วยเหลือ NGO</p><p>สามารถอ่านรายละเอียดเพิ่มเติมได้ที่ <a href="http://ng-ns.org/">https://ng-ns.org</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X721wpESSPtg8_fm.JPG" /></figure><p>ต่อไปเป็นช่วงของ Ionic ผู้อยู่คู่กับ Angular มานานแสนนาน (สร้าง App Cross-platform ด้วย WebView) Mike Harington</p><p>สมัยก่อนทีม Ionic สร้าง Tools (CLI), Router และ Best Practices ของตัวเอง แต่แล้วก็ตระหนักว่ามันเป็นการลงทุนที่มากเหมือนกัน จนมาถึง Ionic 4 ที่ Adopt ตาม Angular เช่น เปลี่ยนจาก @ionic/app-scripts เป็น @angular/cli, Ionic Router เป็น @angular/router และ ใช้ Best Practice ของ Angular นอกนั้นยังไม่พอ ทีม Ionic ยังต่อยอด Angular Router เป็น IonRouterOutlet ด้วยการเพิ่ม Animation เปลี่ยนหน้า, ต่อยอด Angular CLI เพื่อ Provide ข้อมูลเพิ่มเติมตอน Build ลง iOS, Android และ ต่อยอด Schematics เพื่อ Override คำสั่ง Default เช่น ng generate page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*I7m5hGEpZxEJFnyz.JPG" /></figure><p>Capacitor ผู้มาแทนที่ Cordova</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4wHu8DYs5QUPCag3.JPG" /></figure><p>กลับมาที่ Stephen กันต่อ</p><p>ยังจำได้ไหมว่า Angular เคยมี Angular for Designer ที่ใช้เครื่องมือออกแบบแล้วสร้างโค๊ด Angular ออกมา มันกลับมาแล้วในชื่อว่า UI Bakery ตามไปลองได้ที่ <a href="https://uibakery.io/">https://uibakery.io/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0RFoYuQo3SCTEW-d.JPG" /></figure><p>มีรายงานว่าใน Google มี Angular Projects 600+ เมื่อปีที่แล้ว</p><p>มาปีนี้มี Angular Project ทั้งหมด 1500+</p><p>Firebase, Google Cloud Platform ล้วนใช้ Angular เป็นการการันตีความน่าเชื่อถือของ Angular ได้อย่างมาก</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fn4iFi1NFVtWPxri.JPG" /></figure><p>ตอนนี้มี GDE Angular ทั้งหมด 105 คนทั่วโลก ผมนี่รอ GDE Angular คนแรกในไทยเลยว่าจะเป็นใครนะ 🤔🤔</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lwbUpO6_u68EJ87b.JPG" /></figure><p>Angular ได้เปิดตัวโปรแกรม Angular Collaborators หรือคนที่ช่วย Contribute Angular Github Repo โดยมี Jia Li ผู้อยู่เบื้องหลัง zone.js และ Joost ดูเรื่อง compiler, ngcc ขอบคุณ Collaborators ทุกท่าน 🙏</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4gJdypx6WvZYBNN5.JPG" /></figure><p>จบแล้วสำหรับฝั่งของ Stephen ถึงเวลาฟังเนื้อหา Technical Update จาก Igor Minar กัน</p><p>เรามาทบทวนกันดีกว่าเรื่อง Release Cycle ปกติแล้ว Angular จะมีการอัพเดท Major Version ทุก 6 เดือน นอกจากฟีเจอร์ใหม่แล้ว สิ่งที่สัญญาตลอดมาคือ Backward Compatibility เพราะฉันรู้ว่าฉันผิดไปแล้วจาก AngularJS (1) -&gt; Angular (2+) 🤞 และอัพเกรดเวอร์ชั่นที่ง่ายดายราวกับเวทย์มนต์ 🧙 (ng update) เดือนพฤษภาคมที่ผ่านมาได้ปล่อย Version 8 ไปแล้ว อีกไม่กี่สัปดาห์เราก็จะเข้าสู่ Version 9 กันในช่วงประมาณพฤศจิกายน โดยต่อไปจะเป็นการแนะนำฟีเจอร์เด็ดๆใน Version 8</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xYcR6B68oCdxr-JP.JPG" /></figure><p>Differential Loading คือการที่ Apps ของเราถูก Build เป็น 2 Bundles — Bundles แรกสำหรับ Browser รุ่นใหม่ Polyfill ไม่มาก Bundle เล็ก และ Bundles สองสำหรับ Browser โบราณ ที่ Polyfill จัดเต็มเลยใหญ่กว่า</p><p>ซึ่งก่อนจะมี Differential Loading นั้น Angular CLI ทำการ Build เป็น Bundle เดียวโดยที่ polyfill ขึ้นกับ browserlist file หมายความว่าถ้าใช้ Browser สมัยใหม่ก็อาจจะโหลด polyfill ที่ไม่ต้องใช้เพื่อ support Browser เก่าๆ อยู่ดี</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bus8GnvVQZH5ntg9.JPG" /></figure><p>หลังจากที่มี Differential Loading เว็บไซต์ angular.io ลดขนาดไป 41 Kb คิดเป็น 10%</p><p>สำหรับเว็บไซต์อื่นๆที่อัพเดทเป็นเวอร์ชั่น 8 จากรายงานแจ้งว่าลดไป 7–20%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ko1ckHG6i731BK9R.JPG" /></figure><p>ประเด็นมันมีอยู่ว่าสมัยก่อนมัน Build 2 รอบสำหรับ Browser รุ่นใหม่ และรุ่นโบราณ ทำให้ Build ช้า (รูปแรก) แต่ได้แก้เป็นการ Downlevel แทนทำให้ Build เร็วขึ้น 45% (รูปที่สอง)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JOm9WPGJlbc5dvVV.JPG" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8wwKPDGL0tXZwRCY.JPG" /></figure><p>คำสั่ง ng deploy สำหรับ deploy Angular app ไปยัง Host ต่างๆ ไม่ว่าจะเป็น Firebase, Azure, Netlify และ Github Pages โดยก่อนใช้คำสั่งต้อง ng add ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1F0HzYvcr4TYMtAu.JPG" /></figure><p>Redesign หน้าตาของ app หลังจาก ng new ให้สวยงามและมีประโยชน์มากขึ้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ag_ATXl4njOGBcNs.JPG" /></figure><p>นอกจากนี้ยังมีฟีเจอร์</p><ul><li>ใช้ Lazy Loading ด้วย import() syntax ตาม Standard</li><li>Custom Builders สำหรับปรับปรุงหรือเพิ่ม Step Build เช่นใช้ Webpack ทำอะไรเพิ่มเติม</li><li>Web Worker Bundling</li><li>AngularJS $location support ใช้สำหรับทำ hybrid AngularJS และ Angular โดยใช้ Router ตัวเดียวกัน</li><li>ปรับปรุงการสนับสนุนของ IDE ให้ดีขึ้น</li><li>นอกจาก Tour of heroes แล้ว ตอนนี้ได้เพิ่ม ตัวอย่าง e-commerce เข้าไปสำหรับมือใหม่</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cOuHD-iZi036CBkg.JPG" /></figure><p>Ivy ทำให้ Debug ง่ายขึ้นโดยสามารถเข้า Console ของ Chrome Dev Tools แล้วพิมพ์คำสั่ง ng.getComponent($0) เพื่อเข้าถึง Component และเรียกใช้ Method ใน Component ณ Runtime นั้นได้เลย โหดๆ 👍👍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7n8IGVNnt0YrYckZ.JPG" /></figure><p>เวอร์ชั่นล่าสุด v9.0.0-next.6 นั้นมีรายละเอียดใหม่ในเรื่องของ Bundle Size</p><p>App ขนาดเล็ก Build แล้วมีขนาดลดลง 30%, ขนาดกลางเพิ่มขึ้น 10%, ขนาดใหญ่ลดลง 40%</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UXZrYKEXJtSWjFTR.JPG" /></figure><p>Runtime Ivy นั้นใช้ Concept คล้ายๆ Assembly ที่มี Instruction Sets</p><p>โดยผมจะยกตัวอย่างใน Ivy Instruction เช่น</p><ul><li>Ivy Instruction ของการเปิดปิด tag จากรูปด้านบน โค๊ดที่เราเขียนคือเปิดปิด tag div คือ elementStart, elementEnd (ตารางฝั่งขวา)</li><li>Ivy Instruction ของการใส่ข้อความ hello ลงใน tag คือ text</li><li>Ivy Instruction ของการทำ Text Interpolotion {{name}} คือ textInterpolate</li></ul><p>และอื่นๆอีกมากมาย โดยปกติแล้ว Instruction ทั้งหมดนี้จะถูกใส่เข้าไปใน Runtime ตามฟีเจอร์ที่เราใช้ใน Code อันไหนไม่ได้ใช้ ก็จะไม่ถูกเข้าไปใน Runtime</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KD8JEbLP-Q0dk05H.JPG" /></figure><p>ต่างจาก View Engine หรือ Render v2 ที่ใช้ Data Structure แปลงตอน Runtime โดยที่ Runtime ต้องมีทุกฟีเจอร์ของ Angular และไม่สามารถ Tree Shake Feature ที่ไม่ได้ใช้ออกไปได้ จะเห็นได้ว่า Ivy นั้นสามารถถอด Feature ที่ไม่ได้ใช้ส่งผลให้ Bundle Size เล็กกว่าได้ ศึกษาเพิ่มเติมได้ที่ Youtube ด้านล่าง</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fisb5Ef6yI48%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Disb5Ef6yI48&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fisb5Ef6yI48%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/30c32150d8a42183173eba771bbb1943/href">https://medium.com/media/30c32150d8a42183173eba771bbb1943/href</a></iframe><p>ขณะนี้มี 150 Ivy Instructions คิดว่ายิ่งมีเยอะยิ่งดีเพื่อให้เป็น Unit ที่เล็กที่สุดในการที่ถอดออกไปได้เมื่อไม่ได้ใช้</p><p>โดย Ivy จะเป็น Default ใน Angular Version 9</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vvmjtyLzsJo3-tw2.JPG" /></figure><p>Library ใน npm นั้นส่วนใหญ่ถูก Compile เพื่อ Support View Engine</p><p>Ivy มี ngcc (Angular Compatibility Compiler) สำหรับแปลง Library ที่เคยถูก Compile ด้วย View Engine ให้เป็น Ivy Code <a href="https://github.com/angular/angular/blob/master/packages/compiler/design/architecture.md#ngcc-operation">อ่าน Compiler Spec เพิ่มเติมได้ที่นี่</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9WXkVn97PjjMlunb.JPG" /></figure><p>Library ที่เป็น Ivy อยู่แล้วก็สามารถใช้ได้เลยไม่ต้อง Compile ซ้ำเพื่อใช้กับ Ivy App ส่วน Library ที่เป็น View Engine ก็ต้องใช้ ngcc Compile ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b2ks0vYWJbFd2c9-.JPG" /></figure><p>Version 9 ตอน Build Apps จะเป็น Ivy โดย Default แต่สำหรับ Libraries จะยังคงเป็น View Engine</p><p>Version 10 มีแนวโน้มที่ Instruction Sets นั้น Stable เลยเริ่มทำการ Build Library เป็น Ivy เพื่อที่จะทำให้ ngcc มีบทบาทน้อยลง</p><p>Version 11 ngcc จะเป็นแค่ backup สำหรับ library เก่าๆที่เป็น View Engine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*feJ0dyl1vLrbYjNn.JPG" /></figure><p>จากผลการทดสอบ 173 Library ชื่อดังทั้งหมด ปรากฏว่า 85% ใช้ ngcc แล้วเข้ากันได้กับ Ivy ทุกท่านสามารถดูผลและทดสอบ Library ของท่านได้ที่ Github <a href="https://github.com/angular/ngcc-validation">https://github.com/angular/ngcc-validation</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u_bu_WzTWXBv6Y4M.JPG" /></figure><p>อย่างไรก็ดี ทุกท่านสามารถเลือกออก (Opt-out) จาก Ivy จนถึง Version 10</p><p>ถ้าอยากลอง Ivy ตอนนี้ คำสั่งนี้เลย</p><p>ng update @angular/cli@next @angular/core@next</p><p>ต่อไปจะเป็นการ Demo Feature ที่ Ivy ทำให้เกิดขึ้นได้ อันแรกคือ</p><p>Style Merging <a href="https://github.com/matsko/ivy-styling-demo">https://github.com/matsko/ivy-styling-demo</a></p><p>Component Lazy Loading <a href="https://github.com/IgorMinar/ivy-lazy-load-component">https://github.com/IgorMinar/ivy-lazy-load-component</a> ซึ่งนำไปสู่ Progressive Rehydration ศึกษาต่อได้ที่วีดีโอด้านล่าง</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFiVw6zjgw24%3Fstart%3D1291%26feature%3Doembed%26start%3D1291&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFiVw6zjgw24&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFiVw6zjgw24%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b4612ae12a242c0741524df5dd388d9/href">https://medium.com/media/5b4612ae12a242c0741524df5dd388d9/href</a></iframe><p>สุดท้ายแล้ว เกิด Ecosystem ใหม่สำหรับ</p><ul><li>ng add เพื่อ Add Library</li><li>ng update อัพเดท Apps และ Library</li><li>builders มีคนทำ Custom Builders ใหม่ๆ เช่น ngx-build-plus</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7_vi8w-9RRTnMx6V.JPG" /></figure><p>จบแล้ว เป็นไงกันบ้างสำหรับการอัพเดทครั้งนี้ ฝากแชร์ต่อให้เพื่อนพี่น้อง ชาว Angular ได้อัพเดทกัน</p><p>แล้วเจอกันบทความหน้า สวัสดีครับ</p><p>ลิงค์ต้นฉบับ <a href="https://perjerz.netlify.com/post/recap-keynote-angular-connect-day-1/">https://perjerz.netlify.com/post/recap-keynote-angular-connect-day-1/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/88/0*4-HuqzNEIILZN79w.png" /></figure><p>บทความนี้ใช้<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/">สัญญาอนุญาตของครีเอทีฟคอมมอนส์แบบ แสดงที่มา-ไม่ใช้เพื่อการค้า-อนุญาตแบบเดียวกัน 4.0 International</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d9b4cfd33e6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>