<?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: Akash Kava</title>
    <description>The latest articles on DEV Community by Akash Kava (@akashkava).</description>
    <link>https://dev.to/akashkava</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%2F52744%2F152ad31a-2eb2-4b67-8d6a-0da3a1fddf9e.jpg</url>
      <title>DEV Community: Akash Kava</title>
      <link>https://dev.to/akashkava</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akashkava"/>
    <language>en</language>
    <item>
      <title>Positron-JS for DotNet Maui</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Tue, 03 Sep 2024 04:18:07 +0000</pubDate>
      <link>https://dev.to/akashkava/positron-js-for-dotnet-maui-2295</link>
      <guid>https://dev.to/akashkava/positron-js-for-dotnet-maui-2295</guid>
      <description>&lt;p&gt;An Advanced Web View based Maui Project. This project was inspired from Cordova/Capacitor. However, building native plugins is very time consuming. Maui offers single language to write native plugins easy on any platform. So we decided to create Capacitor/Electron-JS for Maui.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why?
&lt;/h1&gt;

&lt;p&gt;Well C# is better language when we want to develop native apps for Android and iOS, however writing everything in C# and deploying app is very time consuming as every build needs to go through app store approvals. Often app store reviewers have no idea about the apps and they keep on clicking on the most unused parts of apps and complain about something trivial and reject the approval.&lt;/p&gt;

&lt;p&gt;We wanted to use Capacitor or React Native, but both of them suffer plugin creation as plugins has to be created in native languages, (Java for Android and Swift on iOS), which requires two separate set of codebases and different expertise.&lt;/p&gt;

&lt;p&gt;So we decided to build a &lt;code&gt;PositronWebView&lt;/code&gt; that offers easy hybrid app creation along with simple API to access Device's native interface.&lt;/p&gt;

&lt;h1&gt;
  
  
  Is HTML Fast?
&lt;/h1&gt;

&lt;p&gt;With recent advancement in HTML5 + CSS3 and JavaScript updates, creating web UI is easier than native UI, you can create almost all effects in HTML. The key to make app superfast is to drop the bulky JavaScript Frameworks, for example using instead of using &lt;code&gt;$('.price').text("$20")&lt;/code&gt; you should use &lt;code&gt;document.getElementsById("price").textContent = "$20"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Try to use inbuilt CSS animation vs JavaScript to emulate animations.&lt;/p&gt;

&lt;p&gt;Our own Web Atoms framework is superfast, but you have your own choice to use any framework you want with &lt;code&gt;PositronWebView&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty folder&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm init&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm install -s @positron-js/cli&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;node ./node_modules/@positron-js/cli init&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm install&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will create a maui project inside maui folder. Along with build scripts to publish.&lt;/p&gt;

&lt;h1&gt;
  
  
  Open Web URL
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;PositronWebView&lt;/code&gt; expects URL for website, you can directly open remote URL and expose &lt;code&gt;positron&lt;/code&gt; context. You can also limit exposure of &lt;code&gt;positron&lt;/code&gt; context by setting &lt;code&gt;ShouldInvokeScript&lt;/code&gt; delegate.&lt;/p&gt;

&lt;p&gt;The url is set in build script's &lt;code&gt;config.js&lt;/code&gt; file, you can also configure url in &lt;code&gt;appsetting.json&lt;/code&gt; file.&lt;/p&gt;

&lt;h1&gt;
  
  
  Access .NET API
&lt;/h1&gt;

&lt;p&gt;Positron exposes positron property on window object, with run method. Positron installs JavaScript engine (YantraJS in Android and JavaScriptCore in iOS), which integrates with CLR. So you can write JavaScript that access CLR objects directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Example - Get DeviceToken
&lt;/h2&gt;

&lt;p&gt;Lets assume that we have configured push messaging and we want to retrieve the device token. (For convenience, we have created Positron class that gives you deviceToken), you have to enable &lt;code&gt;RegisterPushMessaging&lt;/code&gt; in &lt;code&gt;MauApplication.cs&lt;/code&gt; file, which is commented by default as it gives build errors if &lt;code&gt;google-services.json&lt;/code&gt; is not configured correctly.&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;import&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&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;@positron-js/context/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cm"&gt;/** Although syntactically correct, this function
     * will be executed inside Positron's JavaScript Engine.
     * And the result will be available after successful execution.
     * 
     * This function cannot contain any closer except `global`;
     */&lt;/span&gt;

    &lt;span class="cm"&gt;/** Basically positron.run() will send script text and parameters */&lt;/span&gt;
    &lt;span class="cm"&gt;/* (as json) to Positron's JavaScript engine */&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deviceToken&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// this runs inside App's Internal JavaScript Engine&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;NSPositronAssembly&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;clr&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;NeuroSpeech.Positron&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Positron&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;NSPositronAssembly&lt;/span&gt;
            &lt;span class="c1"&gt;// following is fully qualified name&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;NeuroSpeech&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Positron&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Positron&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;Positron&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deviceToken&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;h2&gt;
  
  
  Example - Open Url
&lt;/h2&gt;

&lt;p&gt;Lets assume you want to open native browser instead of navigating WebView.&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;import&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&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;@positron-js/context/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Essentials&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;clr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Microsoft.Maui.Essentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Browser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Essentials&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ApplicationModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Browser&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nx"&gt;Browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;openAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://socialmail.me&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Note, we are sending parameters as first parameter in call to &lt;code&gt;run&lt;/code&gt; method. And same parameters object can be accessed inside &lt;code&gt;function(p)&lt;/code&gt;. You can only pass plain non recursive primitive types in parameters. As they are sent to Positron as JSON.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example - Create New Instance
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&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;@positron-js/context/index.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;PositronInBrowser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Essentials&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;clr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Microsoft.Maui.Essentials&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Graphics&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;clr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Microsoft.Maui.Graphics&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Browser&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;BrowserLaunchOptions&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Essentials&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ApplicationModel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Microsoft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Maui&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Graphics&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BrowserLaunchOptions&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;preferredToolbarColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Colors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;Browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;openAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://socialmail.me&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h1&gt;
  
  
  Positron Context
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;PositronWebView&lt;/code&gt; creates a new JavaScript context (JavaScriptCore in iOS and YantraJS on other platforms) and it exposes &lt;code&gt;clr.assembly&lt;/code&gt; function, which you can access by calling &lt;code&gt;this.clr.assembly&lt;/code&gt;, from this assembly you can easily access namespaces and types.&lt;/p&gt;

&lt;p&gt;Once you have types, you can call methods or construct an objects from it.&lt;/p&gt;

&lt;p&gt;For convenience we have created &lt;code&gt;@positron-js/context&lt;/code&gt; npm package which exposes typescript definitions for &lt;code&gt;Microsoft.Maui.Graphics&lt;/code&gt;, &lt;code&gt;Microsoft.Maui.Essentials&lt;/code&gt; and &lt;code&gt;NeuroSpeech.Positron&lt;/code&gt; assemblies.&lt;/p&gt;

&lt;p&gt;You can add your own assemblies easier, the source code is available on github &lt;a href="https://github.com/Positron-JS/context" rel="noopener noreferrer"&gt;https://github.com/Positron-JS/context&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  AOT and Linking
&lt;/h1&gt;

&lt;p&gt;For &lt;code&gt;PositronWebView&lt;/code&gt; to access all CLR objects, Linking must be disabled and interpreter must be turned on, these settings are automatically set when cli creates a sample project.&lt;/p&gt;

&lt;p&gt;Using interpreter, reduces code size, but it does add performance overhead. However, if you do your most stuff inside HTML, browser's native performance will take care of everything. And if you only need to occasionally access .NET APIs such as geolocation or push registration token, select files etc, there would be no visible performance issues.&lt;/p&gt;
&lt;h1&gt;
  
  
  Publishing
&lt;/h1&gt;

&lt;p&gt;To publish the project, you must execute &lt;code&gt;.jsx&lt;/code&gt; file with &lt;code&gt;@neurospeech/jex&lt;/code&gt; as shown below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node ./node_modules/@neurospeech/jex/index.js ./build-android.jsx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Jex is a new scripting engine that executes jsx files as a build script, and you can easily edit them and utilize JavaScript in the build script.&lt;/p&gt;

&lt;p&gt;You just have to configure environment variables and put your certificates in cert folder, you can review &lt;code&gt;build-%%%%%-config.js&lt;/code&gt; file to find out what every platform needs.&lt;/p&gt;
&lt;h1&gt;
  
  
  Positron Web View Repository
&lt;/h1&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Positron-JS" rel="noopener noreferrer"&gt;
        Positron-JS
      &lt;/a&gt; / &lt;a href="https://github.com/Positron-JS/positron-web-view" rel="noopener noreferrer"&gt;
        positron-web-view
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Positron JS WebView for MAUI
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Positron Web View&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;An Advanced Web View based Maui Project. This project was inspired from Cordova/Capacitor. However, building native plugins is very time consuming. Maui offers single language to write native plugins easy on any platform. So we decided to create Capacitor for Maui.&lt;/p&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/Positron-JS/positron-web-view./diagram.jpg"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8JuvDD1S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://github.com/Positron-JS/positron-web-view./diagram.jpg" alt="Positron Diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Get Started&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://www.nuget.org/packages/NeuroSpeech.Positron" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/ac2b9e498f65cb8e32e5cc4927777ef211d293c321c59ffe55c848365e1de606/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f762f4e6575726f5370656563682e506f736974726f6e2e7376673f6c6162656c3d4e75476574" alt="NuGet"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create an empty folder&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm init&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm install -s @positron-js/cli&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;node ./node_modules/@positron-js/cli init&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;npm install&lt;/code&gt; again.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This will create a maui project inside maui folder. Along with build scripts to publish.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Publish&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;To publish the project, you must execute &lt;code&gt;.jsx&lt;/code&gt; file with &lt;code&gt;@neurospeech/jex&lt;/code&gt; as shown below.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node ./node_modules/@neurospeech/jex/index.js ./build-android.jsx&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Jex is a new scripting engine that executes jsx files as a build script, and you can easily edit them and utilize JavaScript in the build script.&lt;/p&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Access .NET Inside Browser&lt;/h1&gt;

&lt;/div&gt;

&lt;p&gt;Positron exposes &lt;code&gt;positron&lt;/code&gt; property on &lt;code&gt;window&lt;/code&gt; object, with &lt;code&gt;run&lt;/code&gt; method. Positron installs JavaScript engine (YantraJS in Android and JavaScriptCore in…&lt;/p&gt;
&lt;/div&gt;


&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Positron-JS/positron-web-view" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>javascript</category>
      <category>dotnet</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Introducing new JavaScript Engine YantraJS for DotNet</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Wed, 27 Oct 2021 08:46:31 +0000</pubDate>
      <link>https://dev.to/web-atoms/introducing-new-javascript-engine-yantrajs-for-dotnet-49h0</link>
      <guid>https://dev.to/web-atoms/introducing-new-javascript-engine-yantrajs-for-dotnet-49h0</guid>
      <description>&lt;p&gt;We are happy to announce a brand new Open Source JavaScript engine completely written in C# for .NET.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managed JavaScript Runtime
&lt;/h2&gt;

&lt;p&gt;YantraJS is a JavaScript runtime written in .NET Standard. Yantra has two components, Expression Compiler and JavaScript engine.&lt;/p&gt;

&lt;p&gt;It is written in .NET standard, so it runs everywhere except iOS which enforces JIT restrictions. However, with help of an interpreter you can still use it on iOS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why did we build it?
&lt;/h2&gt;

&lt;p&gt;We wanted a JavaScript engine with complete support of ES6, including generators and async/await. And we want to officially support as a commercial product. YantraJS is open source.&lt;/p&gt;

&lt;h2&gt;
  
  
  License
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Apache 2.0 License&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For more details, please visit &lt;a href="https://yantrajs.com"&gt;YantraJS Website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Compiles JavaScript to .Net Assembly &lt;/li&gt;
&lt;li&gt;Strict Mode Only JavaScript*&lt;/li&gt;
&lt;li&gt;Arrow functions&lt;/li&gt;
&lt;li&gt;Classes&lt;/li&gt;
&lt;li&gt;Enhanced object literals&lt;/li&gt;
&lt;li&gt;Template strings and tagged templates&lt;/li&gt;
&lt;li&gt;Destructuring&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;let&lt;/code&gt; &lt;code&gt;const&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Map, Set, WeakMap, WeakSet&lt;/li&gt;
&lt;li&gt;Symbols&lt;/li&gt;
&lt;li&gt;Subclassable built-ins&lt;/li&gt;
&lt;li&gt;Binary and Octal literals&lt;/li&gt;
&lt;li&gt;Module support&lt;/li&gt;
&lt;li&gt;Null coalesce&lt;/li&gt;
&lt;li&gt;Optional property chain &lt;code&gt;identifier?.[]&lt;/code&gt;, &lt;code&gt;identifier?.(&lt;/code&gt;, &lt;code&gt;identifier?.identifier&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Rest, Default and Spread Parameters&lt;/li&gt;
&lt;li&gt;Generators, iterators, for..of&lt;/li&gt;
&lt;li&gt;Async/Await&lt;/li&gt;
&lt;li&gt;Optional parameters&lt;/li&gt;
&lt;li&gt;Many ES5 + ES6 features&lt;/li&gt;
&lt;li&gt;CommonJS Module Support&lt;/li&gt;
&lt;li&gt;Easily marshal CLR Object to JavaScript and other way around&lt;/li&gt;
&lt;li&gt;CSX Module support&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;*&lt;/code&gt; Most JavaScript today is available in strict mode, we do not feel any need to support non strict mode as modules are strict by default.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roadmap
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Support for V8 Debugger Protocol&lt;/li&gt;
&lt;li&gt;Increase ECMAScript conformance&lt;/li&gt;
&lt;li&gt;Faster IL Serialization&lt;/li&gt;
&lt;li&gt;Faster Debugging&lt;/li&gt;
&lt;li&gt;Support for module pollyfills (ability to redirect default node modules, to support dual platform)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  ECMAScript Conformance
&lt;/h2&gt;

&lt;p&gt;Currently we are seeing more than 70% conformance to ECMAScript, reaching 100% is little out of scope as it is very huge and Yantra is only one year old. We are focusing on supporting most used JavaScript patterns instead of targeting 100% compliance due to limited development bandwidth.&lt;/p&gt;

&lt;h2&gt;
  
  
  Expression Compiler
&lt;/h2&gt;

&lt;p&gt;YantraJS is built on custom Expression Compiler, which allows us to create expressions similar to that of Linq Expressions. Expression Compiler has several methods to generate IL, you can compile expression to &lt;code&gt;MethodBuilder&lt;/code&gt;. Since there is no support for Linq to compile expressions to &lt;code&gt;MethodBuilder&lt;/code&gt;, Yantra Expression Compiler was written from ground up to support saving IL to various ways.&lt;/p&gt;

&lt;h2&gt;
  
  
  Engine Types
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;JSContext - plain JavaScript context&lt;/li&gt;
&lt;li&gt;JSModuleContext - context with modules and clr support&lt;/li&gt;
&lt;li&gt;YantraJSContext - context with modules, clr and CSX Module support&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  How to use?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Simple Execution
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;JSContext&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// create global function&lt;/span&gt;
&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"add"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;JSFunction&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;Arguments&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;JSNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="n"&gt;IntValue&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="m"&gt;0&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="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="n"&gt;IntValue&lt;/span&gt; &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="m"&gt;0&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="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FastEval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"add(4,5)"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"script.js"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Wrap CLR Object
&lt;/h3&gt;

&lt;p&gt;Custom CLR types can be wrapped in ClrProxy which will allow you to call any methods directly from JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"createUri"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateFunction&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;Arguments&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;uri&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Uri&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]?.&lt;/span&gt;&lt;span class="nf"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; 
          &lt;span class="p"&gt;??&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;NewReferenceError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                   &lt;span class="s"&gt;"At least one parameter expected"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ClrProxy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="s"&gt;"add"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FastEval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="s"&gt;"var uri = createUri('https://yantrajs.com'); uri.host"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For more information on how to use various types, please visit &lt;a href="https://github.com/yantrajs/yantra/wiki/JavaScript-Engine-Example"&gt;YantraJS Examples&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Alternative to Razor View in ASP.NET Core
&lt;/h2&gt;

&lt;p&gt;We have created our website using JavaScript as view instead of Razor view, though it started as a simple application, but we realized that by using JavaScript as view, we can easily plugin Server Side Rendering and improve page delivery speed. However, using traditional JSDom is not yet supported due to very heavy dependency on various built in node modules. But you can easily create a wrapper with mocks to render content of your React/Angular components on server easily with YantraJS. Check out source code for our website at &lt;a href="https://github.com/yantrajs/web-site"&gt;Github Repository for YantraJS Website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Originally Posted at &lt;a href="https://www.webatoms.in/blog/yantra-js/Introducing-new-JavaScript-Engine-YantraJS-for-DotNet-2g"&gt;Introducing YantraJS - Web Atoms Blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>showdev</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Difference between instanceOf Array and Array.isArray</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Mon, 18 Oct 2021 10:35:37 +0000</pubDate>
      <link>https://dev.to/akashkava/difference-between-instanceof-array-and-arrayisarray-4j7f</link>
      <guid>https://dev.to/akashkava/difference-between-instanceof-array-and-arrayisarray-4j7f</guid>
      <description>&lt;p&gt;There are two major differences between &lt;code&gt;instanceOf Array&lt;/code&gt; and &lt;code&gt;Array.isArray&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cross Context Object
&lt;/h2&gt;

&lt;p&gt;In browser, when you access object from different window (such as different iframe from same domain), &lt;code&gt;instanceOf Array&lt;/code&gt; will return false. However &lt;code&gt;Array.isArray&lt;/code&gt; will return true.&lt;/p&gt;

&lt;p&gt;For example,&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;iframe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;iframe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;iframe&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;iArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frames&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;frames&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;iArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// [1,2,3]&lt;/span&gt;

&lt;span class="c1"&gt;// Correctly checking for Array&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="c1"&gt;// Considered harmful, because doesn't work through iframes&lt;/span&gt;
&lt;span class="nx"&gt;arr&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;Well internally, all root level (global) functions/constructors such as &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Object&lt;/code&gt; are isolated under the currently executing contexts. Two browser windows or two iframes will have different context and object created in one context will have prototype associated with the context.&lt;/p&gt;

&lt;p&gt;When object is accessed in different context, &lt;code&gt;instanceOf&lt;/code&gt; will fail to identify object's prototype chain in current context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Created with &lt;code&gt;Object.create&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prototype&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{});&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// it will display '1,2'.&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// it will display '1,2'.&lt;/span&gt;

&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isArray&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="nx"&gt;instanceOf&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="nx"&gt;instanceOf&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Why?
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;Object.create&lt;/code&gt;, Array.prototype is present in prototype chain of &lt;code&gt;a&lt;/code&gt;, so &lt;code&gt;instanceOf Array&lt;/code&gt; will be true, as in the context of JavaScript, a has prototype of Array. So all the methods of &lt;code&gt;Array&lt;/code&gt; will work correctly on &lt;code&gt;a&lt;/code&gt; as those methdos are generic.&lt;/p&gt;

&lt;p&gt;But &lt;code&gt;Array.isArray&lt;/code&gt; does not check for prototype, it checks if it was created using &lt;code&gt;Array&lt;/code&gt; constructor, which internally is a separate type of object in the language it was implemented. Such as in V8, &lt;code&gt;Array&lt;/code&gt; constructor will create an object of class &lt;code&gt;V8Array&lt;/code&gt; which inherits &lt;code&gt;V8Object&lt;/code&gt;. And &lt;code&gt;Object.create&lt;/code&gt; will create &lt;code&gt;V8Object&lt;/code&gt;. &lt;code&gt;Array.isArray&lt;/code&gt; method in V8 will check if the receiver is instance of &lt;code&gt;V8Array&lt;/code&gt; class in C++. Similarly every JavaScript engine will check natively, what kind of object it is, rather then checking prototype.&lt;/p&gt;

&lt;p&gt;Originally Posted at &lt;a href="https://www.webatoms.in/blog/general/Difference-between-instanceOf-Array-and-Array-isArray-2f"&gt;Web Atoms Blog - Difference between instanceOf Array and Array.isArray&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Web Atoms for Xamarin Forms vs React Native</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Thu, 18 Feb 2021 04:56:11 +0000</pubDate>
      <link>https://dev.to/web-atoms/web-atoms-for-xamarin-forms-vs-react-native-512a</link>
      <guid>https://dev.to/web-atoms/web-atoms-for-xamarin-forms-vs-react-native-512a</guid>
      <description>&lt;h1&gt;
  
  
  Xamarin Forms
&lt;/h1&gt;

&lt;p&gt;Xamarin Forms provides platform independent UI framework, however the code is natively compiled, it gives you speed but deployment is lengthy process. Xamarin Forms makes it easier to create and deploy custom UI components using Custom Renderers.&lt;/p&gt;

&lt;h1&gt;
  
  
  React Native
&lt;/h1&gt;

&lt;p&gt;React Native on other hand provides quick updates but to achieve native performance, and for custom UI components, you need to write code in different platforms in different languages.&lt;/p&gt;

&lt;h1&gt;
  
  
  Web Atoms
&lt;/h1&gt;

&lt;p&gt;With Web Atoms, we decided to bring all features of React Native in Xamarin Forms to get the best of both.&lt;/p&gt;

&lt;h2&gt;
  
  
  Native Component
&lt;/h2&gt;

&lt;p&gt;We are always in need to create native components when framework components don't provide exact features we need. In case of React Native, we are left to create new components in Java/Kotlin for Android and in Swift for iOS. In Xamarin Forms, we can create custom components by combining existing platform neutral controls or write custom renderers in different platform but all in C#. &lt;/p&gt;

&lt;p&gt;In Web Atoms, you can create custom controls using JavaScript and in C#, (Writing in C# will require you to redeploy application in AppStore).&lt;/p&gt;

&lt;h2&gt;
  
  
  JSX + JavaScript Support
&lt;/h2&gt;

&lt;p&gt;Xamarin Forms does not have any support for JSX + JavaScript, React Native and Web Atoms, both provides support for JSX.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support for NuGet Packages
&lt;/h2&gt;

&lt;p&gt;In Xamarin Forms you can reuse all existing NuGet Packages. There is no support for NuGet packages in React Native as it is not built on .NET framework.&lt;/p&gt;

&lt;p&gt;In Web Atoms, you can reuse all existing NuGet Packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Support for NPM Packages
&lt;/h2&gt;

&lt;p&gt;Since there is no support for JavaScript, using NPM package is not possible. In React Native, you can use most of NPM Packages.&lt;/p&gt;

&lt;p&gt;In Web Atoms, you can use most of NPM Packages as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Reload in Production
&lt;/h2&gt;

&lt;p&gt;Application deployment is becoming lengthy day by day, the queue to publish new update is increasing and also subject to approval.&lt;/p&gt;

&lt;p&gt;Live Reload allows user to refresh the app version without having to download the app from the respective store.&lt;/p&gt;

&lt;p&gt;In Xamarin Forms, it is not possible to provide live reload as entire code is natively compiled and shipped via store.&lt;/p&gt;

&lt;p&gt;In React Native and Web Atoms for Xamarin Forms, you can provide live reload in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Binding and MVVM Pattern
&lt;/h2&gt;

&lt;p&gt;Xamarin Forms has excellent One, Two way binding and MVVM Pattern support.&lt;/p&gt;

&lt;p&gt;React Native is purely functional and there are no inbuilt binding/MVVM concepts.&lt;/p&gt;

&lt;p&gt;In Web Atoms, we have created Binding and MVVM support to reduce learning time, you can easily translate Xaml + C#  to JSX + JavaScript with exact similar concepts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependency Injection
&lt;/h2&gt;

&lt;p&gt;Xamarin Forms has simple dependency injection and Prism provides advanced dependency injection.&lt;/p&gt;

&lt;p&gt;React Native does not have dependency injection, but there are other frameworks in NPM in which you can achieve same.&lt;/p&gt;

&lt;p&gt;Web Atoms provides Prism kind of Dependency Injection in JavaScript with decorators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reuse Existing C# Code
&lt;/h2&gt;

&lt;p&gt;If you have your backend and most of your front end application already has C# code, reusing them in Xamarin Forms is very easy.&lt;/p&gt;

&lt;p&gt;Using existing C# code in React Native is not easy, either you will have to rewrite it in JavaScript or provide server side rest proxy.&lt;/p&gt;

&lt;p&gt;Using existing C# code in Web Atoms is as easy as using in Xamarin Forms. In fact, you can use Web Atoms in existing app without having to rewrite most of its parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Side by Side versioning
&lt;/h2&gt;

&lt;p&gt;Since Xamarin Forms apps are compiled natively, you cannot allow users to switch the version, this is very useful in beta test, early adopter tests. For admin and investigation purpose.&lt;/p&gt;

&lt;p&gt;In React Native, apps are mostly in JavaScript, it is possible to load JavaScript from server and it is possible to switch to different version for various investigation/debugging purpose.&lt;/p&gt;

&lt;p&gt;In Web Atoms for Xamarin Forms, apps are mostly in JavaScript and they can be loaded from server, it is possible to use different versions.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Xamarin Forms&lt;/th&gt;
&lt;th&gt;React Native&lt;/th&gt;
&lt;th&gt;Web Atoms for Xamarin Forms&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Native Component Implementation Languages&lt;/td&gt;
&lt;td&gt;C#&lt;/td&gt;
&lt;td&gt;JavaScript, Swift, Java&lt;/td&gt;
&lt;td&gt;JavaScript, C#&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;JSX + JavaScript Support&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support for NuGet Packages&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Support for NPM Packages&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Live Reload in Production&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Binding and MVVM Pattern&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Dependency Injection&lt;/td&gt;
&lt;td&gt;Requires Prism&lt;/td&gt;
&lt;td&gt;Requires other packages&lt;/td&gt;
&lt;td&gt;Inbuilt&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reuse Existing C# Code, if you already have various  application logic already available in C#&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Side by side versioning (Use different versions of Application  without uninstall/reinstall)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Possible&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Exception Line Numbers in Production&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Available&lt;/td&gt;
&lt;td&gt;Available&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
      <category>xamarinforms</category>
      <category>reactnative</category>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Today it is Parler, Tomorrow it could be Us</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Wed, 13 Jan 2021 04:49:57 +0000</pubDate>
      <link>https://dev.to/akashkava/today-it-is-parler-tomorrow-it-could-be-us-136</link>
      <guid>https://dev.to/akashkava/today-it-is-parler-tomorrow-it-could-be-us-136</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This post does not justify content on parler or its way of doing business. Whatever happened on Parler may not be legal, but even criminal judgement requires trial, Should Big Tech take justice on their hand?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Small business is Dying
&lt;/h1&gt;

&lt;p&gt;Imagine you are a small business running a small social network, you have only some budget to maintain the network, advertise and generate revenue. Suddenly some group of people on network does something offensive, it spreads like wildfire and Apple, Amazon and Google collectively decide to kick you out of network. &lt;/p&gt;

&lt;p&gt;You can find hosting, but Apple and Google controls complete App market.&lt;/p&gt;

&lt;p&gt;The only thing you are left with is world wide web, within limited browser with slow UI which no one is comfortable with. Notifications/calendar many things are difficult to implement.&lt;/p&gt;

&lt;p&gt;Amazon killed small shop owners, Apple, Google, Facebook are killing small social networks by making the entry and survival very difficult.&lt;/p&gt;

&lt;h1&gt;
  
  
  Apple Google Amazon Facebook, all are watching US
&lt;/h1&gt;

&lt;p&gt;These companies have information about probably every individual on internet, I am sure they have more information about US than our government. Google started presenting my "Interesting Article" in Google search home page, this means that Google has kept all my search engine history since day 1 unless I manually go and delete it.&lt;/p&gt;

&lt;p&gt;All information in big tech is watched by default.&lt;/p&gt;

&lt;h1&gt;
  
  
  Web Browser isn't free anymore
&lt;/h1&gt;

&lt;p&gt;Apple owns Safari, Google owns Chrome, This comprises of 90% of users of web. Everything is forced upon by these two browsers.&lt;/p&gt;

&lt;p&gt;I got annoyed when our users didn't want Browser to store username/password, we spend so much time in customer support that it is done by browser fast and automatic, and we cannot control, even after specifying &lt;code&gt;auto-complete="off"&lt;/code&gt;, both browsers simply ignore this as per their term. Me as a developer and my customers as users do not want this, but both of us do not have any good handle on it. Our users are old and non tech savvy, it is very annoying to explain this at least once a day to them.&lt;/p&gt;

&lt;h1&gt;
  
  
  Communication is Restricted indirectly
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;As mentioned above, Safari and Chrome are forcing Web Standard upon us and way to stop/alternative is very long.&lt;/li&gt;
&lt;li&gt;Instagram does not allow business profiles unless you open an ads account with Facebook and spend money (Instagram puts you on shadow ban).&lt;/li&gt;
&lt;li&gt;GMail API is restricted by Google, and access requires approval by Google after reviewing the process of how the app will use the Api. Here it is a problem for developers and customers, emails belong to customer and they are buying app from developer to manage email. Google should not sit as a Gatekeeper because that is not what customers have signed up for. Many customers aren't realizing this now.&lt;/li&gt;
&lt;li&gt;Once we had Amazon complain about outgoing email, (due to some error, many bounce resulted due to extra character in email address), Amazon threatened to stop account. SES is a problem, we realized we are at mercy of Amazon. Bounce wasn't problem, they analyzed outgoing content and gave us some improvement tips on spam check. I didn't opt for them to read and do spam check. We immediately moved out of it.&lt;/li&gt;
&lt;li&gt;The biggest problem is "Content Guidelines", it is impossible to setup an easy framework to moderate content. I bet you can easily report competitors content on social media to make them suffer.&lt;/li&gt;
&lt;li&gt;Apple isn't allowing financial transactions in the app without you agreeing to pay 30% of your hard earn money.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  So what can we do?
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Us Multiple hosting providers along with cloud, and avoid cloud services such as SQS, SNS.&lt;/li&gt;
&lt;li&gt;Create an abstract microservice service on top of cloud service in such a way that in case of outage/suspension you can easily migrate to an alternative service.&lt;/li&gt;
&lt;li&gt;Avoid any cloud service except storage and pure compute, it is easy to move your VM from one service to even smaller hosting provider with bare metal servers.&lt;/li&gt;
&lt;li&gt;It will take little longer to build basic services but "Parler" is a lesson for small business to avoid Amazon Web Services.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Software License
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;License of a purchased software is still more valuable than cloud service.&lt;/li&gt;
&lt;li&gt;It is considered as an asset in your company's balance sheet and you are allowed to use it as long as you are alive on same type and quantity of hardware.&lt;/li&gt;
&lt;li&gt;You can even install a software in a personal computer in your Garage.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Keep little distance from Large Social Media
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Create your own blog&lt;/li&gt;
&lt;li&gt;Publish content at multiple locations&lt;/li&gt;
&lt;li&gt;Always gather readers back to your own website&lt;/li&gt;
&lt;li&gt;Collect email addresses of your users (opt in) not automatic by telling them to subscribe.&lt;/li&gt;
&lt;li&gt;Email communication is still relevant and should be made more important than gated community.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  We need improvements in Email and we need to be free from Social Media.
&lt;/h1&gt;

</description>
      <category>cloud</category>
      <category>watercooler</category>
    </item>
    <item>
      <title>JavaScript does not cache array.length</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Wed, 30 Sep 2020 15:20:47 +0000</pubDate>
      <link>https://dev.to/akashkava/javascript-does-not-cache-array-length-2n65</link>
      <guid>https://dev.to/akashkava/javascript-does-not-cache-array-length-2n65</guid>
      <description>&lt;h1&gt;
  
  
  Myth: &lt;code&gt;array.length&lt;/code&gt; is cached by JavaScript Engine
&lt;/h1&gt;

&lt;p&gt;I have seen many comments and posts saying that JavaScript VM caches array.length for optimization.&lt;/p&gt;

&lt;p&gt;So following piece of code is not required...&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this one is automatically optimized by modern compilers.&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well this is a myth, compiler can optimize but only if the for loop does not call any other method and performs simple mathematical steps.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://jsfiddle.net/4fao0jpn//embedded//dark" width="100%" height="600"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;In above example,&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

   &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;f&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;i&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&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="nx"&gt;n&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;n&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&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;The output should be &lt;code&gt;0,1,2,3&lt;/code&gt; if engine caches &lt;code&gt;array.length&lt;/code&gt;, but if you notice, the output is &lt;code&gt;0,1,2,3,4,5&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This means that &lt;code&gt;a.length&lt;/code&gt; is read before every comparison.&lt;/p&gt;

&lt;h1&gt;
  
  
  Optimization is expensive
&lt;/h1&gt;

&lt;p&gt;Source level analysis of script is an expensive process, if JavaScript engine would spend time on detect complex logic to decide whether to cache or not, it would slow down startup time. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>showdev</category>
    </item>
    <item>
      <title>Why isn’t mainstream Linux available for mobile?</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Sat, 12 Sep 2020 03:22:08 +0000</pubDate>
      <link>https://dev.to/akashkava/why-isn-t-mainstream-linux-available-for-mobile-188e</link>
      <guid>https://dev.to/akashkava/why-isn-t-mainstream-linux-available-for-mobile-188e</guid>
      <description>&lt;p&gt;I am tired of iOS and all restrictions. I like PC because we have choice to virtualize, use any OS and any product from any company. &lt;/p&gt;

&lt;p&gt;Why hasn’t anyone invested in open OS that can be installed on any phone. Just like Linux.&lt;/p&gt;

&lt;p&gt;Android is there but it is still in control of Google. &lt;/p&gt;

&lt;p&gt;What is stopping people from creating free OS for any or at lest most recent mobile phones?&lt;/p&gt;

&lt;p&gt;LLVM compiler tools are available for all processor types and are used to compile native mobile libraries.&lt;/p&gt;

&lt;p&gt;Is there any project already doing this?&lt;/p&gt;

&lt;p&gt;Why isn’t Linux community doing anything?&lt;/p&gt;

&lt;p&gt;Pine64 looks interesting, but is it fork of Android? Can we fork it and create own private distro?&lt;/p&gt;

</description>
      <category>linux</category>
      <category>mobile</category>
      <category>discuss</category>
    </item>
    <item>
      <title>C# Pattern Matching Performance Overhead</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Thu, 10 Sep 2020 15:49:32 +0000</pubDate>
      <link>https://dev.to/akashkava/c-pattern-matching-performance-overhead-8g7</link>
      <guid>https://dev.to/akashkava/c-pattern-matching-performance-overhead-8g7</guid>
      <description>&lt;p&gt;Pattern matching is great, makes life easier, but it comes with a cost. Most of the time the cost is negligible. But it is better to know when not to use it.&lt;/p&gt;

&lt;p&gt;Lets assume following simple case,&lt;/p&gt;

&lt;h1&gt;
  
  
  Pattern Matching
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Radius&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Height&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;We want to calculate area, by using pattern matching, so here is the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;Pattern&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Circle&lt;/span&gt; &lt;span class="n"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PI&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;circle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Radius&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Rectangle&lt;/span&gt; &lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Width&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rectangle&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;NotSupportedException&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;Now lets analyze JIT ASM generated for above code,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C.Pattern(Shape)
    L0000: push rsi
    L0001: sub rsp, 0x20
    L0005: vzeroupper
    L0008: mov rsi, rdx
    L000b: mov rdx, rsi
    L000e: mov rcx, 0x7ffb9945d250
    L0018: call 0x00007ffbef626620
    L001d: test rax, rax
    L0020: jne short L0049
    L0022: mov rdx, rsi
    L0025: mov rcx, 0x7ffb9945d3c0
    L002f: call 0x00007ffbef626620
    L0034: test rax, rax
    L0037: je short L0064
    L0039: vmovsd xmm0, [rax+8]
    L003e: vmulsd xmm0, xmm0, [rax+0x10]
    L0043: add rsp, 0x20
    L0047: pop rsi
    L0048: ret
    L0049: vmovsd xmm0, [rax+8]
    L004e: vmovaps xmm1, xmm0
    L0052: vmulsd xmm1, xmm1, [C.Pattern(Shape)]
    L005a: vmulsd xmm0, xmm0, xmm1
    L005e: add rsp, 0x20
    L0062: pop rsi
    L0063: ret
    L0064: mov rcx, 0x7ffb8fbddfd8
    L006e: call 0x00007ffbef6278f0
    L0073: mov rsi, rax
    L0076: mov rcx, rsi
    L0079: call System.NotSupportedException..ctor()
    L007e: mov rcx, rsi
    L0081: call 0x00007ffbef5eb3a0
    L0086: int3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice lines,  &lt;code&gt;L0018: call 0x00007ffbef626620&lt;/code&gt; and &lt;code&gt;L002f: call 0x00007ffbef626620&lt;/code&gt;, both calls are to check whether the object is of instance requested. I was also surprised to see this as pattern matching can also match an interface/base class. So it is not simple comparison. Every pattern matching case requires separate &lt;code&gt;CALL&lt;/code&gt; instruction, which is a considerable overhead on CPU.&lt;/p&gt;

&lt;p&gt;So, in simple words, the last case will always require all &lt;code&gt;instance of&lt;/code&gt; &lt;code&gt;CALL&lt;/code&gt; before hitting the case. You can certainly move the most used cases on the top to make life easier.&lt;/p&gt;

&lt;h1&gt;
  
  
  Plain old OOPS
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Radius&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;Area&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="n"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;PI&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;Radius&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;Radius&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="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Rectangle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="n"&gt;Height&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;Area&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="n"&gt;Width&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;Height&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;Now lets call &lt;code&gt;Area&lt;/code&gt; method and see what JIT ASM generates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;double&lt;/span&gt; &lt;span class="nf"&gt;Area&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Shape&lt;/span&gt; &lt;span class="n"&gt;shape&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="n"&gt;shape&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Area&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C.Area(Shape)
    L0000: mov rcx, rdx
    L0003: mov rax, [rdx]
    L0006: mov rax, [rax+0x40]
    L000a: mov rax, [rax+0x20]
    L000e: jmp rax
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is simplest single call, it loads and address and jumps to it and returns from the method. The speed is achieved by avoiding instance of checks.&lt;/p&gt;

&lt;h1&gt;
  
  
  Complete sample
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIGYACMhgYQYG8aHunHiUGAWQAUASg5ceAX0ndZvBgBMIAV2AAbGAwCCsbMIDKAC2wAHLbhPnxnaj3tMA7A0tmYAOl0x9ogNzyZOx55eiVVDS0ABWwMDBgoADtDKwsUm3l7XAB3AEsMMCNhV2sJIIcHMDwtFhyoME0GMFr6mBAM8odiZ0EYo3dIgEkGACpG5s13ACVsRRyVXBGxuonp2fn/Mo7uStwtSZgwDGwEgHMG2EPjs9b2re4uhguj04mAdRzFDCNFp6uJgAkYDkTkYMBstoEtl8oBAsgwEjA4QA5CAYAwqUymaBxRQAUQQYBgpgwOQgST8AXkIUY2GAuAwUGwhyYpAYxjcpS2oVp9MZzOUagaXh84OkVM2oWYNWWrTZKU5HVCAoiDFWc1wG1uCggADd4lAPlplUK9GItbY7jwHj0vv0hqM1fNFo6NVrIWLNtSWaqDs9riA5RyLYrGMatO9PkZReUleEGoDgaDow4taFdfrDWFBVphWIFZaHhGvosEyCwW7KdQpEA="&gt;https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBDAzgWwB8ABAJgEYBYAKGIGYACMhgYQYG8aHunHiUGAWQAUASg5ceAX0ndZvBgBMIAV2AAbGAwCCsbMIDKAC2wAHLbhPnxnaj3tMA7A0tmYAOl0x9ogNzyZOx55eiVVDS0ABWwMDBgoADtDKwsUm3l7XAB3AEsMMCNhV2sJIIcHMDwtFhyoME0GMFr6mBAM8odiZ0EYo3dIgEkGACpG5s13ACVsRRyVXBGxuonp2fn/Mo7uStwtSZgwDGwEgHMG2EPjs9b2re4uhguj04mAdRzFDCNFp6uJgAkYDkTkYMBstoEtl8oBAsgwEjA4QA5CAYAwqUymaBxRQAUQQYBgpgwOQgST8AXkIUY2GAuAwUGwhyYpAYxjcpS2oVp9MZzOUagaXh84OkVM2oWYNWWrTZKU5HVCAoiDFWc1wG1uCggADd4lAPlplUK9GItbY7jwHj0vv0hqM1fNFo6NVrIWLNtSWaqDs9riA5RyLYrGMatO9PkZReUleEGoDgaDow4taFdfrDWFBVphWIFZaHhGvosEyCwW7KdQpEA=&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Can performance of Pattern matching improved?
&lt;/h1&gt;

&lt;p&gt;Not really, high level languages usually store too much type information in order to provide improved pattern matching. But underlying cost of every single comparison is costly.&lt;/p&gt;

&lt;p&gt;In Processor, any type of processor, be it ARM, X64 or any, single numeric comparison is much caster than hierarchical or sequential types. Basically type matching is a multi step comparison.&lt;/p&gt;

&lt;p&gt;This is also the reason V8 team decided to store Enum flag to detect type in JavaScript inbuilt type instead of pattern matching.&lt;/p&gt;

&lt;h1&gt;
  
  
  Branchless
&lt;/h1&gt;

&lt;p&gt;OOPS will also make most of your code branchless, which makes CPU eagerly load next set of instruction to execute instead of missing branch cache and slowing the execution.&lt;/p&gt;

&lt;p&gt;More about branchless coding&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/bVJ-mWWL7cE"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

</description>
      <category>csharp</category>
      <category>performance</category>
    </item>
    <item>
      <title>Live &amp; Hot Reload/Code Push Xamarin.Forms Apps with Web Atoms</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Thu, 10 Sep 2020 09:52:00 +0000</pubDate>
      <link>https://dev.to/web-atoms/hot-reload-code-push-xamarin-forms-apps-with-web-atoms-15ma</link>
      <guid>https://dev.to/web-atoms/hot-reload-code-push-xamarin-forms-apps-with-web-atoms-15ma</guid>
      <description>&lt;h1&gt;
  
  
  History &amp;amp; Motivation
&lt;/h1&gt;

&lt;p&gt;We have been using Xamarin.Forms for a couple of years, but business augmentation demanded more frequent app updates. We were assessing React native as an alternative, but the learning curve was very steep and our developers are considerably more familiar with MVVM approach up against the MVC method. Thus three years back, we ran a pilot by writing Xamarin Forms in JavaScript, it was relatively easy to fabricate and prototype swiftly. We now have three apps that are partly c# and partly JavaScript, as all-new screens are shipped through JSX&lt;/p&gt;

&lt;h2&gt;
  
  
  Native Limitations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Native code is fast, but for most business application needs, this performance vs the time need to build/deploy and maintain release cycle is extremely costly.&lt;/li&gt;
&lt;li&gt;No side by side versioning, once the bug is found, fix is not available instantly.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Xamarin.Forms Limitations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Xamarin has an advantage of writing app in one language c# along with Powerful set of NuGet Libraries.
2 &lt;em&gt;BUT&lt;/em&gt;, yes the big But is, the c# code is translated into native, so it requires same time to build and deploy the app.&lt;/li&gt;
&lt;li&gt;Unfortunately, Android builds are still relatively slow.&lt;/li&gt;
&lt;li&gt;Developing and debugging is painfully slow.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Deployment Limitations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;iOS App approvals take longer, bugs do go out on production as we never have million dollar app budgets to fix all the bugs before rolling out.&lt;/li&gt;
&lt;li&gt;There is no quick way to fix bug, a new upgrade reaches all your customers after couple of days. Most of the time, users don't have auto update enabled, they don't download new version, they are not connected to high speed internet and above all, all the major heavy updates in queue will delay your update.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  React Native Limitations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;React native was great alternative to bypass all slowness, but for C# developers, it has many roadblocks.&lt;/li&gt;
&lt;li&gt;C# developers are more familiar with MVVM pattern, lack of MVVM pattern on React increases learning time.&lt;/li&gt;
&lt;li&gt;Rewriting C# components and services on React will defy the purpose of making life easier.&lt;/li&gt;
&lt;li&gt;Native integration in C++/Swift/Java is again problem for developers who have years of experience in C#.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Hot/Live reloading with Web Atoms
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Language/Platform
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;You can use JavaScript + C#, JavaScript for your business pages/UI and C# only for high speed computation and other native integrations.&lt;/li&gt;
&lt;li&gt;NuGet has probably million packages that you can easily use in Xamarin Forms. And all that can be used in JavaScript.&lt;/li&gt;
&lt;li&gt;Web Atoms is designed by keeping MVVM in mind, so writing JSX with MVVM is extremely easy. For C# developers it only feels different in syntax, rest of things remain as it is. &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Reuse
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Since you can reuse all of your existing Xamarin.Forms code, time to shift to Web Atoms is really negligible.&lt;/li&gt;
&lt;li&gt;You don't have to rewrite everything.&lt;/li&gt;
&lt;li&gt;You can simply add nearly 20 to 30 lines of code to start using JSX instead of Xaml in Xamarin.Forms project.&lt;/li&gt;
&lt;li&gt;You can reuse all your existing C# components in JavaScript.&lt;/li&gt;
&lt;li&gt;You can create reusable components in JavaScript and use them in your existing components of C#.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Side by side versioning
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Since web atoms javascript packages are deployed simply as nuget packages, you can easily create some strategy to upgrade/downgrade versions on your web server. &lt;/li&gt;
&lt;li&gt;You can easily distribute private beta and offer different version to different customers to debug or quickly patch few bugs.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Advantages of Web Atoms over React Native and Native Script
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Both, React native and Native script offers JavaScript , but native integration and high performing code needs to be written in Swift/Java/C++. With Web Atoms, you can easily write platform independent in C# and use it in Web Atoms.&lt;/li&gt;
&lt;li&gt;You can continue to use your existing code/libraries written in C# easily without any hassle.&lt;/li&gt;
&lt;li&gt;Debugging Xamarin apps is easy compared to native platforms.&lt;/li&gt;
&lt;li&gt;Debugging JavaScript in Android is done via Chrome debugger and in iOS with Safari development tools.&lt;/li&gt;
&lt;li&gt;JSX syntax in Web Atoms is exactly same as Xaml, you can perform all kinds of Bindings in JSX in exactly same fashion as in Xaml.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  How does it work?
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Your existing Xamarin Forms app is loaded natively in exactly same manner.&lt;/li&gt;
&lt;li&gt;As soon as the app is launched, a new JavaScript bridge (V8 in Android and JavaScriptCore in iOS) is created.&lt;/li&gt;
&lt;li&gt;Web Atoms module loader loads your scripts and provides integration between c# and your code.&lt;/li&gt;
&lt;li&gt;Once the bridge is loaded, you can refresh the bridge inside the app via some code, or some trigger, without reloading entire app, the bridge loads new version of application JavaScript. This happens usually within 1-2 seconds.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Once built, only JavaScript is reloaded
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;You don't need to publish your app on app store unless you make any changes in the C# code.&lt;/li&gt;
&lt;li&gt;You don't even need to close/restart the app to see new changes.&lt;/li&gt;
&lt;li&gt;You can publish javascripts on the Wifi and you can also debug your app over wifi.&lt;/li&gt;
&lt;li&gt;JavaScript reloading is little slow compared to native code, but for prototyping, for business applications, the time delay in JavaScript code is negligible.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>typescript</category>
      <category>javascript</category>
      <category>xamarin</category>
      <category>xamarinforms</category>
    </item>
    <item>
      <title>When and What to Unit Test</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Mon, 13 Jul 2020 05:55:32 +0000</pubDate>
      <link>https://dev.to/akashkava/when-and-what-to-unit-test-4g9d</link>
      <guid>https://dev.to/akashkava/when-and-what-to-unit-test-4g9d</guid>
      <description>&lt;p&gt;I have seen many posts about justifying why and why not to unit test, but most posts only talk about burden of writing unit tests, testing framework shortfalls and overhead of mocking in testing.&lt;/p&gt;

&lt;p&gt;After writing and deciding not to write unit tests, I have finally compiled one and only one single reason why and what should be unit tested. How is not the question. If you think any testing framework is inadequate, you can simply create one.&lt;/p&gt;

&lt;p&gt;So what should be unit tested? &lt;/p&gt;

&lt;h1&gt;
  
  
  Edge Cases
&lt;/h1&gt;

&lt;p&gt;Answer is, "Edge Cases", yes, only the edge cases should at least be unit tested.&lt;/p&gt;

&lt;h2&gt;
  
  
  Early Age
&lt;/h2&gt;

&lt;p&gt;Lets take a simple function as an example, we will use C# to demonstrate the reason, however same can be done in any language.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;
   &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&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="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&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;Most of you will think that this function will never fail, well hold on, see what will happen when you do &lt;code&gt;Add(int.MaxValue, int.MaxValue)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This is called an edge case.&lt;/p&gt;

&lt;p&gt;If you run this code, &lt;a href="https://dotnetfiddle.net/H3wmI6"&gt;https://dotnetfiddle.net/H3wmI6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see the answer given is &lt;code&gt;-2&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now lets assume that we wrote this simple method and which is used by 10 methods and all 10 methods are used by total of 100 another methods. So you now have 100s of dependent callers to this method.&lt;/p&gt;

&lt;h2&gt;
  
  
  Middle Age
&lt;/h2&gt;

&lt;p&gt;At one point, somebody decides that function returning &lt;code&gt;-2&lt;/code&gt; is really not helpful, so they create a method &lt;code&gt;VerifyAdd&lt;/code&gt; with following implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;   &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;VerifyAdd&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MaxValue&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MaxValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
           &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ArgumentException&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="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&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;And at some part of code we continue to use old &lt;code&gt;Add&lt;/code&gt; and some part of code we write &lt;code&gt;VerifyAdd&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mature Age
&lt;/h2&gt;

&lt;p&gt;When project is couple of months old and has entered into maturity, we decide that we should change &lt;code&gt;Add&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;   &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;Add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MaxValue&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MaxValue&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="m"&gt;1&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="n"&gt;a&lt;/span&gt; &lt;span class="p"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&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;Now this is an issue, because half of your logic will expect &lt;code&gt;ArgumentException&lt;/code&gt; and half of them will expect -1 as return answer. Leading to inconsistency in the logic.&lt;/p&gt;

&lt;p&gt;Though this example looks simple, but when code graph is complex, when classes are subclassed and implementations are overriden, inconsistency in code keeps on rising. Now some will come and argue that this is the reason functional programming is best, nope, it is not, same can happen in any language. No language and no framework can ever provide immunity against logical inconsistencies.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to identify Edge cases?
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;All exceptions and errors are edge cases. So you must unit test every error, we have to make sure that the callers get correct error messages.&lt;/li&gt;
&lt;li&gt;Edge cases are also evolved, as we have seen, introducing one change in logic, change introduce new edge case.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  So only edge cases for Unit tests?
&lt;/h1&gt;

&lt;p&gt;Nope, Edge cases are must, arithmetic and time delay related logic must also be unit tested. &lt;/p&gt;

&lt;p&gt;Apart from error edge cases, we must consider logical edge cases &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Integer/float overflow&lt;/li&gt;
&lt;li&gt;Delay, timeout, any method should not indefinitely hang&lt;/li&gt;
&lt;li&gt;Never eat errors, log them and throw again, Application level unit testing must catch all errors.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  How to learn to write unit tests?
&lt;/h1&gt;

&lt;p&gt;For early developers, it is difficult to understand how and when to write unit tests. Even I was against it and I never wrote in my early years thinking it was total waste of time to unit test &lt;code&gt;5 == Add(2,3)&lt;/code&gt;, and it is.&lt;/p&gt;

&lt;p&gt;To begin with, we should look at how large open source repositories are built and maintained. And look at the simple implementations and simple unit tests backing the logic.&lt;/p&gt;

&lt;p&gt;Even if you don't contribute to any open source project, downloading them and browsing them for hours will give you many meaningful insights.&lt;/p&gt;

</description>
      <category>testing</category>
      <category>unittesting</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Introducing Xamarin.Forms Fiddle </title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Wed, 08 Jul 2020 15:29:06 +0000</pubDate>
      <link>https://dev.to/web-atoms/introducing-xamarin-forms-fiddle-2h1i</link>
      <guid>https://dev.to/web-atoms/introducing-xamarin-forms-fiddle-2h1i</guid>
      <description>&lt;h1&gt;
  
  
  Xamarin.Forms app in JavaScript
&lt;/h1&gt;

&lt;p&gt;With Web Atoms, you can create Xamarin.Forms apps in JavaScript. You can write JSX instead of Xaml and that gives you powerful multibinding and allows you to push code on production.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Side by side versioning&lt;/li&gt;
&lt;li&gt;Divide large app in multiple javascript npm packages&lt;/li&gt;
&lt;li&gt;No need to create multiple apps and integrate all of them&lt;/li&gt;
&lt;li&gt;Debug JavaScript in Chrome using V8 Inspector protocol for Android&lt;/li&gt;
&lt;li&gt;Debug JavaScript in Safari debugger for iOS&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Download the App
&lt;/h1&gt;

&lt;p&gt;Trying and playing with Xamarin.Forms in JavaScript is one step process, download the app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://apps.apple.com/us/app/id1516606498" rel="noopener noreferrer"&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%2Frxq4nf3l4zxln2hzolrp.png" alt="App Store"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://play.google.com/store/apps/details?id=in.webatoms.debugger" rel="noopener noreferrer"&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%2Fu8xoqg3a7cjafke01jb2.png" alt="Play Store"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Open Demo
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Shapes
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.webatoms.in/play/demo/shapes/1" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/shapes/1&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.webatoms.in/play/demo/rating/4" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/rating/4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore new feature "Shapes" of Xamarin.Forms 4.7.&lt;/p&gt;

&lt;h2&gt;
  
  
  Master Detail
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.webatoms.in/play/demo/master-detail" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/master-detail&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Application with drawer and multiple pages, using navigation service to open pages, retrieve result and load unpacked pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  List View
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.webatoms.in/play/demo/list" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/list&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore list view with Cell bindings. Using two way binding to update the selection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Form
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.webatoms.in/play/demo/form/3" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/form/3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore validation sample with simple form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tabbed Page
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://www.webatoms.in/play/demo/tabbed-page/3" rel="noopener noreferrer"&gt;https://www.webatoms.in/play/demo/tabbed-page/3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Explore tabbed pages.&lt;/p&gt;

&lt;h1&gt;
  
  
  Scan QR Code
&lt;/h1&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%2F17fbafr67i4vsuhpec1m.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%2F17fbafr67i4vsuhpec1m.png" alt="Scan and Play"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Console Logging
&lt;/h1&gt;

&lt;p&gt;You can see console of your device and you can log errors/warnings in the console in your code.&lt;/p&gt;

</description>
      <category>xamarinforms</category>
      <category>typescript</category>
      <category>xamarin</category>
      <category>showdev</category>
    </item>
    <item>
      <title>ViewModel Decorators in Web Atoms for Xamarin.Forms</title>
      <dc:creator>Akash Kava</dc:creator>
      <pubDate>Sun, 14 Jun 2020 09:03:07 +0000</pubDate>
      <link>https://dev.to/web-atoms/viewmodel-decorators-in-web-atoms-for-xamarin-forms-2icl</link>
      <guid>https://dev.to/web-atoms/viewmodel-decorators-in-web-atoms-for-xamarin-forms-2icl</guid>
      <description>&lt;h1&gt;
  
  
  Rich View Model
&lt;/h1&gt;

&lt;p&gt;Web Atoms provides feature rich View Model to write common logic with simple configuration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Watch Decorator
&lt;/h2&gt;

&lt;p&gt;Watching property is super easy with Web Atoms. You can simply create a readonly accessor and mark it is &lt;code&gt;@Watch&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;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;EditorViewModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CustomerModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Watch&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firstName&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;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;lastName&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;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&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;Usage&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;this&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomForm&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Entry&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;twoWays&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&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="sr"&gt;/WA.AtomField&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Entry&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;twoWays&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&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="sr"&gt;/WA.AtomField&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Label&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;oneWay&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fullName&lt;/span&gt;&lt;span class="p"&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="sr"&gt;/WA.AtomField&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="sr"&gt;/WA.AtomForm&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Validate Decorator
&lt;/h1&gt;

&lt;p&gt;Validate is special type of watch, which gets activate only if validation was requested.&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;SignupViewModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CustomerModel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;emailAddress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Validate&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;errorFirstName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&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;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;First name is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Validate&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;errorEmailAddress&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;email&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;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emailAddress&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;email&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Email is required&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;emailRegEx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;email&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid email&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;actionSignup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// only when this was invoked&lt;/span&gt;
        &lt;span class="c1"&gt;// in UI, validation occurs&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;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;Signup&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomXFContentPage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;viewModel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SignupViewModel&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="p"&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;viewModel&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;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;SignupViewModel&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;render&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomForm&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Entry&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;twoWays&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firstName&lt;/span&gt;&lt;span class="p"&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="sr"&gt;/WA.AtomField&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Entry&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;twoWays&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emailAddress&lt;/span&gt;&lt;span class="p"&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="sr"&gt;/WA.AtomField&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;WA&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AtomField&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;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;
                    &lt;span class="nx"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;actionSignup&lt;/span&gt;&lt;span class="p"&gt;())}&lt;/span&gt;
                    &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Signup&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="sr"&gt;/WA.AtomField&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="sr"&gt;/WA.AtomForm&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&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;h1&gt;
  
  
  Load Decorator
&lt;/h1&gt;

&lt;p&gt;Load decorator makes loading of async data very easy. Let's assume that we want to load countries and then selected state. It reports exceptions and cancels previous&lt;br&gt;
operation.&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;SignupViewModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="cm"&gt;/** This gets called on initialization */&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;init&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;loadCountries&lt;/span&gt;&lt;span class="p"&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;countries&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
            &lt;span class="k"&gt;await&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;restService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getCountries&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;selectedCountry&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;countries&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;find&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;x&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;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;IN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cm"&gt;/** This gets called when `this.selectedCountry` changes */&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="cm"&gt;/* watch */&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;loadStates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CancelToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;country&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;selectedCountry&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// pass cancel token&lt;/span&gt;
        &lt;span class="c1"&gt;// to automatically cancel previous&lt;/span&gt;
        &lt;span class="c1"&gt;// incomplete request&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;states&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
            &lt;span class="k"&gt;await&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;restService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getStates&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;country&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ct&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;h1&gt;
  
  
  Debouncing
&lt;/h1&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;SignupViewModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Load&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="cm"&gt;/** watch for changes */&lt;/span&gt;
        &lt;span class="na"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="cm"&gt;/** wait as user might still be typing */&lt;/span&gt;
        &lt;span class="na"&gt;watchDelayInMS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;loadCities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;CancelToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;search&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;search&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="cm"&gt;/** cancellation of previous request is tracked here */&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;cities&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&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;restService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;searchCities&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ct&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;h1&gt;
  
  
  Action
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;@Action&lt;/code&gt; decorator can be applied on a method which will automatically display an alert if there was any error. And it will invoke validation before executing the method. Display an success alert after completion if configured. You can also configure &lt;code&gt;confirm&lt;/code&gt; to request confirmation (e.g. for delete operations).&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;SignupViewModel&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;AtomViewModel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="cm"&gt;/** This decorator will handle validation, display error
     * and will display an alert for success
     */&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Signup successful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;confirm&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;signup&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;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;XF&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Button&lt;/span&gt;
        &lt;span class="nx"&gt;command&lt;/span&gt;&lt;span class="o"&gt;=&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="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;viewModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;signup&lt;/span&gt;&lt;span class="p"&gt;())}&lt;/span&gt;
        &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Signup&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>xamarin</category>
      <category>xamarinforms</category>
      <category>mvvm</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
