<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Bulent Gorkem</title>
    <description>The latest articles on DEV Community by Bulent Gorkem (@bgorkem).</description>
    <link>https://dev.to/bgorkem</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F390293%2Fb0c4262d-1120-4251-b457-625901e9ddef.jpeg</url>
      <title>DEV Community: Bulent Gorkem</title>
      <link>https://dev.to/bgorkem</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bgorkem"/>
    <language>en</language>
    <item>
      <title>Lambda function use in React Class Components</title>
      <dc:creator>Bulent Gorkem</dc:creator>
      <pubDate>Sat, 06 May 2023 13:58:45 +0000</pubDate>
      <link>https://dev.to/bgorkem/lambda-function-use-in-react-class-components-5a77</link>
      <guid>https://dev.to/bgorkem/lambda-function-use-in-react-class-components-5a77</guid>
      <description>&lt;p&gt;React functional components have become more popular than React class components in recent times. Hence we don’t need to rely on use of often misunderstood "this" keyword to access member variables, methods. We used to add a lot of mysterious &lt;code&gt;bind(this)&lt;/code&gt; methods to our handlers in &lt;strong&gt;constructors&lt;/strong&gt; before.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkedHandler&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;checkedHandler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Together with lambda syntax used in class methods we don't need this ceremony anymore. &lt;/p&gt;

&lt;p&gt;If you want to understand why, the code sample below explains briefly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PropsWithChildren&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;handle &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;handleThisWithLambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;handle that&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleThis&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Handle&lt;/span&gt; &lt;span class="nx"&gt;This&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="nx"&gt;onClick&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleThisWithLambda&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Handle&lt;/span&gt; &lt;span class="nx"&gt;That&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&amp;gt; &amp;lt;/&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 2 methods: &lt;code&gt;handleThis&lt;/code&gt; and &lt;code&gt;handleThisWithLambda&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;First one prints &lt;code&gt;undefined&lt;/code&gt; as &lt;code&gt;this&lt;/code&gt;, because in strict-mode &lt;code&gt;this&lt;/code&gt; value is undefined when run outside of any object, ie. the event handler, unless it was bound by the function called, hence the use of &lt;code&gt;...bind.this( )&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The second one with the lambda syntax though prints the correct App instance we are running in. &lt;/p&gt;

&lt;p&gt;What is the difference? &lt;/p&gt;

&lt;p&gt;If you copy-paste this code to a code transpiler, like &lt;a href="https://www.typescriptlang.org/play"&gt;typescript playground&lt;/a&gt; which converts it old ECMAScript 2017 code, you will spot the difference in how lambda syntax is translated inside the class code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;handleThisWithLambda&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;handle that&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;handleThis&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;handle &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see &lt;code&gt;handleThisWithLambda&lt;/code&gt; code moved into the constructor function, hence created with a closure to the &lt;code&gt;this&lt;/code&gt; instance. So it is already doing the same job &lt;code&gt;bind.this&lt;/code&gt; was doing previously for the legacy method case.&lt;/p&gt;

&lt;p&gt;In React Functional components, you don't need this or bind.this anymore, as every thing is inside the same function closure anyway. &lt;/p&gt;

&lt;p&gt;Hope this helps!&lt;/p&gt;

</description>
      <category>react</category>
      <category>lambda</category>
    </item>
    <item>
      <title>Why Typescript?</title>
      <dc:creator>Bulent Gorkem</dc:creator>
      <pubDate>Sat, 09 Jan 2021 13:53:11 +0000</pubDate>
      <link>https://dev.to/bgorkem/why-typescript-inm</link>
      <guid>https://dev.to/bgorkem/why-typescript-inm</guid>
      <description>&lt;h2&gt;
  
  
  Why Typescript
&lt;/h2&gt;

&lt;p&gt;Typescript extends JavaScript by adding types at build time.&lt;/p&gt;

&lt;p&gt;Benefits&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;✅ Encode constraints and assumptions, as part of developer intent. Defensive programming: Don't trust any of your inputs. Causes cognitive and performance overhead&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Speeds up your development experience by catching errors and providing fixes even&lt;br&gt;
before you run your code. Some 15% of JavaScript detectable bugs could be prevented according to a &lt;a href="http://earlbarr.com/publications/typestudy.pdf"&gt;research&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Easier to refactor code without breaking it significantly. Gives you the confidence to refactor without fear of breaking assumed, implicit contracts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Improved Developer experience: Navigating, understanding complex large size code is easier. Don't need to drill into source files and read all code implementation. You can go one level higher abstraction: rather than how you look at what the code does&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;✅ Helps with documentation. Automated API docs generation. More formalized and stable contracts&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cons
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;❌ Not true static typing, only checks the shape of the object, not its true type.&lt;/li&gt;
&lt;li&gt;❌ Paradigm shift for developers coming from non statically typed languages, the learning curve&lt;/li&gt;
&lt;li&gt;❌ Adding extra step — transpiling from .ts files to .js / so many options to consider.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  App vs Library concerns
&lt;/h2&gt;

&lt;p&gt;App perspective&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;More richness when you work with data. You can discover enumerations you can use, overloads of methods you can call.&lt;/li&gt;
&lt;li&gt;Better encapsulation tools. Private, protected, public, read-only. Unintended code is hidden away from end-user&lt;/li&gt;
&lt;li&gt;Improved "major version upgrade" experience, ie. upgrade from Lodash 3 to 4, you get immediate todo list with all those broken code showing typescript checks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Library perspective&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create and maintain public API surface, helps with semantic version guarantees&lt;/li&gt;
&lt;li&gt;Use enums to allow the only type encoded list of values and support for future compatibility, reserve values for future&lt;/li&gt;
&lt;li&gt;SemVer (deprecations, breakage)&lt;/li&gt;
&lt;li&gt;API Docs&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Show me some code examples
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;casing/typing errors&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;plain old .js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let toothBrush = { name:'OracleB', price: 2.99 }

function getProductName(product) {
    console.log(product.Name); //simple case error
}

getProductName(toothBrush)  //undefined

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;type checking .ts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Product= { name:string, price: number}; //type is defined here..

let toothBrush = { name:'OracleB', price: 2.99 }

function getProductName(product: Product) {
    console.log(product.Name); // !! will fail at development time
}

getProductName(toothBrush)


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;undefined is not a function
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
let myFunction;

myFunction('hello'); //Uncaught type error, not defined..

myFunction = (message)=&amp;gt; console.log(message);

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Accidental type coercion
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addFive(num) {
    return num + 5;
}

let result = addFive('hello') // result = hello5

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function addFive(num:number) { ... } // would have fixed this problem in advance.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Myths
&lt;/h3&gt;

&lt;p&gt;It is not going to fix everything, won't fix bad code smells.&lt;/p&gt;

&lt;p&gt;❌ No more runtime errors&lt;br&gt;
❌ Code will run faster&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Typescript Newish Features</title>
      <dc:creator>Bulent Gorkem</dc:creator>
      <pubDate>Tue, 29 Dec 2020 18:04:29 +0000</pubDate>
      <link>https://dev.to/bgorkem/typescript-newish-features-39i0</link>
      <guid>https://dev.to/bgorkem/typescript-newish-features-39i0</guid>
      <description>&lt;p&gt;Introducing useful Typescript features arrived with 3.7 and later&lt;/p&gt;

&lt;p&gt;I learned these from the Frontend Masters course, definitely recommended 👍&lt;/p&gt;

&lt;p&gt;&lt;a href="https://frontendmasters.com/courses/production-typescript"&gt;Production Grade Typescript&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Recursive Type References (3.7)
&lt;/h3&gt;

&lt;p&gt;For example, this was not feasible in 3.6:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ValueOrArray&amp;lt;T&amp;gt; = T | Array&amp;lt;ValueOrArray&amp;lt;T&amp;gt;&amp;gt;; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now type declarations can recursively reference themselves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optional Chaining (3.7)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type ContactDetails =  {
    name: string,
    phone: string,
    address?: {
        city: string,
        street?: string,
    }
}
const myOtherFriend : ContactDetails = { name:'Some Guy', phone:'0123456766'}
console.log(myOtherFriend.address?.street);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Nullish Coalescing (3.7)
&lt;/h3&gt;

&lt;p&gt;raw name is either undefined or null, not empty string, false values&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;this.name = rawName ?? '(no name)';

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Private class fields (3.8)
&lt;/h3&gt;

&lt;p&gt;3.8 adds private fields, which are a way of declaring a class field to&lt;br&gt;
be unavailable outside of the containing class, including to subclasses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Foo {
  #name:string;
  constructor() {
    this.#name = 'whatever'; //ok here
  }  
}
const myVal = new Foo();
myVal.#name // Error! can't access name outside class Foo;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ReExport from (3.8)
&lt;/h3&gt;

&lt;p&gt;With 3.8, TypeScript supports more of the export&lt;br&gt;
statement forms in the JavaScript specs, letting&lt;br&gt;
you write a single line to re-export a module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export * as jestConsole from "@jest/console";
export * as jestReporters from "@jest/reporters";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Variadic Tuple Types (4.0)
&lt;/h3&gt;

&lt;p&gt;A variadic tuple type is a tuple type that has the same properties - defined length and the type of each element is known - but where the exact shape is yet to be defined.&lt;/p&gt;

&lt;p&gt;The first change is that spreads in tuple type syntax can now be generic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// spreads in tuples can be generic now
type GenericTuple&amp;lt;S extends unknown[]&amp;gt; = [first:number,  ...spread:S,  last: string];

const foo:GenericTuple&amp;lt;[boolean, string]&amp;gt; = [12,false,'aaa','aaa'];
const bar:GenericTuple&amp;lt;[number, string, boolean]&amp;gt; = [13,1,'bbb', false,'ccc'];


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second change is that rest elements can occur anywhere in a tuple – not just at the end!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Strings = [string, string];
type Numbers = [number, number];

// [string, string, number, number, boolean]
type StrStrNumNumBool = [...Strings, ...Numbers, boolean];

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Labeled tuple types (4.0)
&lt;/h3&gt;

&lt;p&gt;old style tuple declaration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Address = [ number, string, string, number];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;vs this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Address = [streetNumber: number, streetName: string, houseName: string, houseNumber: number];

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now you can see tuple variables labels in intellisense&lt;/p&gt;

&lt;p&gt;instead of this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printAddress(/*address_0*/54,/*address_1*/'regents street',/*address_2*/'whitehouse', /*address_3*/12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you get this..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;printAddress(/*streetNumber*/54,/*streeName*/'regents street',/*houseName*/'whitehouse', /*houseNumber*/12)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Template type literals (4.1)
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Features = "Redesign" | "newArtistPage";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.1 supports a set of new generic-like keywords which&lt;br&gt;
you can use inside a template literal to manipulate strings.&lt;br&gt;
These are: Uppercase, Lowercase, Capitalize and Uncapitalize&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type FeatureID = `${Lowercase&amp;lt;Features&amp;gt;}-id`;
type FeatureEnvVar = `${Uppercase&amp;lt;Features&amp;gt;}-ID`;

const z: FeatureID = 'redesign-id'; //works
const t: FeatureID = 'Redesign-id'; //not valid
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>typescript</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A Micro FrontEnd Journey</title>
      <dc:creator>Bulent Gorkem</dc:creator>
      <pubDate>Thu, 23 Jul 2020 16:07:41 +0000</pubDate>
      <link>https://dev.to/bgorkem/a-micro-frontend-journey-158e</link>
      <guid>https://dev.to/bgorkem/a-micro-frontend-journey-158e</guid>
      <description>&lt;h3&gt;
  
  
  What we need
&lt;/h3&gt;

&lt;p&gt;A scalable, modular, dev-ops friendly, enterprise grade web app hosting platform (ie. Shell) which will compose multiple SPAs side-by-side and allow them to communicate with each other under a single website brand.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpnh753p5xhnoy9hmzeib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpnh753p5xhnoy9hmzeib.png" alt="Micro FrontEnds composition"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  MFE features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Single Page Apps (SPAs) should follow Micro Services development principles, hence each SPA can be also called Micro FrontEnd following the same terminology.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MFEs should be lightweight and should focus on one business workflow (e.g one for Accounts, one for Recipients, one for Making Payment, one for Statements ...) &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They can be developed using different UI Frameworks ( React, Angular, Vue, Svelte ) depending on application requirements or team's skillsets. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They should share a common look and feel via modular CSS, they can also share common functionality via WebComponents  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They live independently, developed, versioned, deployed separately. Should not clash with each other when composed, no global pollution, double loading React or conflicting versions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They are lazy loaded at runtime (they have to implement a common interface), by the hosting shell app. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;They manage their own App state but also raise / subscribe to events so they can communicate with each other.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Shell features
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The security context (login / logout / session monitor, permissions), &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lazy loading and layout of MFEs at runtime when routed&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lifecycle management of each MFE as they get mounted or unmounted.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What have we used to build this
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://lerna.js.org/" rel="noopener noreferrer"&gt;Lerna&lt;/a&gt; to organise our sample code as a &lt;a href="https://en.wikipedia.org/wiki/Monorepo" rel="noopener noreferrer"&gt;monorepo&lt;/a&gt; to manage independent MFEs in a single repository for convenience. In a multi team environment, this may not be desirable. &lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lerna behind the scenes uses &lt;a href="https://classic.yarnpkg.com/en/docs/workspaces" rel="noopener noreferrer"&gt;Yarn workspaces&lt;/a&gt; to link multiple package dependencies and install all MFEs and Shell in one go using &lt;code&gt;yarn install&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/systemjs/systemjs" rel="noopener noreferrer"&gt;SystemJS&lt;/a&gt; Dynamic ES Module loader polyfill (which will eventually be replaced with es-modules when all browsers support import-maps). SystemJS is like AMD allows multiple assets to be dynamically loaded on demand.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://single-spa.js.org/" rel="noopener noreferrer"&gt;SingleSPA&lt;/a&gt; to register and manage individual MicroFEs implemented with different FWs ( React and Svelte example here)   &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Where is the code
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/bgorkem/mfe-base" rel="noopener noreferrer"&gt;Micro FrontEnds Base&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;ReadMe documentation should give you all the know-how you need&lt;/p&gt;

&lt;h3&gt;
  
  
   Links
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://micro-frontends.org/" rel="noopener noreferrer"&gt;Microfrontends.org&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://martinfowler.com/articles/micro-frontends.html" rel="noopener noreferrer"&gt;Cam Jackson's article on Martin Fowler website&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Also inspired from Jack Harrington's Youtube posts &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wxnwPLLIJCY"&gt;
&lt;/iframe&gt;
&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/wU06eTMQ6yI"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
