<?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: Verge729</title>
    <description>The latest articles on DEV Community by Verge729 (@verge_729).</description>
    <link>https://dev.to/verge_729</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%2F705480%2F64785a45-e137-4765-b909-aa4a0b55a57a.jpeg</url>
      <title>DEV Community: Verge729</title>
      <link>https://dev.to/verge_729</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/verge_729"/>
    <language>en</language>
    <item>
      <title>Using Fission with Elm - Part 3: Adding authentication and using the Fission Drive</title>
      <dc:creator>Verge729</dc:creator>
      <pubDate>Tue, 09 Nov 2021 01:22:08 +0000</pubDate>
      <link>https://dev.to/xeticode/using-fission-with-elm-part-3-adding-authentication-and-using-the-fission-drive-3fig</link>
      <guid>https://dev.to/xeticode/using-fission-with-elm-part-3-adding-authentication-and-using-the-fission-drive-3fig</guid>
      <description>&lt;h5&gt;
  
  
  &lt;strong&gt;[UPDATE]&lt;/strong&gt; The Fission team released fission-suite/webnative-elm version 7.0.0 since the original publish date of this article. This update includes a sign out function. The following sections of the article have been changed to reflect this update: &lt;code&gt;Walkthrough/Authentication/'Prep work'&lt;/code&gt;and &lt;code&gt;Walkthrough/Authentication/'Signing out'&lt;/code&gt;. This article no longer makes any changes to the &lt;code&gt;js/index.js&lt;/code&gt; file as defined in &lt;code&gt;Fission with Elm - Part 2&lt;/code&gt;.
&lt;/h5&gt;

&lt;h5&gt;
  
  
  Make sure the npm and elm-module packages for &lt;code&gt;webnative-elm&lt;/code&gt; are at 6.1.0 and 7.0.0, respectively. To update them, run the following from the root of the project:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev webnative-elm
npx elm-json install fission-suite/webnative-elm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Prelude&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is a three-part series. In part one, I showed you how to use Vite to manage an Elm application. In part two, I showed you how to integrate the basics of Fission via the Webnative SDK into the project. In part three (this article), I will show how to add authentication and storage via the &lt;code&gt;Webnative SDK&lt;/code&gt; to the application. This article is written assuming the developer already has a Fission account and has completed parts 1 and 2.&lt;/p&gt;

&lt;p&gt;It should be noted that the last two articles were fairly short. Both have set the stage for this article, the pinnacle of the series. There will be much to add to our growing application, some of these additions are due to Elm being a strongly typed language.&lt;/p&gt;

&lt;p&gt;It should also be noted that if you are using a browser that using something similar to Brave Shields in the Brave browser, you will need to disable the feature so Fission can communicate with the application.&lt;/p&gt;

&lt;p&gt;This article will also require the use of a Fission account. If you do not yet have one, take a moment to create one now. Check &lt;strong&gt;Appendix A&lt;/strong&gt; at the end of this article for steps on how to do so.&lt;/p&gt;

&lt;p&gt;The Github repository associated with this article can be found here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/xeticode/fission-with-elm-demos/tree/Part-3" rel="noopener noreferrer"&gt;https://github.com/xeticode/fission-with-elm-demos/tree/Part-3&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Welcome to the final article. Here you will be tested beyond anything you have ever experienced… Nah, this is not some epic set of trials. That being said, it is my hope that by the end of this article, you have been exposed enough to Fission to continue on in your own Fission-based applications. &lt;br&gt;
It is time to add some usefulness to this application. Right now, it is like a wallpaper: good to look at and not much else. The first feature we will add is user authentication. After authentication, we will add code that will interact with the Fission Drive to write a file to storage. There are no introductions to be made this go-around, so we will review important concepts for what I am about to show you.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Things to review&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;elm ports&lt;/em&gt;&lt;/strong&gt; are the medium by which an Elm application communicates with JavaScript. For more information, see &lt;a href="https://guide.elm-lang.org/interop/ports.html" rel="noopener noreferrer"&gt;Elm Ports&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;IPFS&lt;/em&gt;&lt;/strong&gt; "is a distributed system for storing and accessing files, websites, applications, and data". For more information, see &lt;a href="https://docs.ipfs.io/concepts/what-is-ipfs/" rel="noopener noreferrer"&gt;IPFS&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Wnfs&lt;/em&gt;&lt;/strong&gt; stands for &lt;code&gt;Webnative File System&lt;/code&gt; and "is a file system built on top of the (IPFS)". For more information, see &lt;a href="https://guide.fission.codes/developers/webnative/file-system-wnfs" rel="noopener noreferrer"&gt;Webnative File System&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Fission Drive&lt;/em&gt;&lt;/strong&gt; is a military-grade encrypted file system located within a distributed network. For more information, see &lt;a href="https://guide.fission.codes/drive/preview" rel="noopener noreferrer"&gt;Fission Drive&lt;/a&gt; .&lt;br&gt;
Let us begin!&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Walkthrough&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Download an updated &lt;code&gt;Main.elm&lt;/code&gt; by running this command in the terminal from the &lt;code&gt;src&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o Main.elm https://raw.githubusercontent.com/xeticode/fission-with-elm-demos/interim/part-3/Main.elm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This new &lt;code&gt;Main.elm&lt;/code&gt; file lays down some new groundwork for our application. It is also divided into sections, the dividers being noticeable comments. Instead of indicating a line in the file to add or find code, I will indicate a region of the code to look. The differences between the new file versus the old one includes additions to our &lt;code&gt;type alias Model&lt;/code&gt;, &lt;code&gt;type Msg&lt;/code&gt;, and &lt;code&gt;update&lt;/code&gt; function (see section: &lt;code&gt;MODEL/UPDATE&lt;/code&gt;); a section for helper functions (see section: &lt;code&gt;HELPER FUNCTIONS&lt;/code&gt;); and a new UI (see section: &lt;code&gt;VIEW&lt;/code&gt;). Let’s quickly go over the new &lt;code&gt;Msg&lt;/code&gt; variants and the &lt;code&gt;Model&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;&lt;code&gt;Msg&lt;/code&gt; variants&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Here are the new variants and their purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;SignIn&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; will be associated with the login button and will initiate the login process with Fission.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;SignOut&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; will be associated with the logout button and will initiate the logout process with Fission.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;UpdateNote&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; is the variant that will update the &lt;code&gt;note&lt;/code&gt; field in the &lt;code&gt;Model&lt;/code&gt;. This is the value that will be written to the Wnfs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;SaveNote&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; is associated with the &lt;code&gt;Save Note&lt;/code&gt; button and will initiate the process of writing and publishing our &lt;code&gt;note&lt;/code&gt; to the Wnfs.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;&lt;code&gt;Model&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Here is a breakdown of the new fields in &lt;code&gt;Model&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;username&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; will store the username of the logged-in Fission user of the current session (if you are not familiar with the &lt;code&gt;Maybe&lt;/code&gt; type, or simply need a refresher, see &lt;a href="https://guide.elm-lang.org/error_handling/maybe.html" rel="noopener noreferrer"&gt;Maybe&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;logs&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; is a list of strings and will store log entries associated with the different stages of interaction with Fission. These will be displayed on the left side of the screen. Consider these as a log that make it easier to see the processes when they occur.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;note&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; this will store the content that will be sent to the Wnfs. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Before we dive in&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;npm run dev&lt;/code&gt; from the root of the project to have the application up and running on the dev server. Once you do this, you should see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqhq3o7h89e15p0szg7b.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhqhq3o7h89e15p0szg7b.PNG" alt="fission-with-elm login" width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, you can click on the login button, but it will not take you anywhere. Its associated message, &lt;code&gt;SignIn&lt;/code&gt;, is currently a dead end. Not to worry, the first thing we will do is implement authentication.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Authentication&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Prep work&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;One of the reasons my meals are so simple and quick is my hungry stomach will usually override my willingness to spend time on quality meal prep. Lucky for us, this is not a food situation.  Before we can sign in, we must add a few things, a metaphorical meal prep, if you will, before we can dig into authentication.&lt;/p&gt;

&lt;p&gt;The first thing we must do is expand the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; branch in our update function. To begin, replace the current &lt;code&gt;GotWebnativeResponse&lt;/code&gt; branch (section: &lt;code&gt;MODEL/UPDATE&lt;/code&gt;, function: &lt;code&gt;update&lt;/code&gt;) with the following code (be aware, the alignment may change when copying and pasting into your developing environment. You will get the red squiggles if the case statement branches are mis-aligned):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="kt"&gt;GotWebnativeResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;decodeResponse&lt;/span&gt; &lt;span class="n"&gt;tagFromString&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt;
        &lt;span class="kt"&gt;Webnative&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Initialisation&lt;/span&gt; &lt;span class="n"&gt;state&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;case&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; 
                &lt;span class="kt"&gt;NotAuthorised&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
                        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auth: NotAuthorised"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="kt"&gt;AuthSucceeded&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;
                        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auth: AuthSucceeded"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="kt"&gt;AuthCancelled&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
                        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auth: AuthCancelled"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="kt"&gt;Continuation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
                    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt;
                        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Auth: Continuation"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
                    &lt;span class="p"&gt;}&lt;/span&gt;
                    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
                    &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kt"&gt;Wnfs&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;


        &lt;span class="kt"&gt;Webnative&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;NoArtifact&lt;/span&gt; &lt;span class="kt"&gt;SignedOut&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Signed out!"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
                &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kt"&gt;Webnative&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;NoArtifact&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kt"&gt;WebnativeError&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;              
            &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="kt"&gt;WnfsError&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
                &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Wnfs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is a lot of new code, and some of it is accompanied by our friendly neighborhood red squiggles. This is due to missing proper imports and a definition for &lt;code&gt;tagFromString&lt;/code&gt;, which is a helper function. Let's resolve the problem starting with the imports.&lt;/p&gt;

&lt;p&gt;Go to the &lt;code&gt;import&lt;/code&gt; block at the top of &lt;code&gt;Main.elm&lt;/code&gt;. Near the bottom of the import block at the top of the file, we have our &lt;code&gt;Webnative&lt;/code&gt; import and it is currently exposing &lt;code&gt;Artifact(..)&lt;/code&gt; and all its variants (represented by the &lt;code&gt;(..)&lt;/code&gt;). Replace this import with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt; &lt;span class="k"&gt;exposing&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Artifact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;NoArtifact&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;DecodedResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;State&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Adding these to the exposing list will allow us access to the &lt;code&gt;DecodedResponse&lt;/code&gt; and &lt;code&gt;State&lt;/code&gt; types from the &lt;code&gt;Webnative-elm&lt;/code&gt; module  (see &lt;a href="https://package.elm-lang.org/packages/fission-suite/webnative-elm/6.0.0/Webnative#DecodedResponse" rel="noopener noreferrer"&gt;DecodedResponse&lt;/a&gt; and &lt;a href="https://package.elm-lang.org/packages/fission-suite/webnative-elm/6.0.0/Webnative#State" rel="noopener noreferrer"&gt;State&lt;/a&gt;). &lt;/p&gt;

&lt;p&gt;Now we will define &lt;code&gt;tagFromString&lt;/code&gt;. In the &lt;code&gt;HELPER FUNCTION&lt;/code&gt; section, add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;tagFromString&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Result&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt;
&lt;span class="n"&gt;tagFromString&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt;
         &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="kt"&gt;Err&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;|&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid tag: "&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Webnative-elm&lt;/code&gt; utilizes tags to differentiate between different requests and connect the appropriate response. For example, if I sent a &lt;code&gt;webnativeRequest&lt;/code&gt; tagged with “StudioGhibli”, the associated &lt;code&gt;webnativeResponse&lt;/code&gt; will have the same tag. We can then create a branch within our &lt;code&gt;GotWebnativeResponse&lt;/code&gt; branch’s case statement and dictate how to handle the response. &lt;/p&gt;

&lt;p&gt;Now, both &lt;code&gt;webnativeRequest&lt;/code&gt; and &lt;code&gt;webnativeResponse&lt;/code&gt; require the tag to be a string not an Elm type. That is why we need such helper functions as &lt;code&gt;tagFromString&lt;/code&gt; and its companion &lt;code&gt;tagToString&lt;/code&gt;. Extra code on our part, yes. This is a byproduct of Elm, not the &lt;code&gt;webnative-elm&lt;/code&gt; wrapper. In fact, this is great design by the people behind the wrapper because it couples the &lt;code&gt;Webnative SDK&lt;/code&gt; with the strengths of Elm.&lt;/p&gt;

&lt;p&gt;Speaking of an Elm type for our tags, we now have another red squiggle to take care of, this time on &lt;code&gt;Tag&lt;/code&gt;. Add the following code between the &lt;code&gt;type Msg&lt;/code&gt; and &lt;code&gt;update&lt;/code&gt; function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt;
    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;ChangeMeLater&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is where we define our different &lt;code&gt;webnativeRequest&lt;/code&gt; tags. To reiterate, we will return to this later when it is time to utilize our &lt;code&gt;Tag&lt;/code&gt; type. We need to define &lt;code&gt;Tag&lt;/code&gt; now so we can proceed with the rest of what the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; has to offer.&lt;br&gt;
We are now ready to officially sign in!&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Signing in&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is where having a Fission account is crucial. If you have yet to do so, stop and take a moment to create a Fission account (see &lt;strong&gt;Appendix A&lt;/strong&gt; at the end of this article for details).&lt;/p&gt;

&lt;p&gt;The application is growing up so fast. To implement sign in, go to the &lt;code&gt;SignIn&lt;/code&gt; branch  of the &lt;code&gt;update&lt;/code&gt; function (section: &lt;code&gt;MODEL/UPDATE&lt;/code&gt;) and replace &lt;code&gt;Cmd.none&lt;/code&gt; with the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;permissions&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;redirectToLobby&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;CurrentUrl&lt;/span&gt;
    &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;webnativeRequest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will take our &lt;code&gt;permissions&lt;/code&gt; (defined in part 2 of this series) and pass it to the Webnative function &lt;code&gt;redirectToLobby&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Time to see it in action! Refresh the app in the browser and click "Login"! This will take us to a Fission authorization lobby. You will see something like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejsrqgyd3njpeubbwfz3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fejsrqgyd3njpeubbwfz3.PNG" alt="Fission Auth Lobby" width="800" height="441"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This lobby utilizes the &lt;code&gt;appPermissions&lt;/code&gt; and &lt;code&gt;fsPermissions&lt;/code&gt; we defined at the beginning of the &lt;code&gt;Main.elm&lt;/code&gt; file. If there are no defined &lt;code&gt;fsPermissions&lt;/code&gt; (like with this application), the only permission request will be for the file path generated for the application. Once you grant permission, authentication will finish. &lt;/p&gt;

&lt;p&gt;Rather than using traditional username and password authentication (such as OAuth), Fission uses cryptographic keys and stores them in a browser you authorize with your Fission account (you can authorize multiple browsers on multiple machines). See &lt;a href="https://guide.fission.codes/developers/webnative/auth" rel="noopener noreferrer"&gt;Webnative Authentication&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;Once you have logged in and granted permission for the app to access &lt;code&gt;Trillian/fission-with-elm&lt;/code&gt; (aka &lt;code&gt;creator/name&lt;/code&gt; as specified in &lt;code&gt;appPermissions&lt;/code&gt; located in the beginning of section: &lt;code&gt;FISSION SETUP&lt;/code&gt;) in your Fission Drive, you will see this simple web page:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8mwnhl1sqnnfc00n108.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx8mwnhl1sqnnfc00n108.PNG" alt="Fission Demo App" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before we implement signing out, I want to give a quick walkthrough of this application.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;The UI&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Under the “Fission with Elm” title, there are two oval-esque elements. The one on the left should display the Fission logo and your Fission username, and the one on the right is a logout button. &lt;/p&gt;

&lt;p&gt;On the far-left side of the screen, you will see “Auth: AuthSucceeded”. When you save a note, more logs will appear here, allowing you to see the process of writing to a Fission Drive.&lt;/p&gt;

&lt;p&gt;The center of the screen has a textbox where you can write a note and a “Save Note” button below it that will write the note to your Fission Drive. This functionality will be implemented after sign out.&lt;/p&gt;

&lt;p&gt;In the bottom right corner, there should be a little blue rectangle which displays the Elm logo and a number. This is a button that will open the Elm debugging window.&lt;/p&gt;

&lt;p&gt;Anyways, on to the implementation of signing out!&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Signing out&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The &lt;code&gt;webnativeRequest&lt;/code&gt; port supports two types methods of signing out: &lt;code&gt;Webnative.leave&lt;/code&gt; and &lt;code&gt;Webnative.signOut&lt;/code&gt; (see &lt;a href="https://package.elm-lang.org/packages/fission-suite/webnative-elm/latest/Webnative" rel="noopener noreferrer"&gt;Webnative&lt;/a&gt;, in the section named "Authentication"). &lt;/p&gt;

&lt;p&gt;&lt;code&gt;Webnative.leave&lt;/code&gt; will redirect the user to a Fission logout lobby, which looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1f0gd71pkeqfpdlxfdii.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1f0gd71pkeqfpdlxfdii.PNG" alt="Fission Logout Lobby" width="800" height="478"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Webnative.signOut&lt;/code&gt; will not redirect the user to a Fission logout lobby.&lt;/p&gt;

&lt;p&gt;To add sign out functionality, go to the &lt;code&gt;SignOut&lt;/code&gt; branch in the update function and replace the current version of it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="kt"&gt;SignOut&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;username&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Nothing&lt;/span&gt;
        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SignOut"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;signOut&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;webnativeRequest&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Bah-duh bing, bah-duh boom! We can now sign in &lt;em&gt;and&lt;/em&gt; sign out! Time to see it in action. Go ahead and test the app by logging in and logging out! Pretty cool! &lt;/p&gt;

&lt;p&gt;Next up on the docket is writing to a Fission Drive, let us dive in!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Data Storage&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Writing to the Wnfs is a two-step process:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Write the data to a file and save it in the Wnfs in the local browser storage&lt;/li&gt;
&lt;li&gt;Once saved locally, replicate and encrypt the data and store it in the Wnfs on the IPFS network&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The following diagram depicts the write process within the context of our application:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0n73bryg5rxfe4e9rj54.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0n73bryg5rxfe4e9rj54.png" alt="Save to Wnfs Process" width="800" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The three circles in the &lt;code&gt;elm app&lt;/code&gt; section represent &lt;code&gt;Msg&lt;/code&gt; and &lt;code&gt;Tag&lt;/code&gt; variants and are milestones in the writing process. We begin by calling the &lt;code&gt;SaveNote&lt;/code&gt; &lt;code&gt;Msg&lt;/code&gt; variant and end in handling a tagged &lt;code&gt;webnativeResponse&lt;/code&gt; with our &lt;code&gt;PublishNote&lt;/code&gt; &lt;code&gt;Tag&lt;/code&gt; variant.&lt;br&gt;
We need to do the following to replicate this process in our application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;type Tag&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Finish defining the variants for the Tag type. Once this is done, we can tag requests and appropriately handle the associated responses.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Helper functions

&lt;ul&gt;
&lt;li&gt;Write several helper functions to help with encoding the data and using tags.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;update&lt;/code&gt; function

&lt;ul&gt;
&lt;li&gt;Update various case statement branches to accommodate saving a note.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once we get through that, our application will be complete. Let’s get started!&lt;/p&gt;
&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;type Tag&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This is our current state of our &lt;code&gt;Tag&lt;/code&gt; type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt;
    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;ChangeMeLater&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need to swap the current variant from &lt;code&gt;ChangeMeLater&lt;/code&gt; with two new variants: &lt;code&gt;WriteNote&lt;/code&gt; and &lt;code&gt;PublishNote&lt;/code&gt;. This will allow us to handle responses to the write and publish requests.&lt;/p&gt;

&lt;p&gt;Change the &lt;code&gt;type Tag&lt;/code&gt; to look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt;
    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;WriteNote&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kt"&gt;PublishNote&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Helper functions&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Two of these helper functions (&lt;code&gt;tagFromString&lt;/code&gt; and &lt;code&gt;tagToString&lt;/code&gt;) are needed simply because Elm is a strongly typed language and does not have a native way to convert type variants to strings. This gives us extra work to do before we can accomplish our goal. Fortunately for this application, our application is small and will not require much of this kind of code.&lt;/p&gt;

&lt;p&gt;The other two helper functions (&lt;code&gt;encode&lt;/code&gt; and &lt;code&gt;save&lt;/code&gt;) are for encoding our note and preparing it as a &lt;code&gt;Webnative.Request&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;tagFromString&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We can now properly finish the implementation of this function! This will allow us to convert our &lt;code&gt;Type&lt;/code&gt; variants to strings. Replace the half-baked &lt;code&gt;tagFromString&lt;/code&gt; with the following full-baked code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;tagFromString&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Result&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt;
&lt;span class="n"&gt;tagFromString&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt;
        &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WriteNote"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="kt"&gt;Ok&lt;/span&gt; &lt;span class="kt"&gt;WriteNote&lt;/span&gt;

        &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PublishNote"&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="kt"&gt;Ok&lt;/span&gt; &lt;span class="kt"&gt;PublishNote&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="kt"&gt;Err&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;|&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Invalid tag: "&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt; &lt;span class="n"&gt;str&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;tagToString&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As promised, here is the second helper function for the tags. This will convert a &lt;code&gt;Tag&lt;/code&gt; into a &lt;code&gt;String&lt;/code&gt; so we may add it to the &lt;code&gt;webnativeRequest&lt;/code&gt;. Make sure to get the spelling right AND that it matches the spellings used in &lt;code&gt;tagFromString&lt;/code&gt; function. Add this code to the &lt;code&gt;HELPERS&lt;/code&gt; section of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;tagToString&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Tag&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt;
&lt;span class="n"&gt;tagToString&lt;/span&gt; &lt;span class="n"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;tag&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; 
        &lt;span class="kt"&gt;WriteNote&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WriteNote"&lt;/span&gt;
        &lt;span class="kt"&gt;PublishNote&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PublishNote"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;encode&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This application will write our &lt;code&gt;note&lt;/code&gt; to a JSON file. This next helper function will JSON encode our &lt;code&gt;note&lt;/code&gt;. Add the following code to the &lt;code&gt;HELPERS&lt;/code&gt; section of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;encode&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Encode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Value&lt;/span&gt;
&lt;span class="n"&gt;encode&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="kt"&gt;Json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Encode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;
        &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;note"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Encode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="n"&gt;note&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;&lt;strong&gt;&lt;em&gt;&lt;code&gt;save&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This function will take the pieces we have made in this portion of the walkthrough and use them to initiate the writing process. It will first take our &lt;code&gt;note&lt;/code&gt; and encode it to a JSON value, prettify it, and then write it to a specified file with an associated &lt;code&gt;Tag&lt;/code&gt;. Add the following code to the &lt;code&gt;HELPERS&lt;/code&gt; section of the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;save&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;String&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt;
&lt;span class="n"&gt;save&lt;/span&gt; &lt;span class="n"&gt;note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="n"&gt;note&lt;/span&gt;    
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;encode&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Json&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Encode&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;encode&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Wnfs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;writeUtf8&lt;/span&gt;
            &lt;span class="kt"&gt;Wnfs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Private&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Path&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Apps"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Trillian"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fission-with-elm"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;notes"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;note.json"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tagToString&lt;/span&gt; &lt;span class="kt"&gt;WriteNote&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;update Function&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;The prep work has been laid, now we need to establish some milestones. The writing process will begin when we click the “Save Note” button, which will send a &lt;code&gt;webnativeRequest&lt;/code&gt; tagged with &lt;code&gt;WriteNote&lt;/code&gt;. We will then handle the associated response and then send one more &lt;code&gt;webnativeRequest&lt;/code&gt; tagged with &lt;code&gt;PublishNote&lt;/code&gt;. The final step will be handling the associated response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;SaveNote&lt;/code&gt; msg&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To begin, we need to change the &lt;code&gt;Cmd.none&lt;/code&gt; in our &lt;code&gt;SaveNote&lt;/code&gt; update branch to a &lt;code&gt;Cmd&lt;/code&gt; that calls our &lt;code&gt;webnativeRequest&lt;/code&gt; port. Replace &lt;code&gt;Cmd.none&lt;/code&gt; with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;webnativeRequest&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;|&lt;/span&gt; &lt;span class="n"&gt;save&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;note&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will begin our interaction with Webnative by writing our &lt;code&gt;note&lt;/code&gt; to a file and then writing it to our Wnfs. The next step is to handle the response.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;WriteNote&lt;/code&gt; handler&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;WriteNote&lt;/code&gt; response will be caught by our subscription to the &lt;code&gt;webnativeResponse&lt;/code&gt; port and be redirected to the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; &lt;code&gt;Msg&lt;/code&gt; variant. Add the following branch to &lt;code&gt;GotWebnativeResponse&lt;/code&gt;, just before the &lt;code&gt;Wnfs _ _&lt;/code&gt; branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="kt"&gt;Wnfs&lt;/span&gt; &lt;span class="kt"&gt;WriteNote&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Note Written..."&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="n"&gt;tag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tagToString&lt;/span&gt; &lt;span class="kt"&gt;PublishNote&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Wnfs&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;publish&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;webnativeRequest&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;This code block will add an entry to our &lt;code&gt;model&lt;/code&gt;’s list of logs and then chain a new request to publish our updated Wnfs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;&lt;code&gt;PublishNote&lt;/code&gt; handler&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our &lt;code&gt;PublishNote&lt;/code&gt; response will again be caught by our subscription to the &lt;code&gt;webnativeResponse&lt;/code&gt; port and be redirected to the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; &lt;code&gt;Msg&lt;/code&gt; variant. In &lt;code&gt;GotWebnativeResponse&lt;/code&gt;, replace the &lt;code&gt;Wnfs _ _&lt;/code&gt; branch with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="kt"&gt;Wnfs&lt;/span&gt; &lt;span class="kt"&gt;PublishNote&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;
        &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Note Published to Fission Drive!"&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logs&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code block will add an entry to our &lt;code&gt;model&lt;/code&gt;’s list of logs and then do nothing because the process of writing our note to the Wnfs has reached its end. Your file will then be accessible from your Fission Drive! It may take a few seconds to propagate the data to the Drive, so be aware of that. &lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Finished Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s do a quick walk through of writing to your Fission Drive. Begin by opening a new window or tab, and navigate to your &lt;a href="https://drive.fission.codes/" rel="noopener noreferrer"&gt;Fission Drive&lt;/a&gt;. Once there, navigate to the &lt;code&gt;fission-with-elm&lt;/code&gt; directory (Apps &amp;gt; Trillian &amp;gt; fission-with-elm). This directory should be empty (unless you saved a &lt;code&gt;note&lt;/code&gt; between finishing the app and now).&lt;/p&gt;

&lt;p&gt;Refresh the app page in the browser to make sure your browser has loaded the latest compiled version of the app from the server. Now, navigate to the “Fission with Elm” application and add some text to the input field in the app. It can be as quick as “asdf” or as creative as “test”, it is up to you. Once you have done so, click the “Save Note” button and then navigate back to your Fission Drive. As a reminder, it can take a few seconds for the new note to propagate to your Drive. Once a note has been written, there should appear a new directory within the &lt;code&gt;fission-with-elm&lt;/code&gt; directory called &lt;code&gt;notes&lt;/code&gt;. Enter that directory and you will see a JSON file entitled &lt;code&gt;note&lt;/code&gt;. If you click on it, you will see the contents of the file in a preview window located on the right side of the screen. Like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmflklynqmzzozaa52hyl.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmflklynqmzzozaa52hyl.PNG" alt="Fission Note Preview" width="800" height="477"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voilà!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The End of a Trilogy&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;There is not much reading left now. And I can guarantee this ending is not as satisfying as the end of watching the &lt;em&gt;Lord of the Rings&lt;/em&gt; trilogy for the umpteenth time… But hey, we made it. The “Fission with Elm” demonstration app is now fully functioning, and you now have a better grip on the basics of integrating Fission into your code.&lt;/p&gt;

&lt;p&gt;In the first part of this series, I showed you how to set up Vite to manage Elm applications. This was the foundation of the application. In the second part, I showed you how to integrate Fission into an Elm project via the &lt;code&gt;webnative-elm&lt;/code&gt; module. This highlighted the structure of Fission integration. This third part took what was established in the previous two parts and demonstrated &lt;em&gt;some&lt;/em&gt; of the processes of Fission.&lt;/p&gt;

&lt;p&gt;I hope you have found this series of articles helpful as you begin to build Fission-based applications in Elm!&lt;/p&gt;

&lt;p&gt;Feel free to email any questions you may have to &lt;a href="mailto:info@xeticode.com"&gt;info@xeticode.com&lt;/a&gt; and my team and I will answer as promptly as we can :)&lt;/p&gt;




&lt;h1&gt;
  
  
  Appendix A
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Creating a Fission account
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Go to &lt;a href="https://fission.codes/" rel="noopener noreferrer"&gt;https://fission.codes/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Click on the "Sign up" button (located in the top portion of the screen)&lt;/li&gt;
&lt;li&gt;Click "Create account"&lt;/li&gt;
&lt;li&gt;Enter an email and desired username into the fields&lt;/li&gt;
&lt;li&gt;Click "Get started"&lt;/li&gt;
&lt;li&gt;Follow the instructions on your screen to link your account to another device!&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>fission</category>
      <category>elm</category>
      <category>vite</category>
    </item>
    <item>
      <title>Using Fission with Elm - Part 2: Integrating Fission into the Elm project</title>
      <dc:creator>Verge729</dc:creator>
      <pubDate>Mon, 18 Oct 2021 22:47:24 +0000</pubDate>
      <link>https://dev.to/xeticode/using-fission-with-elm-part-2-integrating-fission-into-the-elm-project-3k0k</link>
      <guid>https://dev.to/xeticode/using-fission-with-elm-part-2-integrating-fission-into-the-elm-project-3k0k</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Prelude&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is part of a three-part series. In part one, I demonstrated how to use Vite to manage an Elm application. In part two (this article), I will show you how to integrate Fission into the project from part one. Part three will walk you through how to refactor the project for Fission authentication and Fission Drive.&lt;/p&gt;

&lt;p&gt;The Github repository associated with this article can be found here:&lt;br&gt;
&lt;a href="https://github.com/xeticode/fission-with-elm-demos/tree/Part-2" rel="noopener noreferrer"&gt;https://github.com/xeticode/fission-with-elm-demos/tree/Part-2&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Welcome to round two! The time has come to upgrade our project from part one! The upgrade will connect the application to Fission, which I will introduce to you in a short moment. Before the introduction, I want to point out why Fission is a tool of the future. Fission uses a distributed system to store data. To one up that, Fission built a file system in the distributed system and protects it with military grade encryption. That means you can have a whole file system saved and protected across a whole network (in this case, the internet) rather than just on a remote machine or your own. And for app development, it means no need to worry about server maintenance or scaling. Anyways, I am getting ahead of myself. Without further ado, I present to you the InterPlanetary File System (IPFS) and, of course, Fission. &lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Enter IPFS…&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;In short, the “IPFS is a distributed system for storing and accessing files, websites, applications, and data” (for more information, see &lt;a href="https://docs.ipfs.io/concepts/what-is-ipfs/" rel="noopener noreferrer"&gt;IPFS&lt;/a&gt;). No more need for centralized servers! Have you ever heard of blockchain? It uses a similar technical approach: peer-to-peer networking using content addressing. Say goodbye to centralized servers!&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Enter Fission…&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To add to my pre-introduction, Fission is built on top of the IPFS, and implements a layer of military grade encryption. I know I mentioned this before, but it deserves more attention. Fission created a file system called Webnative File System (Wnfs). It has a huge advantage over cloud storage in that it resides in a distributed system rather than centralized servers, meaning it is backed up on a vast network of machines and not at the data centers of some tech company.&lt;/p&gt;

&lt;p&gt;Fission developed the &lt;code&gt;Webnative SDK&lt;/code&gt; to interact with Fission services. Since we are working with an Elm application, we will use the &lt;code&gt;Webnative-elm&lt;/code&gt; module for Elm (see &lt;a href="https://package.elm-lang.org/packages/fission-suite/webnative-elm/6.0.0/" rel="noopener noreferrer"&gt;Webnative-Elm&lt;/a&gt;). Using this wrapper allows us to maximize our Elm code and minimize the JavaScript for the project. &lt;/p&gt;


&lt;h2&gt;
  
  
  &lt;strong&gt;The Walkthrough&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;NOTE: This article assumes you have completed the project as described in part 1. If you have not completed that project, please go back and follow the steps in part 1 to complete it or download the part 1 reference project. See &lt;a href="https://dev.to/xeticode/using-fission-with-elm-part-1-using-vite-to-manage-elm-applications-4ahk"&gt;Fission with Elm, Part 1: Using Vite to manage Elm applications&lt;/a&gt; for both options.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Installing Webnative dependencies&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;To start things off, we will need to install Webnative to our node modules and &lt;code&gt;elm.json&lt;/code&gt; file. To do this, run the following commands in the terminal from the root directory of the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev webnative webnative-elm
npx elm-json install fission-suite/webnative-elm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;&lt;code&gt;npm install webnative webnative-elm&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; will install both &lt;code&gt;webnative&lt;/code&gt; and &lt;code&gt;webnative-elm&lt;/code&gt; libraries to the project (check &lt;code&gt;package.json&lt;/code&gt; for the new additions).&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;&lt;code&gt;npx elm-json install fission-suite/webnative-elm&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; will install the Elm dependency of the &lt;code&gt;fission-suite/webnative-elm&lt;/code&gt; module (check &lt;code&gt;elm.json&lt;/code&gt; for the new addition). This module is a wrapper, written in Elm, for &lt;code&gt;Webnative&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Modifying js/index.js&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;This is pretty simple. &lt;/p&gt;

&lt;p&gt;At the top of the file, add these two lines:&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="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;webnative&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;webnative&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;webnativeElm&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;webnative&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;elm&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And after the &lt;code&gt;const app = Elm.Main.init({});&lt;/code&gt; line, add these two lines:&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="nx"&gt;webnative&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;debug&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;enabled&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="nx"&gt;webnativeElm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;webnative&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a quick breakdown of the new lines:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;&lt;code&gt;webnative.setup.debug({enabled:true});&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; toggles on the debug mode. If enabled, the debug mode will output Webnative-related messages to the &lt;code&gt;Console&lt;/code&gt; tab in the &lt;code&gt;Developer Tools&lt;/code&gt; window. Toggle debug mode with this window open and you will easily see the difference.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;&lt;em&gt;&lt;code&gt;webnativeElm.setup({app, webnative});&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; initiates the &lt;code&gt;webnative-elm&lt;/code&gt; wrapper, taking the initialized Elm application and the &lt;code&gt;Webnative SDK&lt;/code&gt; connection as parameters.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Modifying src/Main.elm&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Ports&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Elm ports are how an Elm application can communicate with JavaScript, or the “outside world” as I like to call it (for an in-depth explanation of Elm ports, see &lt;a href="https://guide.elm-lang.org/interop/ports.html" rel="noopener noreferrer"&gt;Elm Ports&lt;/a&gt;). The current state of the &lt;code&gt;Main.elm&lt;/code&gt; file does not permit the use of ports. To change this, we need to change the file from a standard module to a port module. On line 1 of &lt;code&gt;Main.elm&lt;/code&gt;, add &lt;code&gt;port&lt;/code&gt; before &lt;code&gt;module&lt;/code&gt;. We can now use ports in this Elm file! Let’s add some!&lt;br&gt;
Normally, Elm ports require two ends: one Elm, and one in JavaScript. What makes this situation “abby”-normal (if you know, you know) is that this application is only concerned with interacting with Fission. The &lt;code&gt;webnative-elm&lt;/code&gt; wrapper handles the JavaScript end of the Webnative-related ports. The wrapper has also consolidated all of the ports we may need into two ports: one for all Webnative requests, and one for all Webnative responses.&lt;br&gt;
The &lt;code&gt;Webnative SDK&lt;/code&gt; requires two ports: one for requests, and one for responses. Add these two lines just after the import block at the top of the file in &lt;code&gt;Main.elm&lt;/code&gt; to satisfy the requirement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;port&lt;/span&gt; &lt;span class="n"&gt;webnativeRequest&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Request&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;
&lt;span class="k"&gt;port&lt;/span&gt; &lt;span class="n"&gt;webnativeResponse&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Response&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Sub&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you have them added, you will notice the red squiggles under &lt;code&gt;Webnative.Request&lt;/code&gt; and &lt;code&gt;Webnative.Response&lt;/code&gt;. This is because we have yet to import &lt;code&gt;Webnative&lt;/code&gt; to the file. Add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to the import block at the top of the file.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Adding Permissions&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Every Fission-based application requires a set of defined permissions to initialize the application.&lt;br&gt;
There are three functions we will add to our project to define these permissions: &lt;code&gt;appPermissions&lt;/code&gt;, &lt;code&gt;fsPermissions&lt;/code&gt;, and &lt;code&gt;permissions&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;appPermissions&lt;/code&gt;&lt;/em&gt; will return a record with fields indicating the name of the application and the creator of the application. Add the following just after the Webnative ports in &lt;code&gt;Main.elm&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;appPermissions&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;AppPermissions&lt;/span&gt;
&lt;span class="n"&gt;appPermissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;creator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Trillian"&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;fission-with-elm"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is what Fission will use to create a file path within the Wnfs to the files produced by this application (i.e. &lt;code&gt;Apps/Trillian/fission-with-elm/&lt;/code&gt;). Feel free to change the creator field to your own username if you so desire.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;fsPermissions&lt;/code&gt;&lt;/em&gt; will return a record with fields indicating what public and private parts of the Wnfs for which the application will request access (“fs” stands for File System here). Add the following a couple of lines after &lt;code&gt;appPermissions&lt;/code&gt;, but before &lt;code&gt;type alias Flags&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;fsPermissions&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;FileSystemPermissions&lt;/span&gt;
&lt;span class="n"&gt;fsPermissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;public&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;directories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
        &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&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="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;private&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
            &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;directories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
            &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;files&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This application is not asking to access any parts of the Wnfs external to this application, so the lists will remain empty. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;permissions&lt;/code&gt;&lt;/em&gt; the icing on the cake. This will return a record with two fields: &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;fs&lt;/code&gt;. These correspond to the two previous code blocks we talked about. Add the following a couple of lines after &lt;code&gt;fsPermissions&lt;/code&gt;, but before &lt;code&gt;type alias Flags&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;permissions&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Permissions&lt;/span&gt;
&lt;span class="n"&gt;permissions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;appPermissions&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;Just&lt;/span&gt; &lt;span class="n"&gt;fsPermissions&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will pass this, our newly defined &lt;code&gt;permissions&lt;/code&gt;, through the &lt;code&gt;webnativeRequest&lt;/code&gt; port in the next step.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;The &lt;code&gt;init&lt;/code&gt; and &lt;code&gt;subscriptions&lt;/code&gt; functions&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;&lt;code&gt;init&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;The only difference here is changing the Cmd msg from &lt;code&gt;Cmd.none&lt;/code&gt; to a command that will initialize the application as a Webnative application. The new &lt;code&gt;init&lt;/code&gt; function should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;init&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;Flags&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Url&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Navigation&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Key&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Model&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt; &lt;span class="kt"&gt;Msg&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;init&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="kt"&gt;Model&lt;/span&gt;
    &lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;permissions&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;init&lt;/span&gt;
        &lt;span class="o"&gt;|&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;webnativeRequest&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a quick explanation of the new command:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;permissions&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; was previously defined in the walkthrough. It indicates both the name and creator of the application and contains a list of Wnfs access requests.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;Webnative.init&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; is a function of &lt;code&gt;webnative-elm&lt;/code&gt; that will load a user's Wenative File System, if said user is authenticated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;em&gt;&lt;code&gt;webnativeRequest&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; is our port for our Webnative related requests.
&lt;strong&gt;&lt;em&gt;&lt;code&gt;subscriptions&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt; 
We now need to subscribe to &lt;code&gt;webnativeResponse&lt;/code&gt; so the response will be properly handled and not left by the wayside. In the &lt;code&gt;subscriptions&lt;/code&gt; function, change &lt;code&gt;Sub.none&lt;/code&gt; to:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="n"&gt;webnativeResponse&lt;/span&gt; &lt;span class="kt"&gt;GotWebnativeResponse&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will set the application to watch our &lt;code&gt;webnativeResponse&lt;/code&gt; port for any changes. &lt;code&gt;GotWebnativeResponse&lt;/code&gt; is a &lt;code&gt;Msg&lt;/code&gt; variant we will add in a few moments and will be where we handle the response.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Adding a variant to the &lt;code&gt;Msg&lt;/code&gt; and updating the &lt;code&gt;update&lt;/code&gt; function&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;&lt;code&gt;Msg&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;At this point, we have only two &lt;code&gt;Msg&lt;/code&gt; variants: &lt;code&gt;UrlChanged Url.Url&lt;/code&gt; and &lt;code&gt;LinkClicked Browser.UrlRequest&lt;/code&gt;. To handle the &lt;code&gt;webnativeResponse&lt;/code&gt;, we need to add the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; variant. Add the new variant to the &lt;code&gt;Msg&lt;/code&gt; so that it looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="kt"&gt;Msg&lt;/span&gt; 
    &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kt"&gt;UrlChanged&lt;/span&gt; &lt;span class="kt"&gt;Url&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Url&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kt"&gt;LinkClicked&lt;/span&gt; &lt;span class="kt"&gt;Browser&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;UrlRequest&lt;/span&gt;
    &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kt"&gt;GotWebnativeResponse&lt;/span&gt; &lt;span class="kt"&gt;Webnative&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="kt"&gt;Response&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This new variant will allow us to dictate how to handle each response the application receives from &lt;code&gt;webnativeResponse&lt;/code&gt;. Our friendly red squiggles should now be present on our &lt;code&gt;update&lt;/code&gt; function. This is because our new &lt;code&gt;Msg&lt;/code&gt; variant is a new branch the case statement in our &lt;code&gt;update&lt;/code&gt; function needs to handle. The only problem? We have yet to add the branch to the case statement. This exemplifies one of the beauties of Elm, it forces us to handle each defined potential outcome or branch of whatever it is that is the subject of a case statement. Super helpful if you are, at times, forgetful 😉 Let us now add the new branch to update.&lt;/p&gt;

&lt;h5&gt;
  
  
  &lt;strong&gt;&lt;em&gt;&lt;code&gt;update&lt;/code&gt;&lt;/em&gt;&lt;/strong&gt;
&lt;/h5&gt;

&lt;p&gt;That being said, as much as we may enjoy the red squiggles, they need to go. Add the following branch to the &lt;code&gt;update&lt;/code&gt; function's case statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="kt"&gt;GotWebnativeResponse&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Cmd&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;none&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will satisfy the Elm compiler, but it needs to be noted that this state of the &lt;code&gt;GotWebnativeResponse&lt;/code&gt; branch does not handle anything. It is currently a dead end for the Webnative response, and for the time being, it will stay that way. The reason for this decision is that adding the proper logic to this branch fits beautifully with what is covered in part three of this series: authentication and interacting with the Wnfs. So be sure to check out part three!&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Ending&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Before its over: See that it works&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;So far we have done all this work, but have yet to visually see any of that work in our app. If you have not done so already, get your dev server running. Once you have the app running, open the &lt;code&gt;Developer Tools&lt;/code&gt; window in your browser, and go to the &lt;code&gt;Console&lt;/code&gt; tab. You should see the following message in the list of messages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[vite-plugin-elm] ports. webnativeRequest.subscribe called
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This indicates that our application is listening to the &lt;code&gt;webnativeRequest&lt;/code&gt; port! Visually, it is not much, but internally this is very important. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Adieu&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;And there you have it! The application has been upgraded with Fission integration. In this article, I showed you how to build upon what we made in the first article. In the third article, we will see the culmination as functionality is added to the project. If you wish to learn more about Fission or the Webntive-Elm module, check out these links: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fission

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://fission.codes/" rel="noopener noreferrer"&gt;https://fission.codes/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.fission.io/docs/" rel="noopener noreferrer"&gt;https://docs.fission.io/docs/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://guide.fission.codes/" rel="noopener noreferrer"&gt;https://guide.fission.codes/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Webnative-elm

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://package.elm-lang.org/packages/fission-suite/webnative-elm/6.0.0/" rel="noopener noreferrer"&gt;https://package.elm-lang.org/packages/fission-suite/webnative-elm/6.0.0/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

</description>
      <category>elm</category>
      <category>fission</category>
      <category>vite</category>
    </item>
    <item>
      <title>Using Fission with Elm - Part 1: Using Vite to manage Elm applications</title>
      <dc:creator>Verge729</dc:creator>
      <pubDate>Tue, 12 Oct 2021 22:34:16 +0000</pubDate>
      <link>https://dev.to/xeticode/using-fission-with-elm-part-1-using-vite-to-manage-elm-applications-4ahk</link>
      <guid>https://dev.to/xeticode/using-fission-with-elm-part-1-using-vite-to-manage-elm-applications-4ahk</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Prelude&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;This is a three-part series. In part one (this article), I will show you how to use Vite to manage an Elm application. The second article will show you how to integrate the basics of Fission via the Webnative SDK into the project and the third will walk you through how to refactor the project for Fission authentication and using a Fission Drive.&lt;/p&gt;

&lt;p&gt;The Github repository associated with this article can be found here: &lt;a href="https://github.com/xeticode/fission-with-elm-demos/tree/Part-1" rel="noopener noreferrer"&gt;https://github.com/xeticode/fission-with-elm-demos/tree/Part-1&lt;/a&gt; .&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;Intro&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Hello, hello! In this article, I will walkthrough how to initialize a Vite project and then set up an Elm application within that project. Before I do that, I will quickly introduce you to both Vite and Elm because a lack of character development is almost always an insufficient foundation for any good story. So, without further ado…&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Enter Elm…&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Elm is not only a typed, pure functional language that transpiles to JavaScript, it is also an architecture for web applications (known as The Elm Architecture or TEA, for short). As a language, Elm offers excellent error messages and is able to avoid runtime errors at compile time because of its strong typing and pure functions. This combination can make refactoring a project a breeze as Elm directs the developer to the exact spot or a specified area where the error is occurring. As an architecture, Elm employs a reactive Model-View-Controller design, or more common within the code: a Model, a view, and an update function. As the user interacts with the UI, messages are sent to the update function which then can alter the data within the Model, which will then update the UI, and the cycle continues on.&lt;/p&gt;

&lt;p&gt;To learn more about Elm, check out &lt;a href="https://elm-lang.org/" rel="noopener noreferrer"&gt;https://elm-lang.org/&lt;/a&gt; .&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Enter Vite…&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Vite is a bundling tool that uses browser-native ES modules and tools such as Rollup to build a project. Vite makes it easy to build JS modules along side your Elm code for seamless project deployment. This will not be apparent in this article because we will not be using JS modules. That being said, we will use them in subsequent articles, so setting up Elm with Vite is necessary moving forward. For now, we will have the benefit of using the dev server, build, and build preview functionality offered by this tool.&lt;/p&gt;

&lt;p&gt;To learn more about Vite, check out &lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;https://vitejs.dev/&lt;/a&gt; .&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Walkthrough&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Alright, now that introductions have been made, we can proceed!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Initialize the Vite project&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First things first: open an IDE of your choice and open the directory in which you want to store the &lt;code&gt;fission-with-elm&lt;/code&gt; application. Once that is done, run the following commands in the terminal from the directory holding the project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init vite
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will initialize a Vite project.&lt;/p&gt;

&lt;p&gt;We will be prompted to enter a name for the Vite project. Normally, this would be your chance to come up with something creative, but since this is a walkthrough, that will have to wait. Name the project &lt;code&gt;fission-with-elm&lt;/code&gt;. Anyway, next you will then be prompted to select a web framework. Vite initializes a project differently based on the chosen web framework. As Elm is not one of the core frameworks we will select &lt;code&gt;vanilla&lt;/code&gt; for the framework and &lt;code&gt;vanilla&lt;/code&gt; as the variant.&lt;/p&gt;

&lt;p&gt;Once the Vite project has successfully been initialized, these will be the next commands to run, some of which are displayed at the end of the output from the &lt;code&gt;npm init vite&lt;/code&gt; command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd fission-with-elm
npm install --save-dev vite-plugin-elm
npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands do the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;cd fission-with-elm&lt;/code&gt; : will move the terminal's working directory into the project directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm install --save-dev vite-plugin-elm&lt;/code&gt; : will install a Vite plugin that bridges the gap between Vite and Elm. Vite supports a handful of web frameworks from the get-go and Elm is not one of them. Thus we install a plugin to make up for that. The &lt;code&gt;--save-dev&lt;/code&gt; tag will make this a development dependency, which is a dependency kept for development and building of the project, but is not kept for deployment.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run dev&lt;/code&gt; : will begin the dev server. &lt;code&gt;dev&lt;/code&gt; is a script defined in the &lt;code&gt;package.json&lt;/code&gt; file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before running these commands in the terminal, take a look at the file explorer and browse the files added by &lt;code&gt;npm init vite&lt;/code&gt;. You should see:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;.gitignore&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;favicon.svg&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;index.html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;main.js&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;style.css&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As we change some of the project structure, some of these files will become redundant and can be removed. I will indicate which files those are at the appropriate times. Now run the three commands indicated by the terminal. &lt;/p&gt;

&lt;p&gt;After running &lt;code&gt;npm run dev&lt;/code&gt; you will see the dev server is running at &lt;code&gt;http://localhost:3000&lt;/code&gt;. If you go there you should see this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq27yafazd7am7bomhqm1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq27yafazd7am7bomhqm1.PNG" alt="Vite Browser" width="588" height="351"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only thing that remains to finish initializing this Vite project is making it so the project can properly use the Elm plugin. To do this, we will create a file named &lt;code&gt;vite.config.js&lt;/code&gt;. This file will be placed within the current directory (which is named after the name you chose for the Vite project). The file needs to contain the following:&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;elmPlugin&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;vite-plugin-elm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// identify what plugins we want to use&lt;/span&gt;
  &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;elmPlugin&lt;/span&gt;&lt;span class="p"&gt;()],&lt;/span&gt;
  &lt;span class="c1"&gt;// configure our build&lt;/span&gt;
  &lt;span class="na"&gt;build&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// file path for the build output directory&lt;/span&gt;
    &lt;span class="na"&gt;outDir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;build&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// esbuild target&lt;/span&gt;
    &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;es2020&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Set up the Elm Application: Installation&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;elm-tooling&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Life and setting up an Elm application have at least one thing in common: there are many ways to do it. As this is a dev article, I will not indicate which way of life you should live, but I will tell you which method to use to set up an Elm application. For this project, we use &lt;code&gt;elm-tooling&lt;/code&gt;. It is a command line program for managing Elm tools, namely: &lt;code&gt;elm&lt;/code&gt;, &lt;code&gt;elm-format&lt;/code&gt;, &lt;code&gt;elm-json&lt;/code&gt;, and &lt;code&gt;elm-test-rs&lt;/code&gt; (see &lt;a href="https://elm-tooling.github.io/elm-tooling-cli/" rel="noopener noreferrer"&gt;elm-tooling-cli&lt;/a&gt; for more information).  First step for setting up an Elm application is to install elm-tooling. Run the following commands in the terminal (double check to make sure you are still in the &lt;code&gt;fission-with-elm&lt;/code&gt; directory):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save-dev elm-tooling
npx elm-tooling init
npx elm-tooling install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These commands do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm install --save-dev elm-tooling&lt;/code&gt; : installs the &lt;code&gt;elm-tooling&lt;/code&gt; tool to the project. &lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm elm-tooling init&lt;/code&gt; : will initialize &lt;code&gt;elm-tooling&lt;/code&gt; within the project. You will notice a new file named &lt;code&gt;elm-tooling.json&lt;/code&gt; : appear in the file explorer.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npx elm-tooling install&lt;/code&gt; : will install the selected tools to &lt;code&gt;~/.elm/elm-tooling/&lt;/code&gt; and create soft links to these tools in &lt;code&gt;./node_modules/.bin/&lt;/code&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can see what tools &lt;code&gt;elm-tooling&lt;/code&gt; has to offer by running the&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx elm-tooling tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;command. This will also let you select the tools you want for the project. Running the command will present you with output like this one: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagttu2olm94z777kbzrm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fagttu2olm94z777kbzrm.PNG" alt="elm-tooling menu" width="519" height="372"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, &lt;code&gt;elm&lt;/code&gt;, &lt;code&gt;elm-format&lt;/code&gt;, and &lt;code&gt;elm-json&lt;/code&gt; are selected by default. We will not be using the last tool, &lt;code&gt;elm-test-rs&lt;/code&gt;, which is a tool used for testing the application, as writing tests is beyound the scope of these articles.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;elm-json&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Next, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx elm-json new
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create a file named &lt;code&gt;elm.json&lt;/code&gt;. This file holds information concerning the Elm application such as: dependencies, location of source directories, and which version of Elm is being used for the project. There will be a question about what type of Elm project you want, select “application”.&lt;/p&gt;

&lt;p&gt;At this point we have four JSON files: elm.json, elm-tooling.json, package-lock.json, package.json. Here is what is significant about each file:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;code&gt;elm.json&lt;/code&gt; : this contains Elm specific information such as Elm module dependencies, the version of Elm being used, and the file path(s) to any source directories within the project.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;elm-tooling.json&lt;/code&gt; : this contains a limited selection of Elm tools&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;package-lock.json&lt;/code&gt; : the npm package version lock.&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;package.json&lt;/code&gt; : this contains information of the project such as the name of the project, command line scripts (i.e., the dev command previously executed in this walkthrough).&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  &lt;em&gt;Set up the Elm Application: Modifying to the file structure&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Ok, now that installation has been complete, let’s add some structure to the project! We will be adding a few directories and files with those directories. As a reminder, everything that will be added will be with the &lt;code&gt;fission-with-elm&lt;/code&gt; directory (now referred to as root directory for the remainder of this article).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Add a directory named &lt;code&gt;src&lt;/code&gt;. This will be for your Elm source files. Within that directory, add a file named &lt;code&gt;Main.elm&lt;/code&gt;. Leave the file empty for now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add another directory in the root directory called &lt;code&gt;js&lt;/code&gt;. In this new directory, create a file called &lt;code&gt;index.js&lt;/code&gt;. Leave the file empty for now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create another directory in the root directory called &lt;code&gt;public&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Within &lt;code&gt;public&lt;/code&gt;, create a directory called &lt;code&gt;assets&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Within &lt;code&gt;assets&lt;/code&gt;, create a directory called &lt;code&gt;images&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; The end product here should look like: &lt;code&gt;./public/assets/images/&lt;/code&gt;. For this project, we will be using the Fission logo. You can download this image from the repo associated with this article. To do so, Run the following command in the terminal from the &lt;code&gt;images&lt;/code&gt; directory:
&lt;/li&gt;
&lt;/ol&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  curl -o fission.svg https://raw.githubusercontent.com/xeticode/fission-with-elm-demos/Part-1/public/assets/images/fission.svg
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;

&lt;/ol&gt;




&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Set up the Elm Application: Adding content to the files&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;We are near the end! We have a few files to change: &lt;code&gt;./js/index.js&lt;/code&gt;, &lt;code&gt;./src/Main.elm&lt;/code&gt;, and &lt;code&gt;./index.html&lt;/code&gt;. First, we will take a look at &lt;code&gt;./index.html&lt;/code&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;index.html&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;We need to connect the &lt;code&gt;index.js&lt;/code&gt; file to the &lt;code&gt;index.html&lt;/code&gt; file via a script tag that will be placed within the &lt;code&gt;head&lt;/code&gt; tag. &lt;/p&gt;

&lt;p&gt;This is the new content of the &lt;code&gt;index.html&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"image/svg+xml"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"favicon.svg"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Vite App&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Here is the new script tag --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"./js/index.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- This is the old content --&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- &amp;lt;div id="app"&amp;gt;&amp;lt;/div&amp;gt; --&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- &amp;lt;script type="module" src="/main.js"&amp;gt;&amp;lt;/script&amp;gt; --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;These changes make the &lt;code&gt;main.js&lt;/code&gt; and &lt;code&gt;styles.css&lt;/code&gt; files redundant as we no longer reference them. Both files are used to present the &lt;code&gt;Hello Vite!&lt;/code&gt; webpage from the beginning of the walkthrough. Delete these files now.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;index.js&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;Here is all that is needed in the &lt;code&gt;./js/index.js&lt;/code&gt; file:&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Elm&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/src/Main.elm&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Elm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Main&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;init&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the connection point between &lt;code&gt;index.html&lt;/code&gt; and our Elm application. Line 1 indicates where to find the application, and line 3 initializes the application. &lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Main.elm&lt;/em&gt;&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;This article does not focus on the components of &lt;code&gt;Main.elm&lt;/code&gt;. Because of this, and the length of the file, we will download the file directly from the Github repository. We will dive into the file in Part 2, but for now, use this command to download the &lt;code&gt;Main.elm&lt;/code&gt; file from the repository asociated with this article. We will dive into this file in part 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o Main.elm https://raw.githubusercontent.com/xeticode/fission-with-elm-demos/Part-1/src/Main.elm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Set up the Elm Application: Importing Elm modules&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Alrighty! Go ahead and run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The compilation should fail. Reason being? There are dependencies we refer to from within &lt;code&gt;Main.elm&lt;/code&gt; that have not been installed. Run the following command in the root directory to install the missing dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx elm-json install elm/browser elm/url mdgriffith/elm-ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is some information on the packages being installed (for more info on each package, see &lt;a href="https://package.elm-lang.org/" rel="noopener noreferrer"&gt;https://package.elm-lang.org/&lt;/a&gt; and enter the package name in the search bar):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;elm/browser&lt;/code&gt; enables the Elm application to run in the browser.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;elm/url&lt;/code&gt; handles creation and parsing of Urls (required when using Browser.application).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mdgriffith/elm-ui&lt;/code&gt; handles layout and styling (there are a few options for for layout and styling, and I chose elm-ui for its simplicity, capability, and ease of use).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After running the command, a confirmation prompt will appear regarding the addition of these modules to the &lt;code&gt;elm.json&lt;/code&gt; file. There will be some dependencies to be installed to the indirect dependcies because the direct dependencies depend on them. The word "dependency" was used too much in that last sentence... I recommend having the &lt;code&gt;elm.json&lt;/code&gt; file open so the changes can be visibly seen.&lt;/p&gt;

&lt;p&gt;You can also run the &lt;code&gt;npx elm-json install&lt;/code&gt; command once per dependency if desired. Once those dependencies have been installed, the error messages should disappear and you should see this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwfgad67r37uvx3b4xvm.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiwfgad67r37uvx3b4xvm.PNG" alt="Final View" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  &lt;strong&gt;The Ending&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Before its over: Witness the live reload of Vite&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;For this part, make sure you have the dev server running and a browser open to the &lt;code&gt;localhost&lt;/code&gt; domain. Vite has live reload functionality. In other words, if you change something in the &lt;code&gt;Main.elm&lt;/code&gt; file, it will take note of the changes made and automatically serve the new files. To demonstrate this, go to line 68 in &lt;code&gt;Main.elm&lt;/code&gt;. You should see this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight elm"&gt;&lt;code&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;EBA&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;|&lt;/span&gt; &lt;span class="kt"&gt;E&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rgb255&lt;/span&gt; &lt;span class="mi"&gt;176&lt;/span&gt; &lt;span class="mi"&gt;192&lt;/span&gt; &lt;span class="mi"&gt;222&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line dictates the background color of the application. Change any number of the intgers following &lt;code&gt;E.rgb255&lt;/code&gt; to a value between 0 and 255 inclusive and see the background automatically change!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Before its over: Build and Serve the project&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Before we can &lt;em&gt;officially&lt;/em&gt; wrap this up, I will show you how to build the project and serve the build directory. Run these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
npm run serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both &lt;code&gt;build&lt;/code&gt; and &lt;code&gt;serve&lt;/code&gt; are scripts defined in &lt;code&gt;package.json&lt;/code&gt;. These commands do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm run build&lt;/code&gt; will use Vite to build the project. As it builds, a new directory named &lt;code&gt;build&lt;/code&gt; will appear in the file structure. The first children of this directory will be the static files from the location indicated by the &lt;code&gt;publicDir&lt;/code&gt; tag from the &lt;code&gt;vite.config.js&lt;/code&gt; file. The other children will take a moment to appear and will be the files generated from the build process.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;npm run serve&lt;/code&gt; will start a &lt;code&gt;localhost&lt;/code&gt; server and serve the files from the &lt;code&gt;build&lt;/code&gt; directory. This will be running at &lt;code&gt;http://localhost:5000&lt;/code&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result should be the same as what is produced by the &lt;code&gt;npm run dev&lt;/code&gt; command.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;&lt;em&gt;Adieu&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;And there you have it! A simple Elm project that is managed by Vite. As a reminder, this only covers the basics of setting up Vite and Elm, if you wish to learn more about what they both have to offer, follow these links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Elm

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://package.elm-lang.org/" rel="noopener noreferrer"&gt;https://package.elm-lang.org/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://elm-lang.org/" rel="noopener noreferrer"&gt;https://elm-lang.org/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Vite

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://vitejs.dev/" rel="noopener noreferrer"&gt;https://vitejs.dev/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In the next article, we will alter this project to integrate Webnative, an SDK built and provided by Fission.&lt;/p&gt;

</description>
      <category>elm</category>
      <category>fission</category>
      <category>vite</category>
    </item>
  </channel>
</rss>
