<rss
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:admin="http://webns.net/mvcb/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
version="2.0">

  <channel>

    <title>Recent &amp; Good Blog Posts on CodePen</title>

    <link>http://codepen.io/posts/</link>

    <description/>

    <dc:language>en</dc:language>

    <dc:creator>nospam@codepen.io</dc:creator>

    <dc:rights>Copyright 2016</dc:rights>

    <dc:date>
      2016-12-01T18:47:23-07:00
    </dc:date>

      <item>

  <title>How Style Scoping Works with Element Queries</title>

  <link>//codepen.io/tomhodgins/post/how-style-scoping-works-with-element-queries</link>
  <guid>//codepen.io/tomhodgins/post/how-style-scoping-works-with-element-queries</guid>

  <dc:creator>Tommy Hodgins</dc:creator>

  <description>
    <![CDATA[
    <p>One of the CSS concepts I've been experimenting with for the past couple of years is the idea of 'style scoping'. There have been a number of different proposals for the way this might work, and early support even crept into Firefox at one point, but as far as I know all development for supporting style scoping has been stopped now. So what is style scoping, how can we use it, and what is it good for?</p>

<p>Style scoping is the idea that you can select an element anywhere in your document to serve as a point of reference as you write styles. Originally the idea was for containment purposes, but with scoped styles and the addition of any kind of responsive query you suddenly have a very powerful new way to build responsive layouts!</p>

<p>You might describe "element queries" as "scoped styles with a responsive condition".</p>

<h2>How can we use Style Scoping</h2>

<p>Currently there isn't enough browser support (or even an approved spec) for style scoping using CSS alone, so most approaches involve either a build step (preprocessing your CSS) or use a JavaScript plugin. The plugin I use to do this is <a href="http://elementqueries.com">EQCSS</a>.</p>

<p>If you think of a web page, everything in your document is a child of the HTML element. When you write media queries to add responsive styles, it always applies to the entire document:</p>

<pre>
  <code>@media (min-width: 500) {
  body {
    background: lime;
  }
}
</code>
</pre>

<p>This means:</p>

<blockquote>
<p>When the HTML element is at least <code>500px</code> wide, make the <code>body</code> element lime.</p>
</blockquote>

<p>This is functionally equivalent to the following element query:</p>

<pre>
  <code>@element 'html' and (min-width: 500px) {
  body {
    background: lime;
  }
}
</code>
</pre>

<p>This could be interpreted the same way:</p>

<blockquote>
<p>When the <code>html</code> element is at least <code>500px</code> wide, make the <code>body</code> element lime.</p>
</blockquote>

<p>In our second example, the element query, we could refer to <code>html</code> as our “scoped element”, or the element that is in the “scope”. The fun part about scoped styles is that you are able to scope styles to <em>any</em> element in your document this way!</p>

<p>How would we describe this kind of a query:</p>

<pre>
  <code>@element '#sidebar' and (min-width: 500px) {
  body {
    background: lime;
  }
}
</code>
</pre>

<blockquote>
<p>When the <code>#sidebar</code> element is at least <code>500px</code> wide, make the <code>body</code> element lime</p>
</blockquote>

<p>This is amazing! But let's suppose for a second that instead of having one <code>#sidebar</code> on the page we have many <code>.widget</code> elements - how could we write a style for them?</p>

<pre>
  <code>@element '.widget' and (min-width: 200px) {
  .widget h2 {
    font-size: 20pt;
  }
}
</code>
</pre>

<blockquote>
<p>When <em>any</em> element with a class of <code>.widget</code> on the page is at least <code>200px</code> wide, make <em>any</em> <code>h2</code> inside any <code>.widget</code> on the page <code>20pt</code></p>
</blockquote>

<p>The problem with this rule is when you have more than one <code>.widget</code> on the page with different widths. Any time <em>any</em> <code>.widget</code> element meets the condition, it's applying that CSS rule to all <code>.widget h2</code> elements. 🤔 Probably <em>not</em> what we want in most cases!</p>

<p>The solution to this is to use a special selector, <code>$this</code>, which only works in EQCSS inside of a scoped style. Anywhere <code>$this</code> is present inside of a scoped style it refers to only the scoped element. This means a rule like this <em>would</em> work for us:</p>

<pre>
  <code>@element '.widget' and (min-width: 200px) {
  $this h2 {
    font-size: 20pt;
  }
}
</code>
</pre>

<blockquote>
<p>When <em>any</em> element with a class of <code>.widget</code>on the page is at least <code>200px</code> wide, make <em>any</em> <code>h2</code> element inside the <code>.widget</code> element that matches the condition <code>20pt</code></p>
</blockquote>

<p>In most cases this is what we want, but it's nice to be able to set styles on any element in your document from within a scoped style too.</p>

<p>Here's another explanation of hot <code>$this</code> affects styles:</p>

<pre>
  <code>@element 'div' and (min-width: 500px) {
  $this { background: red; }
  /* When any div is &lt;500px, make that div red */

  div { background: lime }
  /* When any div is &lt;500px, make all divs on the page lime */

  $this div { background: gold }
  /* When any div is &lt;500px, make all divs inside the scope gold */
}
</code>
</pre>

<h2>What is Style Scoping useful for?</h2>

<p>There are many potential uses for style scoping, so I'll just list the ones that have proven the most useful to me over the past two years:</p>

<h3>Style scoping makes it easy to 'quarantine' your styles</h3>

<p>When building modules, embeddable widgets, or adding new code to old sites it can be nice to have the peace of mind knowing that 100% of the new styles you are adding to the website are contained within the scope of the element they apply to, and <em>will not</em> be applying to anything else on the page.</p>

<h3>Selectively quarantining your styles</h3>

<p>Tools that build things like HTML5 animations sometimes have a feature where they can either allow your animation to inherit styles on the page, or be 100% self-contained. With style scoping you have total control over how permeable you want your styles to be. A style like this would allow its children to inherit styles from the page it's embedded on:</p>

<pre>
  <code>@element '#animation' {}
</code>
</pre>

<p>And if we wanted to ensure that nothing from the page gets inherited, we could do something like this (or include any <a href="http://meyerweb.com/eric/tools/css/reset/">CSS reset</a>):</p>

<pre>
  <code>@element '#animation' {
  $this,
  $this *,
  $this :before,
  $this :after {
    all: initial !important;
  }
}
</code>
</pre>

<p>This would reset (in most browsers) all styles for the scoped element and all of the elements it contains, ensuring that only our styles inside the scoped style apply to its element. In the past without style scoping, we used to isolate animations, widgets, and embed inside <code>iframe</code> elements, but this cut them off entirely from the pages they were displayed in, sometimes had cross-origin issues, and it wasn't possible for the embedded content and the page to interact.</p>

<p>Now with style scoping we can have the same styling flexibility as embeds in an <code>iframe</code> with better interactivity with the pages it's embedded on.</p>

<h3>Writing Element Queries</h3>

<p>When you add responsive conditions to scoped styles you can build responsive websites without using <code>@media</code> queries. This is something that has proven really useful for building layouts as self-responsive modules that all fit into a basic page layout. These modules can be displayed in all kinds of different websites, with all sorts of different visual styles and branding, and you never have to fiddle with <code>@media</code> query breakpoints when moving the modules around from layout to layout since they are based on the properties of the elements themselves, not based on the dimensions or properties of the browser and viewport.</p>

<p>Some of the responsive conditions you can add to scoped styles in EQCSS include: <code>min-height</code>, <code>max-height</code>, <code>min-width</code>, <code>max-width</code>, <code>min-characters</code>, <code>max-characters</code>, <code>min-lines</code>, <code>max-lines</code>, <code>min-children</code>, <code>max-children</code>, <code>min-scroll-y</code>, <code>max-scroll-y</code>, <code>min-scroll-x</code>, <code>max-scroll-x</code>, <code>orientation</code>, <code>min-aspect-ratio</code>, <code>max-aspect-ratio</code> which make this sort of responsive styling a <em>lot</em> more flexible than what <code>@media</code> queries can do.</p>

<h2>Conclusion</h2>

<p>If you haven't experimented with style scoping yet, it's a very exciting concept and usable today in all browsers via JS plugins. Here are a few demos from Codepen that are made possible by style scoping. View them, fork them, play around with them, use them, and enjoy!</p>

<ul>
<li><p><strong>Nested Element Queries:</strong>
<p data-slug-hash="beeQON" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p></li>
<li><p><strong>Order form with Element Queries:</strong>
<p data-slug-hash="yOjrzx" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p></li>
<li><p><strong>Testimonials block:</strong>
<p data-slug-hash="vOqaVa" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p></li>
<li><p><strong>Responsive Table Layouts:</strong>
<p data-slug-hash="akrRqX" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p></li>
<li><p><strong>Element Query Layout Demo:</strong>
<p data-slug-hash="eJJqoz" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p></li>
</ul>

<p>Happy Hacking!</p>

    ]]>
  </description>

  <dc:subject>How Style Scoping Works with Element Queries</dc:subject>

  <dc:date>
    2016-12-01T18:47:23-07:00
  </dc:date>

</item>
      <item>

  <title>Learning to multiply using 2 and 10.</title>

  <link>//codepen.io/pixelass/post/learning-to-multiply-using-2-and-10</link>
  <guid>//codepen.io/pixelass/post/learning-to-multiply-using-2-and-10</guid>

  <dc:creator>Gregor Adams</dc:creator>

  <description>
    <![CDATA[
    <h2>A few tricks and ideas how anybody can improve in mental arithmetic.</h2>

<p>Some people have difficulties multiplying or dividing numbers. Others find it hard to add or subtract. Doing simple math without a calculator or a pen and paper can become very difficult. I want to show some small tricks that will help your brain understand simple math. I am writing this for fun, there is no study or any proof behind this. It's just what my brain does on a daily basis. Some tricks were taught at school, others were not accepted there and often caused me to fail because they were too fast or different. Due to that fact I never really liked math. I am also not really good at math, which might or might not be related to this disappointment. Most of the things I know today are self taught, math is just an example.</p>

<h3>Let's take a look at some simple algebra.</h3>

<pre>
  <code class="js">a * 9 = b
2 * 9 = 18
</code>
</pre>

<p>This multiplication might seem very easy to a lot of people but for others there is no logic and therefore they will have problems solving this example. While <code>2 * 9</code>  might be easy to calculate beacuse it is no different than <code>9 + 9</code> , higher numbers might become more difficult to solve.</p>

<p>There are several helpers we can use to "cheat" by using a different method. Everybody will develop their own method based on those that seem easier.<br />
The easiest multiplication is <code>n * 1</code>, beacuse it is the same as <code>n</code>.<br />
Ranked 2nd is <code>n * 10</code>, because we simply need to add a <code>0</code> to the end.<br />
Since the difference from <code>9</code> and <code>10</code> is <code>1</code>, we can simply multiply by <code>10</code> and then subtract <code>n</code>, instead of the more complicated original task.</p>

<pre>
  <code class="js">n * 9 = n * 10 - n 
/* Examples */
1 * 9 = 1 * 10 - 1 = 10 - 1 =  9
2 * 9 = 2 * 10 - 2 = 20 - 2 = 18
...
5 * 9 = 5 * 10 - 5 = 50 - 5 = 45
...
8 * 9 = 8 * 10 - 8 = 80 - 8 = 72
9 * 9 = 9 * 10 - 9 = 90 - 9 = 81

3 * 9 
= 3 * 10 - 3 
= 30 - 3 
= 27
</code>
</pre>

<p>This method will help anybody that has problems with multiplication, at least for any number up to 10. Higher numbers get more complicated.</p>

<pre>
  <code class="js">2834 * 9
= 2834 * 10 - 2834
= 28340 - 2834
</code>
</pre>

<p>I am not going to solve this task right now since it's purpose is to show that things can get complicated. People that are fast at subtracting have a huge advantage here. Let's solve this using a method that focuses on the <code>10</code>.</p>

<pre>
  <code class="js">2834 * 9
= 2834 * 10 - 2834
= 2000 * 10 - 2000
+  800 * 10 -  800
+   30 * 10 -   30
+    4 * 10 -    4
= 20000 - 2000
+  8000 -  800
+   300 -   30
+    40 -    4
= 18000 
+  7200 
+   270 
+    36
= 25506
</code>
</pre>

<p>While this works for some people, others will have problems adding 4 numbers, even though those were easy to solve. I am pretty sure that a lot of people will have learned something similar in school. In Germany a common calculation is <code>n * 1.19</code>, because <code>19%</code> is the tax rate in Germany. So let's remember what we just looked at and then get back to our task.</p>

<pre>
  <code class="js">n * 1.19
= n * 1
+ n * 0.1
+ n * 0.09
= n 
+ n / 10
+ (n * 10 - n) / 100
</code>
</pre>

<pre>
  <code class="js">8 * 1.19

= 8 * 1
+ 8 * 0.1
+ 8 * 0.09

= 8 
+ 8 / 10
+ (8 * 10 - 8) / 100 

= 8
+ 0.8
+ (80 - 8) / 100

= 8.8
+ 72 / 100

= 8.8
+ 0.72

= 9.52
</code>
</pre>

<p>As you can see I only solved one step per line. There are several reasons to do this especially while training or learning.</p>

<ul>
<li>  allow the brain to remember the steps</li>
<li>  reduce risks of wrong solutions</li>
</ul>

<p>The further you break down a task the easier the each step gets but you will have to add more numbers at the end. At least we now know, that we can use <code>10</code>, to help us multiply by numbers that consist of the digits <code>0</code>, <code>1</code> or <code>9</code>.<br />
So what about other numbers like <code>7</code> or <code>8</code>? Solving <code>n * 8</code> is fairly simply and not much different than <code>n * 9</code>.</p>

<pre>
  <code class="js">n * 8 = n * 10 - n * 2
7 * 8 
= 7 * 10 - 7 * 2
= 70 - (7 + 7)
= 70 - 14
= 70 - 10 - 4
= 60 - 4
= 56
</code>
</pre>

<p>Here we can make use of the trick <code>n * 2 = n + n</code> It does get a little harder since we might have to subtract a two digit number from another two digit number but at least the higher number is divisable by <code>10</code>. To get around the more complicated subtraction I simply broke it down into easier steps. But there are more methods to solve this. As mentioned before, different people prefer different methods and as long as the answer is correct everything is acceptable. Sadly this was something my teachers did not like and I often got 0 points for correct solutions because the method was not what we learned in school.</p>

<pre>
  <code class="js">7 * 8 
= 7 * 10 - 7 * 2
= 70 - 7 - 7
= 63 - 7
= 63 - 13 + 13 - 7
= 50 + 6
= 56 
</code>
</pre>

<pre>
  <code class="js">7 * 8 
= (7 - 5) * 8 + 5 * 8
= 2 * 8 + 5 * 10 - 5 * 2
= 8 + 8 + 50 - 10
= 16 + 40
= 56
</code>
</pre>

<pre>
  <code class="js">7 * 8 
= 7 * 9 - 7
= 7 * 10 - (7 + 7)
= 70 - 14
= 70 - 10 - 4
= 60 - 4
= 56
</code>
</pre>

<p>As you can see there are many ways to solve this problem and it really depends on the way your brain works, when it comes to math. Having learned the trick about <code>9</code> and <code>10</code> helps a lot along the way and will train our brain into using these numbers whenever we see a number close to them. Let's get back to the problem of solving <code>a * 7 = b</code>. We can look at the methods we have used above but will soon realize that we are just starting to turn a lot of steps into additions or subtractions.</p>

<pre>
  <code class="js">n * 7 
= n * 8 - 7 
= n * 9 - 7 - 7 
= n * 10 - 7 - 7 - 7
= n * 10 - 7 * 3
</code>
</pre>

<p>None of the above solutions make me happy or allow some kind of logic to form. It just seems overly complicated and time consuming. Since <code>7</code> is actually closer to <code>5</code>, than <code>10</code>, let's take a look at how easy it is to solve <code>n * 5</code></p>

<pre>
  <code class="js">a * 5 = b

6 * 5 
= 6 * 10 / 2
= 60 / 2
= 30
</code>
</pre>

<p>My brain immediately used <code>10</code> and <code>2</code>, since I learned the advantages of using these numbers. Your brain might work different and find a better solution for <code>n * 5</code> but let's get back to our problem.</p>

<pre>
  <code class="js">6 * 7
= 6 * 2 + 6 * 5
= 6 + 6 + 6 * 10 / 2
= 12 + 60 / 2
= 12 + 30
= 42
</code>
</pre>

<p>I think that worked out pretty nicely. We used the same methods as before, by breaking everything down, so we can use <code>10</code> and <code>2</code>. The rest of the numbers should get easier since we already covered the highest numbers. I personally have some difficulties multiplying by <code>3</code>, because my brain automatically wants to add the same number three times. The reason for that is, that it seems a lot easier than breaking the task down into smaller steps. If we train our brain to do really fast math using <code>2</code> and <code>10</code>, then this is false, because our brain will learn to automate this and simply provide an answer.</p>

<pre>
  <code class="js">n * 3 
= n + n + n
= n * 5 - n * 2
= n * 10 / 2 - (n + n)
</code>
</pre>

<pre>
  <code class="js">6 * 3
= 6 * 5 - 6 * 2
= 6 * 10 / 2 - (6 + 6)
= 60 / 2 - 12
= 30 - 10 - 2
= 20 - 2
= 18
</code>
</pre>

<p>Remember this is just one example of cheating to solve this task. Another one would be to turn the numbers around and see if that makes more sense. In my case it does, since my brain is pretty fast at multiplying by <code>5</code> and an addition at the end is really simple.</p>

<pre>
  <code class="js">6 * 3
= 3 * 6
= 3 * 5 + 3
= 3 * 10 / 2 + 3
= 30 / 2 + 3
= 15 + 3
= 18
</code>
</pre>

<p>This is something you should always do where you see fit. I tend to multiply by bigger single-digit numbers and add or subtract smaller numbers but this is just the way it works for me.</p>

<pre>
  <code class="js">9 * 3 
= 3 * 9 
= 3 * 10 - 3
= 30 - 3
= 27
</code>
</pre>

<pre>
  <code class="js">7 * 4 
= 4 * 7
= 4 * 5 + 4 * 2 
= 4 * 10 / 2 + 4 + 4
= 40 / 2 + 8
= 20 + 8
= 28
</code>
</pre>

<pre>
  <code class="js">21 * 83
= 83 * 21
= 80 * 20 + 80 + 3 * 20 + 3
= 8 * 10 * 2 * 10 + 80 + 3 * 2 * 10 + 3
= 8 * 2 * 10 * 10 + 80 + (3 + 3) * 10 + 3
= (8 + 8) * 100 + 80 + 6 * 10 + 3

= 16 * 100 
+ 80 
+ 60
+ 3

= 1600 
+   80 
+   60 
+    3
= 1743
</code>
</pre>

<p>Sometimes solutions are very similar but use a completely different pattern. This is where our methods will differ. While one person will use example 1, somebody else might find this way too complicated and just solve the task with less steps as seen in example 2.</p>

<pre>
  <code class="js">9 * 5
= 5 * 9
= 5 * 10 - 5
= 50 - 5
= 45
</code>
</pre>

<pre>
  <code class="js">9 * 5
= 9 * 10 / 2
= 90 / 2
= 45
</code>
</pre>

<h3>Conclusion</h3>

<p>Math is about logic. The more we train our brains to use helpers like the examples above, the faster it will be able to process tasks without the use of a calculator pen and paper.  </p>

<p>Smaller steps are easier to understand and or brain will automate these processes over time.<br />
Using the numbers <code>2</code> and <code>10</code> allows us to create a pattern and therefore see a logic in numbers that made no sense before.  </p>

<p>Often talents are not discovered because we are too focused on "the right way", some will still rise but we are wasting a lot of amazing ideas by not accepting or respecting what others have tried.</p>

<p>This could be your first step into getting the hang of math and making a good impression the next time you invite someone to a burrito and lemonade from that van around the corner.</p>

<p>I hope you enjoy this article and maybe this even encourages you to do more mental arithmetic. If you are interested in thinking patterns you should search for <a href="https://www.ted.com/talks/daniel_tammet_different_ways_of_knowing">"Daniel Tammet"</a> who explains how his brain recognizes numbers as unique shapes allowing him to multiply large numbers in a few seconds and therefore faster than typing it into a calculator. He also applies similar patterns to learning languages. A true genius and someone to learn from and listen to.</p>

<p>
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/28359/daniel_tammet_numbers.png" alt="daniel tammet sees numbers as shapes" />
</p>

<blockquote>
<p>When I started writing this article I was fully unaware of the power the numbers <code>2</code> and <code>10</code> have when multiplying. This is something I just realized, while writing this article, even though my brain has been doing it for a long time. </p>
</blockquote>

    ]]>
  </description>

  <dc:subject>Learning to multiply using 2 and 10.</dc:subject>

  <dc:date>
    2016-11-30T13:41:51-07:00
  </dc:date>

</item>
      <item>

  <title>The Wave</title>

  <link>//codepen.io/chriscoyier/post/the-wave</link>
  <guid>//codepen.io/chriscoyier/post/the-wave</guid>

  <dc:creator>Chris Coyier </dc:creator>

  <description>
    <![CDATA[
    <p>SVG filters are awesome and can do <a href="https://www.smashingmagazine.com/2015/05/why-the-svg-filter-is-awesome/">all kinds of crazy stuff</a>. The turbelence one, <code>&lt;feTurbulence&gt;</code>, is particularly cool. </p>

<p><a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Element/feTurbulence">The demo on MDN</a> shows how gnarly it can blast out a circle:</p>

<p><p data-slug-hash="ffde55c640a4067d282fdf164c7851f0" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>It's a filter that <em>really looks like movement</em> but it doesn't actually move. I was playing with a demo that used a turbulence filter the other day that was applied to the entire screen, and noticed as I resized the browser window that the elements under that filter were kind of <em>waving</em>. Because, I suppose, the filter was applying to different areas of the element.</p>

<p>I figured we could exploit that idea a little by animating <code>padding</code> and <code>translate</code>, keeping the elements in the same place but ultimately moving the filter. Check it:</p>

<p><p data-slug-hash="eBRRLe" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>Uncomment the last few lines of CSS to sneak a peak into the animation that is happening to make it work. </p>

    ]]>
  </description>

  <dc:subject>The Wave</dc:subject>

  <dc:date>
    2016-11-24T16:14:09-07:00
  </dc:date>

</item>
      <item>

  <title>Layout powered by CSS variables</title>

  <link>//codepen.io/pixelass/post/layout-powered-by-css-variables</link>
  <guid>//codepen.io/pixelass/post/layout-powered-by-css-variables</guid>

  <dc:creator>Gregor Adams</dc:creator>

  <description>
    <![CDATA[
    <h2>CSS frameworks are nice, but...</h2>

<p>Over the years we have worked with different frameworks, to add basic layout or themes to our projects. These so called "boilerplates" are often very detailed and deliver quite some weight.</p>

<p>The goal of a framework is, to speed up the development process, while delivering the best compatibility. The drawback is a big code base. Since frameworks are often modular and allow configuration, the integration can take longer than expected. Extra steps might be required, when you want to customize the framework or only need a small part of it.</p>

<h2>Who uses bootstrap anymore?</h2>

<p>Thankfully, a lot of developers have started writing their own boilerplates. Some are based on popular frameworks, others are written from scratch but they usually have one thing in common. The frameworks deliver static CSS and require a preprocessor, to change attributes.</p>

<p>A simple grid framework might look something like this:</p>

<h4>CSS framework</h4>

<pre>
  <code class="scss">$columns: 12;
$gutter: 12px;
$padding: 10px;

.column {
  flex-basis: calc(100% / #{$columns});
  margin: 0 $gutter;
  padding: 0 $padding;

  @for $i from 2 through 12 {
    &amp;._#{$i} {
      flex-basis: calc(100% / #{$columns * $i});
    }
  }
}

.grid, .row {
  display: flex;
  flex-wrap: wrap;
}

.row {
  margin: 0 ($padding + $gutter) * -2;
}
</code>
</pre>

<h4>Usage</h4>

<pre>
  <code class="html">&lt;div class="grid"&gt;
  &lt;div class="column _4"&gt;&lt;/div&gt;
  &lt;div class="column _4"&gt;&lt;/div&gt;
  &lt;div class="column _2"&gt;&lt;/div&gt;
  &lt;div class="column _2"&gt;&lt;/div&gt;
&lt;/div&gt;
</code>
</pre>

<p>To change any attribute in this framework, we need to compile a new version. Using CSS variables, we don't need this step and can remove a majority of the code.</p>

<p>Let's look at something very similar using CSS variables.</p>

<h4>CSS framework</h4>

<pre>
  <code class="css">:root {
  --columns: 12;
  --gutter: 12;
  --padding: 10;
}

.column {
  --colspan: 1;
  flex-basis: calc(100% / var(--columns) * var(--colspan));
  margin: 0 calc(var(--gutter) * 1px);
  padding: 0 calc(var(--padding) * 1px);
}

.grid, .row {
  display: flex;
  flex-wrap: wrap;
}

.row {
  margin: 0 calc((var(--gutter) + var(--padding)) * -1px);
}
</code>
</pre>

<h4>Usage</h4>

<pre>
  <code class="html">&lt;div class="grid"&gt;
  &lt;div class="column" style="--colspan: 4"&gt;&lt;/div&gt;
  &lt;div class="column" style="--colspan: 4"&gt;&lt;/div&gt;
  &lt;div class="column" style="--colspan: 2"&gt;&lt;/div&gt;
  &lt;div class="column" style="--colspan: 2"&gt;&lt;/div&gt;
&lt;/div&gt;
</code>
</pre>

<p>As you can see I chose to set the <code>colspan</code> as an inline style instead of giving the element a classname. There are three reasons for this choice.</p>

<ol>
<li>inline styles allow a real scope</li>
<li>the cascade will break the grid logic</li>
<li>no cascading (unreliable) classnames (less code)</li>
</ol>

<h2>Writing a lightweight grid framework</h2>

<p>Let's take the code from above and think about improvement. 
Both, the SCSS version and the CSS version produce the same logic but our plain CSS version does not need to be recompiled. We can simply import it and overwrite the <code>:root</code> variables. This is where the cascade comes in handy.</p>

<pre>
  <code class="css">@import "path/to/grid.css";
:root {
  --gutter: 10;
  --padding: 10;
}
</code>
</pre>

<h3>Nesting grids</h3>

<p>The examples above follow a very simple logic.</p>

<ol>
<li><code>.grid</code> provides the outer element</li>
<li><code>.column</code> defines the width of an element relative to its parent</li>
<li><code>.row</code> opens a new grid and resets the gutter and padding.</li>
</ol>

<p>This means, if we have a grid inside a column with a width of <code>4</code>, we are actually allowing our grid to be split into 48 columns. Often this is not what we are aiming for</p>

<p>The code below will probably seem familiar.</p>

<pre>
  <code class="html">&lt;div class="grid"&gt;
  &lt;div class="column _12"&gt; 12 columns &lt;/div&gt;
  &lt;div class="column _6"&gt; 6 columns&lt;/div&gt;
  &lt;div class="column _6"&gt;
    &lt;div class="row"&gt;
      &lt;div class="column _12"&gt; 6 columns&lt;/div&gt;
      &lt;div class="column _6"&gt; 3 columns&lt;/div&gt;
      &lt;div class="column _6"&gt; 3 columns&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code>
</pre>

<p>You might agree, that this can cause layout issues and there is no real solution to this problem. We have accepted this issue and learned to use grids in this way.</p>

<p>CSS variables can be a big help here. By simply adding one line to our CSS, we can tell a row how many columns are available. This is something that would usually require javascript or large amounts of code and configuration.</p>

<pre>
  <code class="css">.row {
  --columns: var(--colspan);
}
</code>
</pre>

<p>We can now define columns relative to the outer <code>.grid</code> instead of the parent element.</p>

<pre>
  <code class="html">&lt;div class="grid"&gt;
  &lt;div class="column" style="--colspan: 12"&gt; 12 columns &lt;/div&gt;
  &lt;div class="column" style="--colspan: 6"&gt; 6 columns&lt;/div&gt;
  &lt;div class="column" style="--colspan: 6"&gt;
    &lt;div class="row"&gt;
      &lt;div class="column" style="--colspan: 6"&gt; 6 columns&lt;/div&gt;
      &lt;div class="column" style="--colspan: 3"&gt; 3 columns&lt;/div&gt;
      &lt;div class="column" style="--colspan: 3"&gt; 3 columns&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code>
</pre>

<h2>Minus minus grid</h2>

<p>A while ago I created a very similar grid, which is available on <a href="https://github.com/pixelass/minus-grid/">github</a> and <a href="https://www.npmjs.com/package/minus-grid">npm</a>.</p>

<p>The name is obviously a pun ✨🦄✨ </p>

<blockquote>
<h3>Minus minus grid</h3>

<p><code>--grid</code><br />
minus-grid</p>
</blockquote>

<p>This grid offers some extra features and handles the entire logic including responsive behavior. If you are interested you should give it a try. Just include this code in your next pen:</p>

<pre>
  <code class="css">@import "https://cdn.rawgit.com/pixelass/minus-grid/v1.2.0/dist/index.css";

.grid {
  --column-margin: 5;
  --column-padding: 5;
}

</code>
</pre>

<p><p data-slug-hash="eBBREx" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<h2>Conclusion</h2>

<p>CSS variables are very powerful and offer some logic we haven't been able to use until now. I am very excited to see how variables will influence open source projects and frameworks. </p>

<p>Before attempting to make use of this technique check the browser support: <a href="http://caniuse.com/#feat=css-variables">http://caniuse.com/#feat=css-variables</a></p>

<h3>Browser support (time of writing)</h3>

<p>Edge is <a href="https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/6261292-css-variables">working on the feature</a>.</p>

<p>
  <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/28359/Screen%20Shot%202016-11-19%20at%207.32.35%20PM.png" alt="Browser support (Edge and IE: no support)" />
</p>

    ]]>
  </description>

  <dc:subject>Layout powered by CSS variables</dc:subject>

  <dc:date>
    2016-11-20T09:23:29-07:00
  </dc:date>

</item>
      <item>

  <title>Getting Technical with Knockout</title>

  <link>//codepen.io/technoloG/post/getting-technical-with-knockout</link>
  <guid>//codepen.io/technoloG/post/getting-technical-with-knockout</guid>

  <dc:creator>Richard Nalezynski</dc:creator>

  <description>
    <![CDATA[
    <p>In thinking about more sophisticated, data-driven modern web sites there is a decision to be made: how to map data to relevant elements on a page.</p>

<p>One fairly straightforward approach is to use JavaScript or a library such as <a rel="nofollow" href="http://codepen.io/technoloG/post/jquery-big-functionality-in-a-small-library">jQuery</a> to help trap events and make updates accordingly. Of course, this will result in a lot of additional code to maintain.</p>

<p>Another approach is to use <strong>Knockout</strong>. Developed by Steve Sanderson from Microsoft and used by Microsoft in products such as the Azure portal, Knockout is a library that helps create rich experiences by mapping representation of data to a data model. This is accomplished through declarative binding of data to elements, along with dependency tracking for real-time updates to UI page elements</p>

<p>Knockout utilizes the <a rel="nofollow" href="http://codepen.io/technoloG/post/modern-web-architecture-and-design">MVVM architectural pattern</a> and has three components:</p>

<ul>
<li>The <strong>Model</strong> and <strong>View Model</strong> defined in JavaScript</li>
<li>The <strong>View</strong> and bindings declared in HTML</li>
<li>Databinding the View Model and View in JavaScript</li>
</ul>

<p>In some ways, you can think of databinding in Knockout as an automated alternative to using jQuery when it comes to filling in certain values and form fields arranged on a page. And Knockout provides precise control of what can be observed and what should not. These <em>observables</em> are the core of what Knockout uses to track changes and reflect updates automatically.</p>

<p>
  <strong>Using Knockout</strong>
</p>

<p>To get started using Knockout, be sure to include the library.</p>

<p>From there, define a View Model via JavaScript with some observables…</p>

<pre>
  <code class="JavaScript">var ViewModel = function() {
  var text = ko.observable("");
}
</code>
</pre>

<p>Then, bind the View Model...</p>

<pre>
  <code class="JavaScript">var VM = new ViewModel();

ko.applyBindings(VM);
</code>
</pre>

<p>And finally, declare the observables in your HTML View…</p>

<pre>
  <code class="HTML">&lt;p&gt;The text is: &lt;span data-bind="text: text"&gt;&lt;/span&gt;&lt;/p&gt;
</code>
</pre>

<p>
  <strong>Things to Keep in Mind with Knockout</strong>
</p>

<p>First, remember that observables in Knockout are functions, so be sure to reference them appropriately.</p>

<pre>
  <code class="JavaScript">var text = ko.observable("");

// wrong way
var greeting = "Hello" + text;

// correct way
var greeting = "Hello" + text();
</code>
</pre>

<p>Second, it's a good practice to set the DOM element in the second parameter when applying bindings. This helps with having multiple views on a single page.</p>

<pre>
  <code class="HTML">&lt;div id="greeting"&gt;
  &lt;p&gt;&lt;span data-bind="text: greeting&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
</code>
</pre>

<pre>
  <code class="JavaScript">// explicit binding to DOM element
var VM = new ViewModel();

ko.applyBindings(VM, document.getElementById("greeting");
</code>
</pre>

<p>See the following example for more ways to use Knockout…
<a rel="nofollow" href="http://codepen.io/technoloG/pen/raZWdG">http://codepen.io/technoloG/pen/raZWdG</a></p>

<p>As powerful as it is, Knockout is just another <a rel="nofollow" href="http://codepen.io/technoloG/post/solving-common-problems-with-libraries-and-frameworks">library</a> and not a full-fledged framework. Its high-level solution to databinding plays nicely with other low- and high-level libraries in a Modern Web project. Depending on your project's needs, Knockout can be as indispensable as <a rel="nofollow" href="http://codepen.io/technoloG/post/bootstrap-consistency-adapted-to-multiple-display-sizes">Bootstrap</a> when building a Modern Web Application. Add it to the list of <em>must-have</em> libraries in your web development tool belt!</p>

<p>URL: <a rel="nofollow" href="http://knockoutjs.com/">http://knockoutjs.com/</a></p>

    ]]>
  </description>

  <dc:subject>Getting Technical with Knockout</dc:subject>

  <dc:date>
    2016-11-22T02:11:02-07:00
  </dc:date>

</item>
      <item>

  <title>A Dummy&#39;s Guide to Redux and Thunk in React</title>

  <link>//codepen.io/stowball/post/a-dummy-s-guide-to-redux-and-thunk-in-react</link>
  <guid>//codepen.io/stowball/post/a-dummy-s-guide-to-redux-and-thunk-in-react</guid>

  <dc:creator>Matt Stow</dc:creator>

  <description>
    <![CDATA[
    <p>If, like me, you've <a rel="nofollow" href="http://redux.js.org">read the Redux docs</a>, <a rel="nofollow" href="https://egghead.io/courses/getting-started-with-redux">watched Dan's videos</a>, <a rel="nofollow" href="https://www.learnredux.com">done Wes' course</a> and still not quite grasped how to use Redux, hopefully this will help.</p>

<p>It took me a few attempts at using Redux before it clicked, so I thought I'd write down the process of converting an existing application that fetches JSON to use Redux and <a rel="nofollow" href="https://github.com/gaearon/redux-thunk">Redux Thunk</a>. If you don't know what Thunk is, don't worry too much, but we'll use it to make asynchronous calls in the "Redux way".</p>

<p>This tutorial assumes you have a basic grasp of React and ES6/2015, but it should hopefully be easy enough to follow along regardless.</p>

<h2>The non-Redux way</h2>

<p>Let's start with creating a React component in <code>components/ItemList.js</code> to fetch and display a list of items.</p>

<h3>Laying the foundations</h3>

<p>First we'll setup a static component with a <code>state</code> that contains various <code>items</code> to output, and 2 boolean states to render something different when it's loading or errored respectively.</p>

<pre>
  <code class="js">import React, { Component } from 'react';

class ItemList extends Component {
    constructor() {
        super();

        this.state = {
            items: [
                {
                    id: 1,
                    label: 'List item 1'
                },
                {
                    id: 2,
                    label: 'List item 2'
                },
                {
                    id: 3,
                    label: 'List item 3'
                },
                {
                    id: 4,
                    label: 'List item 4'
                }
            ],
            hasErrored: false,
            isLoading: false
        };
    }

    render() {
        if (this.state.hasErrored) {
            return &lt;p&gt;Sorry! There was an error loading the items&lt;/p&gt;;
        }

        if (this.state.isLoading) {
            return &lt;p&gt;Loading…&lt;/p&gt;;
        }

        return (
            &lt;ul&gt;
                {this.state.items.map((item) =&gt; (
                    &lt;li key={item.id}&gt;
                        {item.label}
                    &lt;/li&gt;
                ))}
            &lt;/ul&gt;
        );
    }
}

export default ItemList;
</code>
</pre>

<p>It may not seem like much, but this is a good start.</p>

<p>When rendered, the component should output 4 list items, but if you were to set <code>isLoading</code> or <code>hasErrored</code> to <code>true</code>, a relevant <code>&lt;p&gt;&lt;/p&gt;</code> would be output instead.</p>

<h3>Making it dynamic</h3>

<p>Hard-coding the items doesn't make for a very useful component, so let's fetch the <code>items</code> from a JSON API, which will also allow us to set <code>isLoading</code> and <code>hasErrored</code> as appropriate.</p>

<p>The response will be identical to our hard-coded list of items, but in the real world, you could pull in a list of best-selling books, latest blog posts, or whatever suits your application.</p>

<p>To fetch the items, we're going to use the aptly named <a rel="nofollow" href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">Fetch API</a>. Fetch makes making requests much easier than the classic <a rel="nofollow" href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest">XMLHttpRequest</a> and returns a promise of the resolved response (which is important to Thunk). Fetch isn't available in all browsers, so you'll need to add it as a dependency to your project with:</p>

<pre>
  <code class="sh">npm install whatwg-fetch --save
</code>
</pre>

<p>The conversion is actually quite simple.</p>

<ol>
<li>First we'll set our initial <code>items</code> to an empty array <code>[]</code></li>
<li><p>Now we'll add a method to fetch the data and set the loading and error states:</p>

<pre><code class="js">fetchData(url) {
    this.setState({ isLoading: true });

    fetch(url)
        .then((response) =&gt; {
            if (!response.ok) {
                throw Error(response.statusText);
            }

            this.setState({ isLoading: false });

            return response;
        })
        .then((response) =&gt; response.json())
        .then((items) =&gt; this.setState({ items })) // ES6 property value shorthand for { items: items }
        .catch(() =&gt; this.setState({ hasErrored: true }));
}
</code></pre></li>
<li><p>Then we'll call it when the component mounts:</p>

<pre><code class="js">componentDidMount() {
    this.fetchData('http://5826ed963900d612000138bd.mockapi.io/items');
}
</code></pre></li>
</ol>

<p>Which leaves us with <em>(unchanged lines omitted)</em>:</p>

<pre>
  <code class="js">class ItemList extends Component {
    constructor() {
        this.state = {
            items: [],
        };
    }

    fetchData(url) {
        this.setState({ isLoading: true });

        fetch(url)
            .then((response) =&gt; {
                if (!response.ok) {
                    throw Error(response.statusText);
                }

                this.setState({ isLoading: false });

                return response;
            })
            .then((response) =&gt; response.json())
            .then((items) =&gt; this.setState({ items }))
            .catch(() =&gt; this.setState({ hasErrored: true }));
    }

    componentDidMount() {
        this.fetchData('http://5826ed963900d612000138bd.mockapi.io/items');
    }

    render() {
    }
}
</code>
</pre>

<p>And that's it. Your component now fetches the <code>items</code> from a REST endpoint! You should hopefully see <code>"Loading…"</code> appear briefly before the 4 list items. If you pass in a broken URL to <code>fetchData</code> you should see our error message.</p>

<p>However, in reality, a component shouldn't include logic to fetch data, and data shouldn't be stored in a component's state, so this is where Redux comes in.</p>

<h2>Converting to Redux</h2>

<p>To start, we need to add Redux, React Redux and Redux Thunk as dependencies of our project so we can use them. We can do that with:</p>

<pre>
  <code class="sh">npm install redux react-redux redux-thunk --save
</code>
</pre>

<h3>Understanding Redux</h3>

<p>There are a few core principles to Redux which we need to understand:</p>

<ol>
<li>There is 1 global state object that manages the state for your entire application. In this example, it will behave identically to our initial component's state. It is the <em>single source of truth</em>.</li>
<li>The only way to modify the state is through emitting an action, which is an object that describes what should change. Action Creators are the functions that are <code>dispatch</code>ed to emit a change – all they do is <code>return</code> an action.</li>
<li>When an action is <code>dispatch</code>ed, a Reducer is the function that actually changes the state appropriate to that action – or returns the existing state if the action is not applicable to that reducer.</li>
<li>Reducers are "pure functions". They should not have any side-effects nor mutate the state – they must return a modified copy.</li>
<li>Individual reducers are combined into a single <code>rootReducer</code> to create the discrete properties of the state.</li>
<li>The Store is the thing that brings it all together: it represents the state by using the <code>rootReducer</code>, any middleware (Thunk in our case), and allows you to actually <code>dispatch</code> actions.</li>
<li>For using Redux in React, the <code>&lt;Provider /&gt;</code> component wraps the entire application and passes the <code>store</code> down to all children.</li>
</ol>

<p>This should all become clearer as we start to convert our application to use Redux.</p>

<h3>Designing our state</h3>

<p>From the work we've already done, we know that our state needs to have 3 properties: <code>items</code>, <code>hasErrored</code> and <code>isLoading</code> for this appliation to work as expected under all circumstances, which correlates to needing 3 unique actions.</p>

<p>Now, here is why Action Creators are different to Actions and do not necessarily have a 1:1 relationship: we need a fourth action creator that calls our 3 other action (creators) depending on the status of fetching the data. This fourth action creator is almost identical to our original <code>fetchData()</code> method, but instead of directly setting the state with <code>this.setState({ isLoading: true })</code>, we'll <code>dispatch</code> an action to do the same: <code>dispatch(isLoading(true))</code>.</p>

<h3>Creating our actions</h3>

<p>Let's create an <code>actions/items.js</code> file to contain our action creators. We'll start with our 3 simple actions.</p>

<pre>
  <code class="js">export function itemsHasErrored(bool) {
    return {
        type: 'ITEMS_HAS_ERRORED',
        hasErrored: bool
    };
}

export function itemsIsLoading(bool) {
    return {
        type: 'ITEMS_IS_LOADING',
        isLoading: bool
    };
}

export function itemsFetchDataSuccess(items) {
    return {
        type: 'ITEMS_FETCH_DATA_SUCCESS',
        items
    };
}
</code>
</pre>

<p>As mentioned before, action creators are functions that return an action. We <code>export</code> each one so we can use them elsewhere in our codebase.</p>

<p>The first 2 action creators take a <code>bool</code> (<code>true</code>/<code>false</code>) as their argument and return an object with a meaningful <code>type</code> and  the <code>bool</code> assigned to the appropriate property.</p>

<p>The third, <code>itemsFetchSuccess()</code>, will be called when the data has been successfully fetched, with the data passed to it as <code>items</code>. Through the magic of ES6 property value shorthands, we'll return an object with a property called <code>items</code> whose value will be the array of <code>items</code>;</p>

<p>
  <em>Note: that the value you use for <code>type</code> and the name of the other property that is returned is important, because you will re-use them in your reducers</em>
</p>

<p>Now that we have the 3 actions which will represent our state, we'll convert our original component's <code>fetchData</code> method to an <code>itemsFetchData()</code> action creator.</p>

<p>By default, Redux action creators don't support asynchronous actions like fetching data, so here's where we utilise Redux Thunk. Thunk allows you to write action creators that return a function instead of an action. The inner function can receive the store methods <code>dispatch</code> and <code>getState</code> as parameters, but we'll just use <code>dispatch</code>.</p>

<p>A real simple example would be to manually trigger <code>itemsHasErrored()</code> after 5 seconds.</p>

<pre>
  <code class="js">export function errorAfterFiveSeconds() {
    // We return a function instead of an action object
    return (dispatch) =&gt; {
        setTimeout(() =&gt; {
            // This function is able to dispatch other action creators
            dispatch(itemsHasErrored(true));
        }, 5000);
    };
}
</code>
</pre>

<p>Now we know what a thunk is, we can write <code>itemsFetchData()</code>.</p>

<pre>
  <code class="js">export function itemsFetchData(url) {
    return (dispatch) =&gt; {
        dispatch(itemsIsLoading(true));

        fetch(url)
            .then((response) =&gt; {
                if (!response.ok) {
                    throw Error(response.statusText);
                }

                dispatch(itemsIsLoading(false));

                return response;
            })
            .then((response) =&gt; response.json())
            .then((items) =&gt; dispatch(itemsFetchDataSuccess(items)))
            .catch(() =&gt; dispatch(itemsHasErrored(true)));
    };
}
</code>
</pre>

<h3>Creating our reducers</h3>

<p>With our action creators defined, we now write reducers that take these actions and return a new state of our application.</p>

<p>
  <em>Note: In Redux, all reducers get called regardless of the action, so inside each one you have to return the original <code>state</code> if the action is not applicable.</em>
</p>

<p>Each reducer takes 2 parameters: the previous state (<code>state</code>) and an <code>action</code> object. We can also use an ES6 feature called default parameters to set the default initial <code>state</code>.</p>

<p>Inside each reducer, we use a <code>switch</code> statement to determine when an <code>action.type</code> matches. While it may seem unnecessary in these simple reducers, your reducers could theoretically have a lot of conditions, so <code>if</code>/<code>else if</code>/<code>else</code> will get messy fast.</p>

<p>If the <code>action.type</code> matches, then we return the relevant property of <code>action</code>. As mentioned earlier, the <code>type</code> and <code>action[propertyName]</code> is what was defined in your action creators.</p>

<p>OK, knowing this, let's create our items reducers in <code>reducers/items.js</code>.</p>

<pre>
  <code class="js">export function itemsHasErrored(state = false, action) {
    switch (action.type) {
        case 'ITEMS_HAS_ERRORED':
            return action.hasErrored;

        default:
            return state;
    }
}

export function itemsIsLoading(state = false, action) {
    switch (action.type) {
        case 'ITEMS_IS_LOADING':
            return action.isLoading;

        default:
            return state;
    }
}

export function items(state = [], action) {
    switch (action.type) {
        case 'ITEMS_FETCH_DATA_SUCCESS':
            return action.items;

        default:
            return state;
    }
}
</code>
</pre>

<p>Notice how each reducer is named after the resulting store's state property, with the <code>action.type</code> not necessarily needing to correspond. The first 2 reducers hopefully make complete sense, but the last, <code>items()</code>, is slightly different.</p>

<p>This is because it could have multiple conditions which would always return an array of <code>items</code>: it could return all in the case of a fetch success, it could return a subset of <code>items</code> after a delete action is <code>dispatch</code>ed, or it could return an empty array if everything is deleted.</p>

<p>To re-iterate, every reducer will return a discrete property of the state, regardless of how many conditions are inside that reducer. That initially took me a while to get my head around.</p>

<p>With the individual reducers created, we need to combine them into a <code>rootReducer</code> to create a single object.</p>

<p>Create a new file at <code>reducers/index.js</code>.</p>

<pre>
  <code class="js">import { combineReducers } from 'redux';
import { items, itemsHasErrored, itemsIsLoading } from './items';

export default combineReducers({
    items,
    itemsHasErrored,
    itemsIsLoading
});
</code>
</pre>

<p>We import each of the reducers from <code>items.js</code> and export them with Redux's <code>combineReducers()</code>. As our reducer names are identical to what we want to use for a store's property names, we can use the ES6 shorthand.</p>

<p>Notice how I intentionally prefixed my reducer names, so that when the application grows in complexity, I'm not constrained by having a "global" <code>hasErrored</code> or <code>isLoading</code> property. You may have many different features that could error or be in a loading state, so prefixing the imports and then exporting those will give your application's state greater granularity and flexibility. For example:</p>

<pre>
  <code class="js">import { combineReducers } from 'redux';
import { items, itemsHasErrored, itemsIsLoading } from './items';
import { posts, postsHasErrored, postsIsLoading } from './posts';

export default combineReducers({
    items,
    itemsHasErrored,
    itemsIsLoading,
    posts,
    postsHasErrored,
    postsIsLoading
});
</code>
</pre>

<p>Alternatively, you could alias the methods on <code>import</code>, but I prefer consistency across the board.</p>

<h3>Configure the store and provide it to your app</h3>

<p>This is pretty straightforward. Let's create <code>store/configureStore.js</code> with:</p>

<pre>
  <code class="js">import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from '../reducers';

export default function configureStore(initialState) {
    return createStore(
        rootReducer,
        initialState,
        applyMiddleware(thunk)
    );
}
</code>
</pre>

<p>Now change our app's <code>index.js</code> to include <code>&lt;Provider /&gt;</code>, <code>configureStore</code>, set up our <code>store</code> and wrap our app (<code>&lt;ItemList /&gt;</code>) to pass the <code>store</code> down as <code>props</code>:</p>

<pre>
  <code class="js">import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import configureStore from './store/configureStore';

import ItemList from './components/ItemList';

const store = configureStore(); // You can also pass in an initialState here

render(
    &lt;Provider store={store}&gt;
        &lt;ItemList /&gt;
    &lt;/Provider&gt;,
    document.getElementById('app')
);
</code>
</pre>

<p>I know, it's taken quite a bit of effort to get to this stage, but with the set up complete, we can now modify our component to make use of what we've done.</p>

<h3>Converting our component to use the Redux store and methods</h3>

<p>Let's jump back in to <code>components/ItemList.js</code>.</p>

<p>At the top of the file, <code>import</code> what we need:</p>

<pre>
  <code class="js">import { connect } from 'react-redux';
import { itemsFetchData } from '../actions/items';
</code>
</pre>

<p><code>connect</code> is what allows us to connect a component to Redux's store, and <code>itemsFetchData</code> is the action creator we wrote earlier. We only need to import this one action creator, as it handles <code>dispatch</code>ing the other actions.</p>

<p>After our component's <code>class</code> definition, we're going to map Redux's state and the dispatching of our action creator to props.</p>

<p>We create a function that accepts <code>state</code> and then returns an object of props. In a simple component like this, I remove the prefixing for the <code>has</code>/<code>is</code> props as it's obvious that they're related to <code>items</code>.</p>

<pre>
  <code class="js">const mapStateToProps = (state) =&gt; {
    return {
        items: state.items,
        hasErrored: state.itemsHasErrored,
        isLoading: state.itemsIsLoading
    };
};
</code>
</pre>

<p>And then we need another function to be able to <code>dispatch</code> our <code>itemsFetchData()</code> action creator with a prop.</p>

<pre>
  <code class="js">const mapDispatchToProps = (dispatch) =&gt; {
    return {
        fetchData: (url) =&gt; dispatch(itemsFetchData(url))
    };
};
</code>
</pre>

<p>Again, I've removed the <code>items</code> prefix from the returned object property. Here <code>fetchData</code> is a function that accepts a <code>url</code> parameter and returns <code>dispatch</code>ing <code>itemsFetchData(url)</code>.</p>

<p>Now, these 2 <code>mapStateToProps()</code> and <code>mapDispatchToProps()</code> don't do anything yet, so we need to change our final <code>export</code> line to:</p>

<pre>
  <code class="js">export default connect(mapStateToProps, mapDispatchToProps)(ItemList);
</code>
</pre>

<p>This <code>connect</code>s our <code>ItemList</code> to Redux while mapping the props for us to use.</p>

<p>The final step is to convert our component to use <code>props</code> instead of <code>state</code>, and to remove the leftovers.</p>

<ul>
<li>Delete the <code>constructor() {}</code> and <code>fetchData() {}</code> methods as they're unnecessary now.</li>
<li>Change <code>this.fetchData()</code> in <code>componentDidMount()</code> to <code>this.props.fetchData()</code>.</li>
<li>Change <code>this.state.X</code> to <code>this.props.X</code> for <code>.hasErrored</code>, <code>.isLoading</code> and <code>.items</code>.</li>
</ul>

<p>Your component should now look like this:</p>

<pre>
  <code class="js">import React, { Component } from 'react';
import { connect } from 'react-redux';
import { itemsFetchData } from '../actions/items';

class ItemList extends Component {
    componentDidMount() {
        this.props.fetchData('http://5826ed963900d612000138bd.mockapi.io/items');
    }

    render() {
        if (this.props.hasErrored) {
            return &lt;p&gt;Sorry! There was an error loading the items&lt;/p&gt;;
        }

        if (this.props.isLoading) {
            return &lt;p&gt;Loading…&lt;/p&gt;;
        }

        return (
            &lt;ul&gt;
                {this.props.items.map((item) =&gt; (
                    &lt;li key={item.id}&gt;
                        {item.label}
                    &lt;/li&gt;
                ))}
            &lt;/ul&gt;
        );
    }
}

const mapStateToProps = (state) =&gt; {
    return {
        items: state.items,
        hasErrored: state.itemsHasErrored,
        isLoading: state.itemsIsLoading
    };
};

const mapDispatchToProps = (dispatch) =&gt; {
    return {
        fetchData: (url) =&gt; dispatch(itemsFetchData(url))
    };
};

export default connect(mapStateToProps, mapDispatchToProps)(ItemList);
</code>
</pre>

<p>And that's it! The application now uses Redux and Redux Thunk to fetch and display the data!</p>

<p>
  <strong>That wasn't too difficult, was it?</strong>
</p>

<p>And you're now a Redux master :D</p>

<h2>What next?</h2>

<p>I've put all of <a rel="nofollow" href="https://github.com/stowball/dummys-guide-to-redux-and-thunk-react">this code up on GitHub</a>, with commits for each step. I want you to clone it, run it and understand it, then add the ability for the user to delete individual list items based on the item's <code>index</code>.</p>

<p>I haven't yet really mentioned that in Redux, the <em>state is immutable</em>, which means you can't modify it, so have to return a new state in your reducers instead. The 3 reducers we wrote above were simple and "just worked", but deleting items from an array requires an approach that you may not be familiar with.</p>

<p>You can no longer use <code>Array.prototype.splice()</code> to remove items from an array, as that will mutate the original array. <a rel="nofollow" href="https://egghead.io/lessons/javascript-redux-avoiding-array-mutations-with-concat-slice-and-spread">Dan explains how to remove an element from an array in this video</a>, but if you get stuck, you can check out (pun intended) the <code>delete-items</code> branch for the solution.</p>

<p>I really hope that this has clarified the concept of Redux and Thunk and how you might go about converting an existing React application to use them. I know that writing this has solidified my understanding of it, so I'm very happy to have done it.</p>

<p>I'd still recommend <a rel="nofollow" href="http://redux.js.org">reading the Redux docs</a>, <a rel="nofollow" href="https://egghead.io/courses/getting-started-with-redux">watching Dan's videos</a>, and <a rel="nofollow" href="https://www.learnredux.com">re-doing Wes' course</a> as you should hopefully now be able to understand some of the other more complex and deeper principles.</p>

    ]]>
  </description>

  <dc:subject>A Dummy&#39;s Guide to Redux and Thunk in React</dc:subject>

  <dc:date>
    2016-11-15T22:10:08-07:00
  </dc:date>

</item>
      <item>

  <title>Keep links accessible &amp; meaningful</title>

  <link>//codepen.io/Muhnad/post/keep-links-accessible-meaningful</link>
  <guid>//codepen.io/Muhnad/post/keep-links-accessible-meaningful</guid>

  <dc:creator>Muhannad Abdelrazek</dc:creator>

  <description>
    <![CDATA[
    <p>Links is the most thing on the web you see so that we should make links more simple and more accessible for all users.</p>

<p>we will take a look at examples and discuss how should links looks.</p>

<p>1-  Link or anchor tag should explain what's happen if you click on, the user need know where this link goes no one like click on an anonymous link.</p>

<p>
  <strong>Do</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  Example || Accessibility Guidelines.
&lt;/a&gt;</code>
</p>

<p>
  <strong>Don't</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  Click here || more
 &lt;/a&gt;</code>
</p>

<p>2- Don't write "link" word in the link because the screen reader knows the link if you use the anchor tag, screen reader differ from one to other some of them say the "link" before value and other say it after value anyway in finally the screen reader know this is the link.</p>

<p>
  <strong>Do</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  Example || Accessibility Guidelines.
&lt;/a&gt;</code>
</p>

<p>
  <strong>Don't</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  Example Link || 
  Accessibility Guidelines Link.
 &lt;/a&gt;</code>
</p>

<p>3- use semantic element don't change the element behaviour.</p>

<p>
  <strong>Do</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  Example || Accessibility Guidelines.
&lt;/a&gt;</code>
</p>

<p>
  <strong>Don't</strong>
</p>

<p>
  <code>&lt;span class="act-link"&gt;
  Act like Link 
 &lt;/span&gt;</code>
</p>

<p>4- if you used the another element to act like link you should make it accessible you should make it foucs you should make screen reader read it a link you should make it real link.</p>

<p>
  <strong>Do</strong>
</p>

<p><p data-slug-hash="zoBRzy" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>5- if the link include image, image should explain what's going in alt OR let alt empty and return to num 1.</p>

<p>
  <strong>Do</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  &lt;img src="/" alt="example"&gt;
&lt;/a&gt;</code>
</p>

<p>
  <strong>OR</strong>
</p>

<p>
  <code>&lt;a href="http://www.example.com"&gt;
  &lt;img src="/" alt=""&gt;
  example
&lt;/a&gt;</code>
</p>

<p>6- the blind users don't know if the link open in new window or not so we should make an alert to recognize them to the link will open in new window.</p>

<p>
  <strong>Do</strong>
</p>

<p><p data-slug-hash="pNbaYO" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>
  <strong>OR</strong>
</p>

<p><p data-slug-hash="rWLJbb" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>we should take care of small things, we should make the web more accessible and more meaningful.</p>

<p>finally, I made a script to check the issue in your code that's will help you to identify the accessibility issue to fix it <a rel="nofollow" href="https://github.com/Muhnad/a11y-checker">a11y-checker</a></p>

    ]]>
  </description>

  <dc:subject>Keep links accessible &amp; meaningful</dc:subject>

  <dc:date>
    2016-12-01T13:22:49-07:00
  </dc:date>

</item>
      <item>

  <title>Codepen stats library</title>

  <link>//codepen.io/remirobichet/post/codepen-stats-library</link>
  <guid>//codepen.io/remirobichet/post/codepen-stats-library</guid>

  <dc:creator>Rémi Robichet</dc:creator>

  <description>
    <![CDATA[
    <p>The purpose of this article is to introduce <em>the Codepen stats library</em> I created.</p>

<p>First, I have made a pen to check your stats using the <a rel="nofollow" href="http://cpv2api.com/">cpv2api</a>:</p>

<p><p data-slug-hash="JKdyoG" data-default-tab="result" data-height="700" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>Then I get the idea to add these informations to my personal website, this is why i created this <strong>ultra small library (1Ko)</strong></p>

<p>To use it, a few instructions should be respected:</p>

<ul>
<li>Check that jQuery is loaded</li>
<li>Include the javascript code <a rel="nofollow" href="http://codepen.io/remirobichet/pen/jVrgqO.js">http://codepen.io/remirobichet/pen/jVrgqO.js</a></li>
</ul>

<pre>
  <code class="javascript">var name = $("[data-user]").attr("data-user"),
  cploves = 0,
  cpviews = 0;

$.getJSON('http://cpv2api.com/profile/' + name, function(res) {
  if (res.success) {
    $("[data-followers]").text(res.data.followers);
  } else {
    $("[data-followers]").text('error');
  }
});

function getViews(page) {
  var name = $("[data-user]").attr("data-user");
  $.getJSON('http://cpv2api.com/pens/public/' + name + '?page=' + page, function(res) {
    if (res.success) {
      $(res.data).each(function() {
        if (this.views != '') {
          cpviews += parseInt(this.views.replace(',', ''));
        } else {
          $("[data-views]").text('error');
        }
        if (this.loves != '') {
          cploves += parseInt(this.loves);
        } else {
          $("[data-loves]").text('error');
        }
      });
      page++;
      getViews(page);
    }
  });

  $("[data-views]").text(cpviews);
  $("[data-loves]").text(cploves);
}

getViews(1);
</code>
</pre>

<ul>
<li>Now you have to add your @username on a <code>data-user</code> attribute wherever you want on your HTML</li>
</ul>

<pre>
  <code class="html">&lt;main data-user="remirobichet"&gt;
</code>
</pre>

<ul>
<li>And finally add the attribute you want (<code>data-followers</code>, <code>data-views</code>, <code>data-loves</code>)</li>
</ul>

<pre>
  <code class="html">&lt;p&gt;I have &lt;b data-followers&gt;&lt;/b&gt; followers on Codepen !&lt;/p&gt;
</code>
</pre>

<p>Here is an example of how you can use the library:</p>

<p><p data-slug-hash="yVJWbv" data-default-tab="result" data-height="300" data-theme-id="0" data-embed-version="2" class="codepen"></p></p>

<p>Thanks for reading :)</p>

<hr />

<p>Be nice, I'm not English!</p>

    ]]>
  </description>

  <dc:subject>Codepen stats library</dc:subject>

  <dc:date>
    2016-11-15T21:08:51-07:00
  </dc:date>

</item>
      <item>

  <title>React Basics - making a markdown parser</title>

  <link>//codepen.io/anuragasaurus/post/react-basics-making-a-markdown-parser</link>
  <guid>//codepen.io/anuragasaurus/post/react-basics-making-a-markdown-parser</guid>

  <dc:creator>anuragasaurus</dc:creator>

  <description>
    <![CDATA[
    <p>Hello guys, this is a post on react basics. This is a very basic tutorial written for people who are beginner in React.</p>

<p>So, below is what we will be making. (If the codepen embed doesn't load, try refreshing the page.)</p>

<p data-height="265" data-theme-id="0" data-slug-hash="WGBgxQ" data-default-tab="js,result" data-embed-version="2" class="codepen">See the Pen <a rel="nofollow" href="https://codepen.io/anuragasaurus/pen/WGBgxQ/">React markdown parser</a> by anuragasaurus (<a rel="nofollow" href="http://codepen.io/anuragasaurus">@anuragasaurus</a>) on <a rel="nofollow" href="http://codepen.io">CodePen</a>.</p>



<p>I have created a component named "TextArea" which is the main and only component. It's state consits of <code>inputValue</code> and <code>parsedValue</code> of markdown input.</p>

<pre>
  <code class="javascript">this.state={
    inputValue:"# hello, write some `markdown` here",
    parsedValue:""
}
</code>
</pre>

<p>TextArea renders a input element where we will write in markdown and a div which will display the result. <code>handleChange</code> function keeps the state of component and value in input field in sync.</p>

<pre>
  <code class="javascript">handleChange(e) {
    this.setState({
      inputValue: e.target.value,
      parsedValue: marked(e.target.value)
    });
}
</code>
</pre>

<p>I am using a mardown parsing library <a rel="nofollow" href="https://github.com/chjj/marked">marked</a>. As input value changes, I pass the input value in marked function which is exposed by "marked" and store it in the <code>this.state.parsedValue</code>.</p>

<p><code>componentDidMount</code> is a react lifecycle function which is run after component is mounted on screen.</p>

<h3>Edit:</h3>

<p>I searched for alternative for <code>dangerouslySetInnerHTML</code> but couldn't find one. They named it <code>dangerouslySetInnerHTML</code> to make developer aware of the risk of XSS attack when they use it. To avoid the risk of XSS attack, we can use <code>DOMPurify</code> which sanitizes the html.</p>

    ]]>
  </description>

  <dc:subject>React Basics - making a markdown parser</dc:subject>

  <dc:date>
    2016-11-30T09:37:07-07:00
  </dc:date>

</item>
      <item>

  <title>ARIA Cheatsheet</title>

  <link>//codepen.io/matchboxhero/post/aria-cheatsheet</link>
  <guid>//codepen.io/matchboxhero/post/aria-cheatsheet</guid>

  <dc:creator>Steven Roberts</dc:creator>

  <description>
    <![CDATA[
    <h1>Aria</h1>

<h2>Cheatsheet for the most common ARIA Roles and Attributes</h2>

<p>HTML elements can only have one role or attribute.
Elements which are already semantic do not require additional aria attributes e.g <code>&lt;nav&gt; &lt;button&gt; &lt;header&gt; &lt;footer&gt; &lt;main&gt;</code></p>

<h2>ARIA Roles</h2>

<p>Aria roles are applied using the <code>role</code> attribute. e.g.
<code>&lt;div role="complementary"&gt;</code></p>

<p><strong>main</strong>
Main content of the document</p>

<p><strong>banner</strong>
The main header of the page</p>

<p><strong>navigation</strong>
Navigation elements</p>

<p><strong>contentinfo</strong>
copyright information usually applied to an element within the footer tag</p>

<p><strong>complementary</strong>
Content which is related to the main element</p>

<p><strong>presentation</strong>
Applied to elements which are used only for presentation</p>

<p><strong>search</strong>
to be used on search elements</p>

<p><strong>alert</strong>
to be used on elements which are shown as an alert</p>

<p><strong>button</strong>
to be used on elements to make them behave like a button. This should be avoided and the button element should be used as extra markup and javascript is required to make a normal link act like a button</p>

<p><strong>combobox, checkbox, listbox and option</strong>
to be used to create faux form elements</p>

<p><strong>tooltip</strong>
to be used to specify an element as a tooltip</p>

<p><strong>dialog</strong>
Used for elements which update the user about an event or action that has occurred for example;
<code>
&lt;div role="dialog" aria-labelledby="dialogTitle" aria-describedby="dialogDescription"&gt;
  &lt;h2 id="dialogTitle"&gt;Your personal details were successfully updated&lt;/h2&gt;
  &lt;p id="dialogDescription"&gt;You can change your details at any time in the user account section.&lt;/p&gt;
  &lt;button&gt;Close&lt;/button&gt;
&lt;/div&gt;
</code></p>

<h2>ARIA Attributes</h2>

<p>Aria attributes are applied to elements directly (inline) or added to an element using javascript following interaction. These attributes fall into one of two categories; states and properties.</p>

<p><strong>States</strong> are likely to change to be updated following an interaction from the user.</p>

<p><strong>Properties</strong> are less likely to change such as <code>aria-labelledby</code> and provide additional information to user using assistive technologies.</p>

<p><strong>aria-label</strong>
to be added to label elements which aren't shown on the page. </p>

<p><strong>aria-controls="ID"</strong> 
aria controls specify an element by ID of which the current element controls</p>

<p><strong>aria-expanded="false"</strong>
this element can be either true or false and should be updated using javascript when the elements state has changed, example usage would be accordions</p>

<p><strong>aria-labelledby</strong>
used to provide a label for elements which don't have a native label;
<code>
&lt;figure aria-labelledby="operahouse_1" role="group"&gt;
    &lt;img src="operahousesteps.jpg" alt="The Sydney Opera House"&gt;
    &lt;figcaption id="operahouse_1"&gt;We saw the opera &lt;cite&gt;Barber of Seville&lt;/cite&gt; here!&lt;/figcaption&gt;
&lt;/figure&gt;
</code></p>

<p>
  <strong>aria-describedby="ID"</strong>
</p>

<p>aria described by requires an ID to be specified this could be linked to a tooltip for a example when a button has an icon but no text.</p>

<p><strong>aria-checked</strong>
used to create a faux radio button or checkbox
<code>
&lt;span role="checkbox" 
      aria-checked="true"
      tabindex="0"
      id="simulatedcheckbox"&gt;
&lt;/span&gt;
</code></p>

<p><strong>aria-hidden</strong>
used to provide information to the browser about the state of the current element can be set to true or false.</p>

    ]]>
  </description>

  <dc:subject>ARIA Cheatsheet</dc:subject>

  <dc:date>
    2016-11-09T10:01:34-07:00
  </dc:date>

</item>

  </channel>

</rss>