<?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>Forem: Stef van den Ham</title>
    <description>The latest articles on Forem by Stef van den Ham (@hyra).</description>
    <link>https://forem.com/hyra</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%2F38280%2F285dee7e-7661-49bd-a858-66ff7611fe07.jpg</url>
      <title>Forem: Stef van den Ham</title>
      <link>https://forem.com/hyra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/hyra"/>
    <language>en</language>
    <item>
      <title>A different kind of blog post</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Wed, 29 Apr 2020 08:01:38 +0000</pubDate>
      <link>https://forem.com/hyra/a-different-kind-of-blog-post-1f16</link>
      <guid>https://forem.com/hyra/a-different-kind-of-blog-post-1f16</guid>
      <description>&lt;p&gt;I enjoy blogging, but was suffering of a little bit of a writer's block. Writing short tutorials, walkthroughs, tips and tricks seemed to be getting more and more redundant because a specific answer is usually a Stackoverflow answer away.&lt;/p&gt;

&lt;p&gt;Writing about a mini project however was a lot of fun which I had done in &lt;a href="https://mindthecode.com/blog/exploring-image-recognition-with-node-and-alpr"&gt;the past&lt;/a&gt;. So I decided a different approach and rather than writing a end-to-end clearcut tutorial to achieve something I instead wrote about my outset, decissions, considerations and fails while working on a personal project dealing with a dataset.&lt;/p&gt;

&lt;p&gt;I really enjoyed writing it and while doing it gave me a lot of new inspiration for future code adventures. Of course I have no idea whether other developers might enjoy reading such posts, but I think the main point is that writing these type of posts helps you grow as a developer as you have to put into words what is the chaos that's in your head.&lt;/p&gt;

&lt;p&gt;If you want to read the post, &lt;a href="https://mindthecode.com/blog/developer-adventure-a-quest-to-find-a-large-dataset-of-beers"&gt;it's here&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>beer</category>
    </item>
    <item>
      <title>Launched a free webservice to check your pagespeeds</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Thu, 30 Nov 2017 20:11:18 +0000</pubDate>
      <link>https://forem.com/hyra/launched-a-free-webservice-to-check-your-pagespeeds-ed1</link>
      <guid>https://forem.com/hyra/launched-a-free-webservice-to-check-your-pagespeeds-ed1</guid>
      <description>&lt;p&gt;Heya, after scratching my own itch I decided to publish the tool Wulfdeck at &lt;a href="https://wulfdeck.com/"&gt;https://wulfdeck.com/&lt;/a&gt; for everyone to use for free.&lt;/p&gt;

&lt;p&gt;It finds the linked pages from your site, and then checks them all for their Pagespeed.&lt;/p&gt;

&lt;p&gt;What do you guys think, useful? Pointless? Does it work for you?&lt;/p&gt;

&lt;p&gt;Hope to get some feedback :)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://wulfdeck.com/"&gt;https://wulfdeck.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>showdev</category>
    </item>
    <item>
      <title>Getting started with the PanResponder in React Native</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Thu, 16 Nov 2017 07:48:26 +0000</pubDate>
      <link>https://forem.com/hyra/getting-started-with-the-panresponder-in-react-native-9mf</link>
      <guid>https://forem.com/hyra/getting-started-with-the-panresponder-in-react-native-9mf</guid>
      <description>&lt;p&gt;Inside React Native you can use the PanResponder to recognize multi-touch gestures as well as swipes and other touches that make native apps feel snappy and intuitive. But getting it up and running can feel daunting and borderline black magic. In this post I'll try and guide you through the process, hopefully demystifying it a bit and get you on track to awesomeness.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we will be making
&lt;/h2&gt;

&lt;p&gt;Obviously we'll be wanting to focus on the PanResponder itself so UI wise this will be pretty barebones. We'll have an image on screen we can drag. When we release it it will bounce back to its original position. As a bonus, while we press down on the image it will scale up.&lt;/p&gt;

&lt;center&gt;
![PanResponder Demo](https://mindthecode.com/images/panresponder_demo.gif)
&lt;/center&gt;

&lt;h2&gt;
  
  
  Setting the stage
&lt;/h2&gt;

&lt;p&gt;I'll be assuming you're somewhat familiar with setting up a fresh React Native project. If not, the guys at Facebook have done an excellent job explaining the steps &lt;a href="http://facebook.github.io/react-native/docs/getting-started.html#content" rel="noopener noreferrer"&gt;right here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's start with a new project. I'll call it panresponder-demo for simplicity sake and lack of a name that rhymes with unicorns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;react-native init panresponder_demo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First up, let's add an image to the project that will act as your drag and drop target.&lt;/p&gt;

&lt;p&gt;Create a directory &lt;code&gt;assets&lt;/code&gt; to the panresponder_demo folder and insert the image you want to use in there. If you don't have one, you can use &lt;a href="///images/panresponder-target.png"&gt;this one&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's get our image on the screen so we can continue on to the cool part.&lt;/p&gt;

&lt;p&gt;Open up &lt;code&gt;index.ios.js&lt;/code&gt; and add the &lt;code&gt;Image&lt;/code&gt; component at the top:&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;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;AppRegistry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="c1"&gt;// we want to use an image&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="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now replace the default app content with our Image so alter the &lt;code&gt;render()&lt;/code&gt; method&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="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./assets/panresponder.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;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;When you run the app now you should see the image in the center of the screen, waiting for you to do something more exciting. So let's get to it.&lt;/p&gt;

&lt;center&gt;
![Panresponder 01](https://mindthecode.com/images/panresponder_01.png)
&lt;/center&gt;

&lt;h2&gt;
  
  
  Adding the PanResponder
&lt;/h2&gt;

&lt;p&gt;Let's get to the more interesting part. Adding the PanResponder system.&lt;/p&gt;

&lt;p&gt;At the top, import &lt;code&gt;PanResponder&lt;/code&gt; so we can use it. While we're at it, we'll also add &lt;code&gt;Animated&lt;/code&gt; which allows us to use Animated values, which will come in handy for our animation and calculations.&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;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;AppRegistry&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;StyleSheet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;View&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// we want to use an image&lt;/span&gt;
  &lt;span class="nx"&gt;PanResponder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// we want to bring in the PanResponder system&lt;/span&gt;
  &lt;span class="nx"&gt;Animated&lt;/span&gt; &lt;span class="c1"&gt;// we wil be using animated value&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="s1"&gt;react-native&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PanResponder basically consists of a couple of event-driven methods that you can implement. Once you've defined what you want it to behave like you attach it to a view, which will then propagate all the events (gestures) to the methods you hooked up.&lt;/p&gt;

&lt;p&gt;To illustrate it in a simple way, let's implement the &lt;code&gt;componentWillMount()&lt;/code&gt; method and set up a basic PanResponder instance:&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="nf"&gt;componentWillMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_panResponder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PanResponder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;onMoveShouldSetResponderCapture&lt;/span&gt;&lt;span class="p"&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;onMoveShouldSetPanResponderCapture&lt;/span&gt;&lt;span class="p"&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="na"&gt;onPanResponderGrant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;gestureState&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="na"&gt;onPanResponderMove&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;event&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="p"&gt;]),&lt;/span&gt;

    &lt;span class="na"&gt;onPanResponderRelease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;vx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vy&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="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_panResponder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;panHandlers&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./assets/panresponder.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Animated.View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;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;&lt;strong&gt;Whoa&lt;/strong&gt;, lots going on here. Let's break it down.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onMoveShouldSetResponderCapture&lt;/code&gt; tells the OS we want to allow movement of the view we'll attach this panresponder to. &lt;code&gt;onMoveShouldSetPanResponderCapture&lt;/code&gt; does the same, but for dragging, which we want to be able to do.&lt;/p&gt;

&lt;p&gt;Next up we got 3 methods that will be called &lt;code&gt;onPanResponderGrant&lt;/code&gt; gets invoked when we got access to the movement of the element. This is a perfect spot to set some initial values.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onPanResponderMove&lt;/code&gt; gets invoked when we move the element, which we can use to calculate the next value for the object&lt;/p&gt;

&lt;p&gt;&lt;code&gt;onPanResponderRelease&lt;/code&gt; is invoked when we release the view. In a minute we'll use this to make the image animated back to its original position&lt;/p&gt;

&lt;p&gt;Last up, we add the panresponder to an &lt;code&gt;Animated.View&lt;/code&gt; which we use to wrap the &lt;code&gt;Image&lt;/code&gt; component in so it will obey our panresponding demands.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make it draggable
&lt;/h2&gt;

&lt;p&gt;Let's implement the first 2 methods to be able to drag the image around the screen.&lt;/p&gt;

&lt;p&gt;In order to keep track of where the image is on the screen we'll want to keep a record of its position somewhere. This is the perfect job for a components &lt;code&gt;state&lt;/code&gt;, so let's add this:&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="nf"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ValueXY&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;Next, let's update the &lt;code&gt;panHandler&lt;/code&gt; implementation:&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="nf"&gt;componentWillMount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_panResponder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;PanResponder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;onMoveShouldSetResponderCapture&lt;/span&gt;&lt;span class="p"&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;onMoveShouldSetPanResponderCapture&lt;/span&gt;&lt;span class="p"&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="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="c1"&gt;// Initially, set the value of x and y to 0 (the center of the screen)&lt;/span&gt;
    &lt;span class="na"&gt;onPanResponderGrant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;gestureState&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;

    &lt;span class="c1"&gt;// When we drag/pan the object, set the delate to the states pan position&lt;/span&gt;
    &lt;span class="na"&gt;onPanResponderMove&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;event&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;dx&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;dy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;]),&lt;/span&gt;

    &lt;span class="na"&gt;onPanResponderRelease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;vx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vy&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="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;Basically, upon dragging we updat the states pan value, and when we move, we set the dx/dy to the value from the pan.&lt;/p&gt;

&lt;p&gt;Now that we have our values, we can use this in our &lt;code&gt;render()&lt;/code&gt; method, which gets called constantly as we're dragging, so we can calculate the position of our image in there:&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="nf"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Destructure the value of pan from the state&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;pan&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Calculate the x and y transform from the pan value&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;translateY&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="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;// Calculate the transform property and set it as a value for our style which we add below to the Animated.View component&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;imageStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nx"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;}]};&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;View&lt;/span&gt; &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;imageStyle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{...&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_panResponder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;panHandlers&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt; &lt;span class="nx"&gt;source&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./assets/panresponder.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Animated.View&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/View&lt;/span&gt;&lt;span class="err"&gt;&amp;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;h2&gt;
  
  
  Getting there!
&lt;/h2&gt;

&lt;p&gt;We're getting somewhere. When you run the app now you will be able to drag the image around the screen! However, when you do this for a second time you will notice it starts from the middle of the screen again instead of following up where you left it.&lt;/p&gt;

&lt;p&gt;Let's fix that.&lt;/p&gt;

&lt;p&gt;Fortunately, it's quite simple. We need to alter the initial value in &lt;code&gt;onPanResponderGrant&lt;/code&gt; to take in account the correct offset (we dragged it off center):&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;onPanResponderGrant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;gestureState&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="c1"&gt;// Set the initial value to the current state&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setOffset&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you were to run the code again you will notice a second drag and drop works perfectly, but every time after that the image will jump erratically. This has to do with the way the offset is calculated. We actually need to flatten this once you let go of the image. This can be done in our 3rd and last method:&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;onPanResponderRelease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;vx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vy&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="c1"&gt;// Flatten the offset to avoid erratic behavior&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flattenOffset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Scaling up and down
&lt;/h2&gt;

&lt;p&gt;Last but not least, lets make the image change in size while we're dragging. First we'll add a &lt;code&gt;scale&lt;/code&gt; property to our state so we can use this in our style and influence its value in the PanResponder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ValueXY&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="na"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll use the value of this in our style inside the render method&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="p"&gt;...&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;rotate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0deg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Calculate the transform property and set it as a value for our style which we add below to the Animated.View component&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;imageStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;&lt;span class="nx"&gt;translateX&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;translateY&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;scale&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;With this in place all that's left to do is influence the value of &lt;code&gt;scale&lt;/code&gt; in the PanResponder implementation. When we start dragging the &lt;code&gt;onPanResponderGrant&lt;/code&gt; method is invoked, so we can animate the value&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;onPanResponderGrant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;gestureState&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="c1"&gt;// Set the initial value to the current state&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setOffset&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;_value&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;spring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;toValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;friction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and when we release it we'll animate it back&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;onPanResponderRelease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;vx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vy&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="c1"&gt;// Flatten the offset to avoid erratic behavior&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;flattenOffset&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;Animated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;spring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scale&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;toValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;friction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;And that's it! We got an image we can drag around, and it will give a visual indication we're doing so (besides following our finger).&lt;/p&gt;

&lt;p&gt;The resulting code can be found &lt;a href="https://github.com/Hyra/panresponder_demo" rel="noopener noreferrer"&gt;here on Github&lt;/a&gt;, in case you didn't follow along or want to review it.&lt;/p&gt;

&lt;p&gt;As always, should you have any questions you can find me on &lt;a href="https://twitter.com/hyra" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>react</category>
      <category>programming</category>
      <category>coding</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Launching a webservice: Defining your MVP</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Tue, 14 Nov 2017 08:34:36 +0000</pubDate>
      <link>https://forem.com/hyra/launching-a-webservice-defining-your-mvp-d1c</link>
      <guid>https://forem.com/hyra/launching-a-webservice-defining-your-mvp-d1c</guid>
      <description>&lt;p&gt;When you have an idea for a webservice it's easy to get lost into coding a lot of neat little features. But do you need all of them straight away? More often than not these features will cost you a lot of time to develop, while they might not even be the features your customer want.&lt;/p&gt;

&lt;p&gt;Wikipedia says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Minimum Viable Product (MVP) is a product with just enough features to satisfy early customers, and to provide feedback for future product development.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But how do you decide which features make it into your Minimal Viable Product? As I'm (re-)launching a webservice at the moment I figured it would be good to use it as an example.&lt;/p&gt;

&lt;h2&gt;
  
  
  A little backstory.
&lt;/h2&gt;

&lt;p&gt;For illustration purposes, I'll be using one of my own webservices and use it to go through the process of defining the MVP for it. I recently launched &lt;a href="https://wulfdeck.com"&gt;Wulfdeck.com&lt;/a&gt;, a service that cralws your website and finds all pages. It then takes them through the Google Pagespeed API and finds the pagespeed for each page. Once scanned you can see what needs to be improved to increase the score. As a bonus, it will tell you exactly how much your score will improve per individual improvement, so you don't waste time fixing things that are not be worth the time/tech investment.&lt;/p&gt;

&lt;p&gt;At the moment it uses a Freemium model and a monthly Pro subscription. I've decided that marketing this SaaS will take too much of my time, let alone maintaining it for paying customers (&lt;em&gt;which it doesn't have yet&lt;/em&gt;). So, I will be dropping the account system altogether and .. make the service free for everyone! In addition, it allows me to use it as a real life use case on this blog to illustrate various topics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A win-win situation ðŸ¦„&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Different types of MVP's
&lt;/h2&gt;

&lt;p&gt;The internet will argue there's different kinds of MVP's. The most barebones variation is one where you have a landingpage and 'pretend' to have a product and then ask people to sign up by email to be informed once it launches. This way you can quickly &lt;strong&gt;validate&lt;/strong&gt; whether it's even worth the actual work of building your SaaS before you write a single line of code for it.&lt;/p&gt;

&lt;p&gt;Another version is where you already validated the idea, by talking to people, and want to get your functional product out there. This is the variation we will be discussing here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting a goal
&lt;/h2&gt;

&lt;p&gt;Every product should have a goal. What problem is your SaaS trying to solve? Ideally this is one line clearly stating what your webservice is all about. For our example, Wulfdeck, this could be the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Goal: Give user insight in the Pagespeed of all their pages, by entering their domain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This goal leaves a lot of things unclear. How about things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do users need to have an account?&lt;/li&gt;
&lt;li&gt;Is the service free to use?&lt;/li&gt;
&lt;li&gt;Do I get the results instantly or do I need to wait?&lt;/li&gt;
&lt;li&gt;Do I get just a score, or information what to fix?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first two are not all that important. They could change and are not directly related to the problem we're solving, so we don't need to mention this in our goal.&lt;/p&gt;

&lt;p&gt;The last two are trickier. &lt;strong&gt;Instant results&lt;/strong&gt; sounds directly related, but is it part of the problem we're solving? Maybe not. It could very be the user doesn't mind waiting for the results. Getting &lt;strong&gt;more information&lt;/strong&gt; besides the score is actually quite important, otherwise we're just making the problem visible, not solvable, so let's add it to the goal:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Goal: Give users instructions on how to increase the overall pagespeed of their site by scanning all pages in the domain they enter.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That sounds better! We're stating what we offer, why we do it, and how we do it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the User Journey
&lt;/h2&gt;

&lt;p&gt;As a user goes through the app there are a few steps he/she will follow to get to the result. This is the &lt;em&gt;User Journey&lt;/em&gt; and should be clear from the beginning. If you have too many different ways a user can use the app it will be difficult to build all flows correctly, and what's worse, it will most likely confuse the user.&lt;/p&gt;

&lt;p&gt;What would a user journey for Wulfdeck look like.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Enter the domain&lt;/li&gt;
&lt;li&gt;See list of pages we find&lt;/li&gt;
&lt;li&gt;See instructions on how to increase the pagespeed score for that page&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This may sound over-simplified. And it should be. If your user has to go through a lot of steps it's only logical there's more points in the flow the user will stop and not get to the result.&lt;/p&gt;

&lt;p&gt;In our case we have actively chosen not to have a user registration system. If we did, however, should it be part of the user flow? It could be, but since the user will probably be logged in in order to use the actual product I personally don't think it should be part of the User Journey. If you think about a flow where the user can use the product, and afterwards can fill out their details to create an account, then you could say it &lt;strong&gt;is&lt;/strong&gt; part of the user journey. Still, it sounds more like a feature than a step within our Goal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So to summarize&lt;/strong&gt;: we define all the steps the user will take to get to the desired 'result' and write them down. This will be your User Journey, and the base for the next step.&lt;/p&gt;

&lt;h2&gt;
  
  
  Features per page
&lt;/h2&gt;

&lt;p&gt;If we think of the steps in our User Journey as pages in our webservice, we can then think of features (or pieces of functionality) each page could have. Let's see what we can come up with.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter the domain&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should be able to add domain with or without http(s):// and or www&lt;/li&gt;
&lt;li&gt;Form should have validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;See list of pages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page should show the google pagespeed score for mobile&lt;/li&gt;
&lt;li&gt;Page should show the google pagespeed score for desktop&lt;/li&gt;
&lt;li&gt;Page should show the url and title&lt;/li&gt;
&lt;li&gt;Pages that are 404 should be marked as such&lt;/li&gt;
&lt;li&gt;Pages should be updated in real time as they are crawled&lt;/li&gt;
&lt;li&gt;Scores should be updated in realtime&lt;/li&gt;
&lt;li&gt;Page should show a screenshot&lt;/li&gt;
&lt;li&gt;Should be able to re-check a page for fresh Pagescore&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;See instructions on how to increase the pagespeed score per page&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should see a list of things that should be fixed&lt;/li&gt;
&lt;li&gt;Should see how many points we gain for fixing an issue&lt;/li&gt;
&lt;li&gt;Should be able to re-check a page for fresh Pagescore&lt;/li&gt;
&lt;li&gt;Should see a screenshot&lt;/li&gt;
&lt;li&gt;Show a visual HAR graph of page loading time&lt;/li&gt;
&lt;li&gt;Offer download of optimized assets&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At this point we have a bunch of features, and have to start prioritizing. Basically, for every feature, no matter how cool it sounds, we have to ask ourselves these four questions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1: Is this feature directly related to solving the original Goal?&lt;/strong&gt;&lt;br&gt;
For the MVP we should really focus on features that solve the original problem. We can always add more features later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2: How many users will use this feature&lt;/strong&gt;&lt;br&gt;
If a feature is only useful or interestig to a very specific user or usecase its overall usefulness is very low and we probably should not be building it at this stage.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3: How much work is building this feature&lt;/strong&gt;&lt;br&gt;
If a feature is a lot of work you have to consider if it's worth building it straight away. Maybe there's an easier way which isn't ideal, but increases your 'product to market' significantly. You can always add the ideal feature later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4: Does it add enough value to the User Experience&lt;/strong&gt;&lt;br&gt;
Some features don't really relate to solving a problem but might be worth building after all. For instance, in our case we know the user will have to wait for both the crawling of the site and the pagespeed checks. Implementing 'real time updates' might be a good feature for the MVP in this case. But always consider question 3.&lt;/p&gt;

&lt;p&gt;This doesn't mean you should throw all other features out of the window though! You should put them on your &lt;strong&gt;Roadmap&lt;/strong&gt; so you can come back to them later. The focus for now is finding those features that are essential to our goal so we can &lt;strong&gt;launch&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If we look at our list above, the most 'feature fluff' is in the last step. Which makes sense, as that's where we display the end result of our page score results. The list of things we can offer the user there is potentially huge, so we have to make sure for our MVP we focus on what's most important for now.&lt;/p&gt;

&lt;p&gt;I think the final MVP list for Wulfdeck features could look like this:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enter the domain&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Form should have validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;See list of pages&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Page should show the google pagespeed score for mobile and desktop&lt;/li&gt;
&lt;li&gt;Page should show the url and title&lt;/li&gt;
&lt;li&gt;Scores should be updated in realtime&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;See instructions on how to increase the pagespeed score per page&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Should see a list of things that should be fixed&lt;/li&gt;
&lt;li&gt;Should see how many points we gain for fixing an issue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It definately feels weird to cut out all the extra features, and you might feel the app is not complete without them. However, don't forget we're building a Minimal Viable Product. We're focussing on getting something out there so real world users can play with the core and essentials. The sooner we can learn from our application &lt;code&gt;out in the wild&lt;/code&gt; the better. Often you will find the features you added to the roadmap are not even the features your users are asking for. Good thing you didn't invest your time in building things people don't want! ðŸ˜‰&lt;/p&gt;

&lt;h2&gt;
  
  
  Feature creep
&lt;/h2&gt;

&lt;p&gt;Having defined the MVP the most important next step is; &lt;strong&gt;AVOID FEATURE CREEP&lt;/strong&gt;. As you're building your MVP it is not uncommon you think of a &lt;strong&gt;new&lt;/strong&gt; exciting features for your application. This is a good thing, but also very dangerous. If you didn't think of it while defining the above list, it's most likely not that important, and can safely be added to the Roadmap.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rounding up
&lt;/h2&gt;

&lt;p&gt;( I originally posted this on &lt;a href="https://mindthecode.com"&gt;https://mindthecode.com&lt;/a&gt; )&lt;br&gt;
If you have any questions or would like to discuss, you can find me on Twitter at &lt;a href="https://twitter.com/hyra"&gt;https://twitter.com/hyra&lt;/a&gt; :)&lt;/p&gt;

</description>
      <category>mvp</category>
      <category>startup</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>The best boilerplate app is the one you code yourself</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Wed, 08 Nov 2017 16:39:56 +0000</pubDate>
      <link>https://forem.com/hyra/the-best-boilerplate-app-is-the-one-you-code-yourself-8if</link>
      <guid>https://forem.com/hyra/the-best-boilerplate-app-is-the-one-you-code-yourself-8if</guid>
      <description>&lt;p&gt;Boilerplate apps are great. They let you get your next project up and running quickly, and usually provide some form of structure you can follow.&lt;/p&gt;

&lt;p&gt;They can also, however, be a massive &lt;strong&gt;time-sink&lt;/strong&gt;. We developers are curious by nature, and tend to have this thing where we want to know exactly how things run under the hood 🙈 In addition, boilerplates can be too minimalistic for your needs, or too much bloat. This means you either spend time adding base-features, or scraping off the excess things you don't need.&lt;/p&gt;

&lt;p&gt;This process is not a bad thing in itself, obviously, but it can easily lead to procrastination. Time you could probably better spend building that awesome feature, instead!&lt;/p&gt;

&lt;h2&gt;
  
  
  Should we use boilerplates?
&lt;/h2&gt;

&lt;p&gt;YES! I'm not saying we shouldn't use boilerplates. Quite the opposite, actually. Building a project from scratch will most always be far more time consuming than using a boilerplate. The trick is using the &lt;strong&gt;right&lt;/strong&gt; boilerplate for your project. I really believe the boilerplate you should be using is the one you code yourself. Creating your own boilerplate not only teaches you a &lt;strong&gt;ton&lt;/strong&gt; about the technology you are using, it also leaves you with a piece of base-code you know inside out and can use to start working on that next project.&lt;/p&gt;

&lt;p&gt;Of course you don't have to start from scratch with this. You can pick any existing boilerplate that almost works for you, and then customize it so it works perfectly for you. Or your team.&lt;/p&gt;

&lt;h2&gt;
  
  
  But not all projects are the same!
&lt;/h2&gt;

&lt;p&gt;Agreed. Even more so, not every &lt;em&gt;environment&lt;/em&gt; is the same. Or project team, for that matter. For instance, you might use a completely different stack when you are working on your pet side-projects than what you use at the office. Personally, I work with about 4 boilerplate apps, depending on the project, the people I work with and sometimes the constraints set by the client. For example, I have boilerplates for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a Single Page VueJS App&lt;/li&gt;
&lt;li&gt;an API only Express application&lt;/li&gt;
&lt;li&gt;a Static Site Generator (Hexo) for blogs&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The idea is that you standardize as much as possible, but don't constrain yourself too much. Sure, every project and situation is different, but starting every project from a  &lt;strong&gt;base&lt;/strong&gt; you are very familiar with makes sure you can get up and running quickly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Keeping up to date
&lt;/h2&gt;

&lt;p&gt;Ideally, you should keep your boilerplate apps up to date. Make sure to check your dependencies are up to date every now and then, check if it still works, and see if there's any upgrades you should be aware of. Over time you will know exactly what works, and what doesn't, so when that new library comes along you know exactly where to fit it in. But, &lt;strong&gt;don't do this religously&lt;/strong&gt;, else we end up tinkering on Boilerplate apps rather than projects that will let you take over the world &lt;/p&gt;

&lt;p&gt;It's all about that fine balance 🦄 ✨&lt;/p&gt;

&lt;p&gt;As always, find my on &lt;a href="https://twitter.com/hyra"&gt;@hyra&lt;/a&gt; at Twitter if you want to discuss!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Using Vue Components in your Express app</title>
      <dc:creator>Stef van den Ham</dc:creator>
      <pubDate>Sun, 22 Oct 2017 11:53:24 +0000</pubDate>
      <link>https://forem.com/hyra/using-vue-components-in-your-express-app-d15</link>
      <guid>https://forem.com/hyra/using-vue-components-in-your-express-app-d15</guid>
      <description>&lt;p&gt;VueJS is awesome. Creating self contained components and compose them together in your pages makes so much sense, and therefore I've been using it extensively in my latest projects. However, sometimes you want (or need) to create a traditional app, and can't use the SPA workflow development with hot reloading and .vue files.&lt;/p&gt;

&lt;p&gt;Or can you? ðŸ¤” &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TL;DR: I've prepared a repo with the full example code in case you want to dive right in at &lt;a href="https://github.com/Hyra/vue-components-in-express"&gt;Github&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Laravel already got Vue tightly integrated out-of-the-box, and you can actually register and use &lt;code&gt;.vue&lt;/code&gt; components in your &lt;code&gt;blade&lt;/code&gt; templates relatively easy. My weapon of choice is usually Express though, as I'm a Javascript fanboy ðŸ¤“. I set out to see if this is possible and spent 2 evenings trying to get the same working. With success! Below the steps to get this up and running for your next Express app as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Defining some goals
&lt;/h2&gt;

&lt;p&gt;Before setting out to come up with a solution I had to define the goals I had in mind. I came up with the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be able to write components using the &lt;code&gt;.vue&lt;/code&gt;  approach&lt;/strong&gt;&lt;br&gt;
Surely it's possible to write lengthy javascript and define components in one big file, but I want to use the .vue approach where &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; are combined in one file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use the components by puttin &lt;code&gt;&amp;lt;custom-tag&amp;gt;&lt;/code&gt; in my view files&lt;/strong&gt;&lt;br&gt;
Registering and compiling is one thing, but being able to use them is another. I don't want to have to use Vue code to render the components explicity&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ability to use a pre-processor&lt;/strong&gt;&lt;br&gt;
I like writing my styles in the &lt;code&gt;scss&lt;/code&gt; format, so this should be supported.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;A simple build tool to compile&lt;/strong&gt;&lt;br&gt;
When developing SPA projects the build tools get rather verbose and complex. For the projects I want to use components in the build tool should be simple.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bonus Feature: Hot Reloading&lt;/strong&gt;&lt;br&gt;
Spoiler alert: I didn't set out to have this as a requirement, but it works, and it's awesome.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting the stage
&lt;/h2&gt;

&lt;p&gt;So let's get started. Obviously we will need a starting point. The easiest way to start a new Express app is by using its generator. Basically this will create an empty project that you can build off from. If you don't have it yet, here is how you get it installed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;express-generator &lt;span class="nt"&gt;-g&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next we run the generator to create our project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;express &lt;span class="nt"&gt;--view&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;pug myapp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I use &lt;code&gt;pug&lt;/code&gt; because I like the clean syntax. Though I know plenty people who hate it, so if you are one of them, just omit the &lt;code&gt;--view&lt;/code&gt; parameter ðŸ˜‰&lt;/p&gt;

&lt;p&gt;The generator will have created a folder &lt;code&gt;myapp&lt;/code&gt; with an app which is pretty much ready to go, just go:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;myapp
yarn &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="c"&gt;# or npm&lt;/span&gt;
yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will just install the dependencies and start the Express webserver. If all went well, browsing to &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; should give you the Welcome page of your new app.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding Vue
&lt;/h2&gt;

&lt;p&gt;With the base set up, it's about time we add some Vue to the project. Let's pull in the Vue dependency first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add vue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we need to create our entry Javascript file. We will eventually bundle all the referenced javascript code into one file, so this will be our main file. I created a file in &lt;code&gt;public/javascripts/main.js&lt;/code&gt;. In there put 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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue/dist/vue.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice we pull in &lt;code&gt;vue/dist/vue.js&lt;/code&gt; rather than just &lt;code&gt;vue&lt;/code&gt;. This is because by default Vue includes the runtime-only build, which means we can't use templates like we want in .vue files.&lt;/p&gt;

&lt;p&gt;We also mount our Vue app to an element with id &lt;code&gt;app&lt;/code&gt;, so change the &lt;code&gt;views/layout.pug&lt;/code&gt; to include that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;doctype html
html
&lt;/span&gt;  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
&lt;span class="gi"&gt;+   #app
&lt;/span&gt;      block content
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a build script
&lt;/h2&gt;

&lt;p&gt;Now, to use our javascript we will need to bundle it and include it in our template. My usual choice is webpack, but configuring this is quite cumbersome and to be completely honest, I couldn't get it to work. For some reason it would incude the default vue version meaning we can't use .vue files, one of the main goals.&lt;/p&gt;

&lt;p&gt;Luckily, there is a nice tool called &lt;a href="https://github.com/vuejs/vueify"&gt;Vueify&lt;/a&gt; which we can use to compile our javascript. As a bonus, it supports pre-processors such as SASS, Styuls and even template languages such as Pug. Win. It's a transform for Browserify, so we will need both.&lt;/p&gt;

&lt;p&gt;Installing is simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn global add browserify &lt;span class="c"&gt;# We want this global, to run is easily&lt;/span&gt;
yarn add vueify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can do the compiling:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;browserify &lt;span class="nt"&gt;-t&lt;/span&gt; vueify &lt;span class="nt"&gt;-e&lt;/span&gt; public/javascripts/main.js &lt;span class="nt"&gt;-o&lt;/span&gt; public/javascripts/bundle.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will, unsurprisingly, create a new file &lt;code&gt;bundle.js&lt;/code&gt; with the compiled code. Let's not forget to include it in our layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;doctype html
html
&lt;/span&gt;  head
    title= title
    link(rel='stylesheet', href='/stylesheets/style.css')
  body
    #app
      block content
&lt;span class="gi"&gt;+   script(src="/javascripts/bundle.js")
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Writing a component
&lt;/h2&gt;

&lt;p&gt;Next up is the part we've been waiting for .. an actual component! Let's add a file &lt;code&gt;public/javascripts/components/cruelWorld.vue&lt;/code&gt;&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cruel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Cruel&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;who&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// This is important, I got errors when using `export default`&lt;/span&gt;
    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;who&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;mounted&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;We can use ES6 too!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cruel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is your basic Vue component. We have a simple template and some data, and it's mounted we log out a message after 1 second to show Arrow functions work as well.&lt;/p&gt;

&lt;p&gt;Let's add it to our &lt;code&gt;main.js&lt;/code&gt; so we can use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue/dist/vue.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;cruelWorld&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/cruelWorld.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;el&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And compile it by running the command again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;browserify &lt;span class="nt"&gt;-t&lt;/span&gt; vueify &lt;span class="nt"&gt;-e&lt;/span&gt; public/javascripts/main.js &lt;span class="nt"&gt;-o&lt;/span&gt; public/javascripts/bundle.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Include the component
&lt;/h2&gt;

&lt;p&gt;Nice. So we got our setup, we got our component. Now let's use it. Open up &lt;code&gt;views/index.pug&lt;/code&gt; and add the component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="p"&gt;extends layout
&lt;/span&gt;
block content
  h1= title
&lt;span class="gi"&gt;+ cruel-world
&lt;/span&gt;  p Welcome to #{title}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start the webserver:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If all went well, you should be seeing our component alive and kicking!&lt;/p&gt;

&lt;p&gt;Now, we can use pre-processors as well. For instance, we can add &lt;code&gt;lang="scss"&lt;/code&gt; to our &lt;code&gt;&amp;lt;style&amp;gt;&lt;/code&gt; tag to use SASS syntax:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cruel&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Cruel&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;who&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;script&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="na"&gt;who&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="nx"&gt;mounted&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;We can use ES6 too!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/script&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt; &lt;span class="nx"&gt;scoped&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scss&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="nx"&gt;attribute&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cruel&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c"&gt;&amp;lt;!--&lt;/span&gt; &lt;span class="nx"&gt;nested&lt;/span&gt; &lt;span class="nx"&gt;scss&lt;/span&gt; &lt;span class="nx"&gt;syntax&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="o"&gt;--&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;orange&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/style&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before compiling this, we need to quickly add &lt;code&gt;node-sass&lt;/code&gt; as dependency:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add node-sass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, when you compile and run, you should see the SASS is being compiled correclty and your component has become more colourful.&lt;/p&gt;

&lt;p&gt;This is great. We can write .vue components and then use them in our traditional app. We could stop here, but let's add one more feature .. &lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Hot Reloading
&lt;/h2&gt;

&lt;p&gt;This is just the icing on the cake. Being able to update our components and see the results straight away in our browser.&lt;/p&gt;

&lt;p&gt;Open up your &lt;code&gt;package.json&lt;/code&gt; and add the following &lt;strong&gt;dev&lt;/strong&gt; script to the &lt;code&gt;scripts&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node ./bin/www"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"dev"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"watchify -vd -p browserify-hmr -t vueify -e public/javascripts/main.js -o public/javascripts/bundle.js &amp;amp; node ./bin/www"&lt;/span&gt;&lt;span class="w"&gt; 
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This script looks daunting but is quite simple. Basically it uses &lt;strong&gt;watchify&lt;/strong&gt; to watch for code changes, and proxies the result of &lt;strong&gt;vueify&lt;/strong&gt; through browserify-hmr (hot module reloading) to our page. Awesome.&lt;/p&gt;

&lt;p&gt;Don't forget to install the dependencies this relies on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn add watchify
yarn add browserify-hmr
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now when you start the server ..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;yarn dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will compile our javascript and watch for changes. Try it out, make a change to &lt;code&gt;cruelWorld.vue&lt;/code&gt; and see the change automagically in the browser!&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I'm glad I could get this working. Sometimes it doesn't make sense to go all out with a single page app. Having the ability to still use the Vue Components in your traditional project is just gold.&lt;/p&gt;

&lt;p&gt;If you want to see the full source code of the above, I've prepared a repository at &lt;a href="https://github.com/Hyra/vue-components-in-express"&gt;Github&lt;/a&gt; which you can use as a reference or starting point.&lt;/p&gt;

&lt;p&gt;Hope the above helps!&lt;/p&gt;

&lt;p&gt;If you have any questions, you can find me on &lt;a href="https://twitter.com/hyra"&gt;https://twitter.com/hyra&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>express</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
