<?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: Steve Monsen</title>
    <description>The latest articles on DEV Community by Steve Monsen (@devwax).</description>
    <link>https://dev.to/devwax</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%2F490953%2Fd4248fdd-065b-4d68-b0fc-2f14a2ba3d12.jpeg</url>
      <title>DEV Community: Steve Monsen</title>
      <link>https://dev.to/devwax</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/devwax"/>
    <language>en</language>
    <item>
      <title>Learning Svelte - Project 1: Dependency Resolution Tool</title>
      <dc:creator>Steve Monsen</dc:creator>
      <pubDate>Tue, 20 Oct 2020 07:00:42 +0000</pubDate>
      <link>https://dev.to/devwax/learning-svelte-project-1-dependency-resolution-tool-b6j</link>
      <guid>https://dev.to/devwax/learning-svelte-project-1-dependency-resolution-tool-b6j</guid>
      <description>&lt;p&gt;I've binge-read the Svelte tutorials for the last few days and it's time to start writing some basic test projects to go beyond basic concepts.&lt;/p&gt;

&lt;p&gt;I'll be posting progress and insights here as I go.&lt;/p&gt;

&lt;h1&gt;
  
  
  About
&lt;/h1&gt;

&lt;p&gt;I found a basic dependency resolution algorithm &lt;a href="https://gist.github.com/RubyTuesdayDONO/5006455"&gt;Gist&lt;/a&gt; the other day and decided to use it as the basis for learning more about Svelte. Basically, an excuse to do something other than stay stuck in tutorial-mode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Graph_theory"&gt;Graph theory&lt;/a&gt; lies at the heart so many modern development paradigms that I thought it would make an excellent &lt;a href="https://en.wikipedia.org/wiki/MacGuffin"&gt;MacGuffin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RX-KsYOv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/b/b6/Moreno_Sociogram_2nd_Grade.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RX-KsYOv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://upload.wikimedia.org/wikipedia/commons/b/b6/Moreno_Sociogram_2nd_Grade.png" alt="Graph theory in sociology: Moreno Sociogram (1953) - Wikipedia"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Project Code
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://codesandbox.io/s/javascript-dependency-resolver-4ecv0?file=/App.svelte"&gt;CodeSanbox&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/devwax/dependency-resolution-with-js/tree/main/"&gt;Github&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Features / To Do
&lt;/h1&gt;

&lt;p&gt;👍 Convert current plain JavaScript CodeSandbox to Svelte.&lt;br&gt;
👍 Format the execution order with an ordered list.&lt;br&gt;
👍 User editable dependency lists that update in realtime. (add/remove items in left column)&lt;br&gt;
🔘 Auto color-coding of dependencies.&lt;br&gt;
🔘 Hovering an item highlights its use elsewhere (bi-directional item highlighting for legibility)&lt;br&gt;
🔘 Add infinite nested levels of dependencies.&lt;br&gt;
🔘 Revise language... 'before', 'after', 'subscribers', 'items', etc.&lt;br&gt;
🔘 Toggle real-time mode.&lt;br&gt;
🔘 CodeMirror for the dependencies editor&lt;br&gt;
🔘 Undo/redo changes.&lt;br&gt;
🔘 Read a &lt;code&gt;package.json&lt;/code&gt; or other dependency configuration and display its resolution. Upload or via URL / fetch.&lt;br&gt;
🔘 Save to localStorage&lt;br&gt;
🔘 Save state to json / file download&lt;br&gt;
🔘 Authenticated users&lt;br&gt;
🔘 Basic CRUD interface for user lists&lt;br&gt;
🔘 Sharing dependency lists&lt;br&gt;
🔘 Visualization of dependency graph&lt;br&gt;
🔘 API - DRaaS (&lt;em&gt;Dependency Resolution as a Service&lt;/em&gt;)&lt;/p&gt;
&lt;h1&gt;
  
  
  Svelte Concepts to incorporate
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Reactivity&lt;/li&gt;
&lt;li&gt;Fetch, Async/Await&lt;/li&gt;
&lt;li&gt;Props&lt;/li&gt;
&lt;li&gt;Slots&lt;/li&gt;
&lt;li&gt;Binding&lt;/li&gt;
&lt;li&gt;Lifecycles&lt;/li&gt;
&lt;li&gt;Stores&lt;/li&gt;
&lt;li&gt;Motion and Transitions&lt;/li&gt;
&lt;li&gt;State management

&lt;ul&gt;
&lt;li&gt;Basic w/out library&lt;/li&gt;
&lt;li&gt;XState&lt;/li&gt;
&lt;li&gt;Overmind&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Authentication (oAuth 2.0)

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://codechips.me/firebase-authentication-with-xstate-and-svelte/"&gt;Firebase&lt;/a&gt; (w/ Cloudflare Workers KV)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;User storage

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.cloudflare.com/products/workers-kv/"&gt;Cloudflare Workers KV&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Explore &lt;a href="https://developers.cloudflare.com/workers/runtime-apis/durable-objects"&gt;Durable Objects&lt;/a&gt; as an option&lt;/li&gt;
&lt;li&gt;Basic CRUD interface for dependency maps&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;API&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  Progress
&lt;/h1&gt;
&lt;h2&gt;
  
  
  Oct 21, 2020
&lt;/h2&gt;

&lt;p&gt;I turned the dependencies and execution order sections into Svelte components that update automatically on user input by adding a &lt;code&gt;resolution&lt;/code&gt; store and auto-subscribing to it.&lt;/p&gt;

&lt;p&gt;I'm planning on adding CodeMirror which I'm assuming would be best implemented with a Svelte module.&lt;/p&gt;

&lt;p&gt;I found some old libraries that shoe-horned CodeMirror into Svelte, but they were from Svelte 1.x, no longer work and are no longer maintained. Just as well, though, since it will provide an excuse to learn more about Svelte modules and lifecycles.&lt;/p&gt;
&lt;h2&gt;
  
  
  Oct 22, 2020
&lt;/h2&gt;

&lt;p&gt;To be honest, now that I've worked with some of the basic fundamentals of Svelte, I'm more interested in its utility as an authenticated app. Which is the way I'll be using it. In other words, an app that you can sign-in to, do stuff (CRUD, etc), and log out of.&lt;/p&gt;

&lt;p&gt;So now I want to try Firebase authentication with a router. And for that I have two options in mind that I'd like to explore...&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traditional&lt;/strong&gt; - A node server w/ authenticated routes and apis. In which case, &lt;a href="https://sapper.svelte.dev/docs#Server_routes"&gt;Sapper&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Edgy&lt;/strong&gt; &lt;em&gt;(literally)&lt;/em&gt; - Achieve the same effect with higher performance and scalability with Cloudflare Workers, KV and &lt;a href="https://developers.cloudflare.com/workers/runtime-apis/html-rewriter"&gt;HTMLRewriter&lt;/a&gt; stream injection.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I've recently read through a couple of great tutorials by &lt;a href="https://codechips.me/about/"&gt;Ilia Mikhailov&lt;/a&gt; that walk  through using &lt;a href="https://codechips.me/firebase-authentication-with-svelte/"&gt;firebase auth w/ Svelte&lt;/a&gt; either directly or &lt;a href="https://codechips.me/firebase-authentication-with-xstate-and-svelte/"&gt;w/ XState&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'll skip XState for now and focus on the more immediate task of evaluating Sapper, Cloudflare, and service workers.&lt;/p&gt;
&lt;h2&gt;
  
  
  Oct 25, 2020
&lt;/h2&gt;

&lt;p&gt;It looks like running Sapper on Cloudflare is certainly possible. There is a GitHub repo that demonstrates it.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/lukeed"&gt;
        lukeed
      &lt;/a&gt; / &lt;a href="https://github.com/lukeed/svelte-ssr-worker"&gt;
        svelte-ssr-worker
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A quick demo for rendering Svelte server-side (SSR), but within a Cloudflare Worker!
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
svelte-ssr-worker&lt;/h1&gt;
&lt;blockquote&gt;
&lt;p&gt;A quick demo for rendering Svelte server-side (SSR), but within a &lt;a href="https://workers.cloudflare.com/" rel="nofollow"&gt;Cloudflare Worker&lt;/a&gt;!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="https://cloudflareworkers.com/#9e1f81f41405f8851b39f4643ce12754:https://tutorial.cloudflareworkers.com/" rel="nofollow"&gt;Live Demo&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is a demo meant to illustrate how to get Svelte SSR in a Cloudflare worker. It is &lt;em&gt;intentionally&lt;/em&gt; very minimal – it extends the official &lt;a href="https://github.com/sveltejs/template"&gt;&lt;code&gt;svelte-template&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;
Install&lt;/h2&gt;
&lt;div class="highlight highlight-source-shell js-code-highlight"&gt;
&lt;pre&gt;$ git clone https://github.com/lukeed/svelte-ssr-worker
$ &lt;span class="pl-c1"&gt;cd&lt;/span&gt; svelte-ssr-worker
$ npm install&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
Scripts&lt;/h2&gt;
&lt;p&gt;The following are &lt;code&gt;npm&lt;/code&gt; scripts included in the project.&lt;br&gt;
They are invoked via &lt;code&gt;npm run &amp;lt;name&amp;gt;&lt;/code&gt; on the command line; for example: &lt;code&gt;npm run build:dom&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
&lt;code&gt;build&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;This is an alias for &lt;em&gt;sequentially&lt;/em&gt; running the &lt;code&gt;build:dom&lt;/code&gt; and &lt;code&gt;build:ssr&lt;/code&gt; scripts.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; These are sequential because &lt;code&gt;build:ssr&lt;/code&gt; imports the &lt;code&gt;public/index.html&lt;/code&gt; that &lt;code&gt;build:dom&lt;/code&gt; produces.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
&lt;code&gt;build:dom&lt;/code&gt;
&lt;/h3&gt;
&lt;p&gt;Builds the client for production, using the &lt;code&gt;src/index.dom.js&lt;/code&gt; entry point.&lt;/p&gt;
&lt;p&gt;All files within the &lt;code&gt;/public&lt;/code&gt; directory comprise your front-end client application.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Important:&lt;/strong&gt; These must be uploaded to a storage bucket and made available on a CDN location. &lt;br&gt;Alternatively, you may upload…&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/lukeed/svelte-ssr-worker"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I also found an interesting svelte/firebase/cloudflare project on Svelt's subreddit: &lt;a href="https://www.reddit.com/r/sveltejs/comments/gt16s8/new_side_project_saas_built_with_svelte_open_demo/"&gt;https://www.reddit.com/r/sveltejs/comments/gt16s8/new_side_project_saas_built_with_svelte_open_demo/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Oct 27, 2020
&lt;/h2&gt;

&lt;p&gt;Sidetracked with a project, but managed to install Sapper locally and get acquainted. Beyond the basics, one idiosyncrasy that I found with Sapper vs Svelte is the difference between the &lt;a href="https://svelte.dev/docs#Client-side_component_API"&gt;Client&lt;/a&gt; and &lt;a href="https://svelte.dev/docs#Server-side_component_API"&gt;Server&lt;/a&gt; Component APIs.&lt;/p&gt;

&lt;h4&gt;
  
  
  Focusing an input on component mount doesn't work in Sapper
&lt;/h4&gt;

&lt;p&gt;Let's say you have a text input that you want to receive focus on DOM ready.&lt;/p&gt;

&lt;p&gt;In Svelte &lt;em&gt;(w/out Sapper)&lt;/em&gt; you simply add an &lt;code&gt;onMount&lt;/code&gt; method and focus the element after having bound it to a variable with &lt;code&gt;bind:this={inputElement}&lt;/code&gt;. &lt;a href="https://svelte.dev/repl/425d987fa48b28dcaa9872f88d5986e3?version=3.0.0-beta.21"&gt;See example&lt;/a&gt; &lt;em&gt;(not mine)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In Sapper, this doesn't work because, as the &lt;a href="https://svelte.dev/docs#Server-side_component_API"&gt;Sapper API explains&lt;/a&gt;: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Unlike client-side components, server-side components don't have a lifespan after you render them — their whole job is to create some HTML and CSS. For that reason, the API is somewhat different.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I've yet to work out how to use this insight to accomplish the focus-input-onmount effect.&lt;/p&gt;

&lt;p&gt;My initial inquest was to create a separate button that calls a &lt;code&gt;handleFocus&lt;/code&gt; component handler &lt;code&gt;on:click&lt;/code&gt; and that works. When you click the button the element is focused. But we want automatic focus &lt;code&gt;onMount&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So now it's a matter of how to do it within a Sapper app.&lt;/p&gt;

&lt;p&gt;My two initial thoughts on strategy are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Svelte Way™ &lt;em&gt;(unknown atm)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;A traditional DOM event listener of some sort shoe-horned into the Sapper paradigm. &lt;em&gt;(the least desirable option)&lt;/em&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I don't really need this for anything at the moment, but I don't like the idea of leaving it unsolved as it provides some important insights into the fundamental differences between client and server-side Svelte components.&lt;/p&gt;

&lt;p&gt;I'll post with more when I have it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mSnXWtTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1xmcigpurgb5zhrausbl.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mSnXWtTA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1xmcigpurgb5zhrausbl.gif" alt="I'm Ready - Cat"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Update: Mystery Solved (a cup of coffee later)
&lt;/h4&gt;

&lt;p&gt;&lt;code&gt;.focus()&lt;/code&gt; doesn't work &lt;code&gt;onMount&lt;/code&gt; on purpose for a11y reasons. Here's an explanation from Rich:&lt;/p&gt;


&lt;div class="ltag_github-liquid-tag"&gt;
  &lt;h1&gt;
    &lt;a href="https://github.com/sveltejs/sapper/issues/619#issuecomment-480616597"&gt;
      &lt;img class="github-logo" alt="GitHub logo" src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg"&gt;
      &lt;span class="issue-title"&gt;
        Comment for
      &lt;/span&gt;
      &lt;span class="issue-number"&gt;#619&lt;/span&gt;
    &lt;/a&gt;
  &lt;/h1&gt;
  &lt;div class="github-thread"&gt;
    &lt;div class="timeline-comment-header"&gt;
      &lt;a href="https://github.com/Rich-Harris"&gt;
        &lt;img class="github-liquid-tag-img" src="https://res.cloudinary.com/practicaldev/image/fetch/s--o1oKIPJN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://avatars3.githubusercontent.com/u/1162160%3Fv%3D4" alt="Rich-Harris avatar"&gt;
      &lt;/a&gt;
      &lt;div class="timeline-comment-header-text"&gt;
        &lt;strong&gt;
          &lt;a href="https://github.com/Rich-Harris"&gt;Rich-Harris&lt;/a&gt;
        &lt;/strong&gt; commented on &lt;a href="https://github.com/sveltejs/sapper/issues/619#issuecomment-480616597"&gt;&lt;time&gt;Apr 07, 2019&lt;/time&gt;&lt;/a&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag-github-body"&gt;
      &lt;p&gt;This is for a11y — when navigating, the focus is supposed to reset (which is also the reason that the &lt;code&gt;autofocus&lt;/code&gt; attribute is discouraged): &lt;a href="https://github.com/sveltejs/sapper/blob/master/runtime/src/app/app.ts#L154"&gt;https://github.com/sveltejs/sapper/blob/master/runtime/src/app/app.ts#L154&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The focus reset happens after navigation, so setting the focus in &lt;code&gt;onMount&lt;/code&gt; will have no effect. If you &lt;em&gt;really&lt;/em&gt; need to focus the input then the &lt;code&gt;setTimeout&lt;/code&gt; is necessary, but ideally I'd try and see if there's an alternative that doesn't break a11y guidelines.&lt;/p&gt;

    &lt;/div&gt;
    &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/sveltejs/sapper/issues/619#issuecomment-480616597"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mHMZHFzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5vvrru5f2jd7fwnjepuh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mHMZHFzm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5vvrru5f2jd7fwnjepuh.gif" alt="Thanks for the cup of obvious!"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
                                            Thanks for the cup of obvious.
&lt;/h4&gt;

</description>
      <category>svelte</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>codesandbox</category>
    </item>
  </channel>
</rss>
