<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Type Faster - Medium]]></title>
        <description><![CDATA[Redshift Digital’s Engineering Blog - Medium]]></description>
        <link>https://medium.com/type-faster?source=rss----55d1797f8f21---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Type Faster - Medium</title>
            <link>https://medium.com/type-faster?source=rss----55d1797f8f21---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:23:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/type-faster" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Host Multiple Serverless APIs Under the Same Domain]]></title>
            <link>https://medium.com/type-faster/how-to-call-multiple-serverless-micro-services-under-the-same-domain-972b5b9e49dd?source=rss----55d1797f8f21---4</link>
            <guid isPermaLink="false">https://medium.com/p/972b5b9e49dd</guid>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloudformation]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[api-gateway]]></category>
            <category><![CDATA[serverless-architecture]]></category>
            <dc:creator><![CDATA[Brock Lanoza]]></dc:creator>
            <pubDate>Fri, 30 Mar 2018 15:57:37 GMT</pubDate>
            <atom:updated>2018-03-30T15:57:37.408Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vJoNzPZwtG7_0uVDFi3KmQ.jpeg" /></figure><p>Did you ever wish that people would just shut-up about serverless? It’s rare that one makes it out of a tech conference these days without hearing endless utterances of the term “serverless”. Annoying as this may be, the concept of serverless itself is incredibly inviting. Think about it; allow developers to write code and build applications without having to deal with all of the underlying infrastructure that more often than not becomes difficult to maintain and scale? It’s a pretty wonderful thing.</p><h3>Serverless APIs: A blessing and a curse</h3><p>If you’ve tried The Serverless Framework out, you’ve seen how easy it is to setup and deploy a live API by leveraging cloud services such as AWS Lambda. At the company I work for, Redshift Digital, we’ve used Serverless on a few client projects that needed a slim, simple backend to serve some content to the frontend application. In that situation, it worked very well and allowed us to move much quicker than would have been possible without such technology.</p><p>Unfortunately, our honeymoon with Serverless came to an abrupt end. While working on a recent project, I was merrily watching our API deploy when the following happened:</p><pre>Serverless: Uploading CloudFormation file to S3...</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*PZgT_L7dxU-fj4cX68Subg.png" /></figure><pre>The CloudFormation template is invalid: Template format error: Number of resources, 212, is greater than maximum allowed, 200</pre><p>Where did this come from? As it turns out, this was an issue with Amazon and not Serverless. Under the hood, when creating services deployed to AWS, Serverless compiles a CloudFormation script from the code you wrote and uploads it to the cloud. CloudFormation can be thought of as the control center for your AWS account. Anything that you can do through the console in AWS can be scripted through CloudFormation and deployed in an automated fashion. Sadly, AWS currently imposes a <strong>hard limit of 200 resources</strong> when deploying a CloudFormation script.</p><p>After digging a bit deeper into what was actually getting deployed with each Serverless package, it was easy to see how we were exceeding this limit, even with only about 30 endpoints in our API.</p><h3>The extra baggage of a Serverless function</h3><p>You don’t need a Nvidia GPU to determine that 30 &lt; 200. That said, how were we hitting the CloudFormation limit? The reason for this can be summed up as such:</p><pre>30Functions != 30Resources</pre><p>Let’s assume you created a Serverless API with 30 functions that acted as endpoints. For every function in your API, you also get the following resources:</p><ul><li>Version (of your Lambda function)</li><li>Log Group (on CloudWatch)</li><li>Permissions (Allowing API Gateway to call your Lambda function)</li><li>Resource path (of the API Gateway endpoint)</li><li>Method (of the API Gateway endpoint)</li></ul><p>In total, you get <strong>6 resources per function</strong> in addition to the few global resources shared by entire API. Although some app APIs can get by with such a limit in place, there are plenty of APIs out there that just simply require more than 30 endpoints to do their job. How can we get around this limit and still use a Serverless API to meet our needs?</p><h3>Microservice architecture</h3><p>To combat this resource limit, our team decided the best course of action was to split up our API into separate micro-services. For each resource in our REST API (users, organizations, etc), we created a new Serverless service with its own serverless.yml` file. By doing this, we realized a few benefits:</p><ul><li>Our code was separated in a way that made it easier to maintain</li><li>We avoided the hard-limit imposed by CloudFormation (hooray!)</li><li>Deployments were faster since we were only deploying a few of the API functions at a time, rather than all of them at once</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*gjxgod-aKTNumxHJGyFWXg.png" /><figcaption>Sample directory structure</figcaption></figure><p>Alas, this did not make a complete solution. At this point, we were left with a number of API hosts generated by AWS (one for each service). Ya know, these things:</p><pre><a href="https://zdqdd62gz9.execute-api.us-west-1.amazonaws.com/development/">https://sougly1337.execute-api.us-west-1.amazonaws.com/development/</a></pre><p>Luckily, it’s possible to alias each of these as base paths of a single API using m̶a̶g̶i̶c̶ a custom domain on API Gateway.</p><h3>Setting up a custom domain on API Gateway</h3><p>To setup a custom domain, go into your AWS console and navigate to the aptly-named “Custom Domain Names” section. Click on “Create a Custom Domain Name” and you will be greeted by this screen:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AbtwSkzAl1VtVNZcDnq07Q.png" /></figure><p>Assuming you have the domain that you want to use handy, you can type it in here and click the appropriate radio button under “Endpoint Configuration”. Generally speaking, the option you select will be determined by the purpose of your API.</p><ul><li>End-user facing APIs will use <strong>Edge Optimized</strong> since this will take advantage of the underlying CloudFront distribution to quickly get data to your users in whatever region they may reside.</li><li>If you API happens to talk exclusively to internal resources, such as an EC2 instance, then you would want to use <strong>Regional</strong> since this would optimize the API for the single region that it has to communicate with.</li></ul><h3>Base Path mappings are friend, not foe</h3><p>Now that we’ve done that, we’re ready to bring it all together and map the microservices to this domain. By adding a base path and choosing the correct microservice to point to (destination), you make it possible to access your individual Serverless services all through a single API endpoint.</p><p>In this case, mediumarticlesarecool.com/users would call the previously mentioned users service. Be aware, creating a custom domain can take up to 45 minutes to finish since it has to spin up a CloudFront distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*eWJ5AO0SzSOiJDr-26V5aw.png" /><figcaption>Don’t worry, organizations is plural</figcaption></figure><h3>Conclusion</h3><p>If you’ve stuck around for this long, you’ve hopefully learned a useful way to implement a large REST API using Serverless functions all whilst avoiding the dreaded CloudFormation resource limit error. Next time, I’ll be writing a piece explaining how we used CircleCI to automate the deployment of our microservices.</p><p><em>Disclaimer about using Serverless APIs in production:</em></p><p><em>It should be noted that while this worked for our particular situation (our serverless API was acting as a middleware layer between the frontend and other backend services), it may not work for you. For as great as serverless can be, there are some pain points that make it more of a hassle than it’s worth in certain situations. For example, dealing with connection pooling is notoriously difficult since Lambda functions are stateless. Make sure your understand your application’s specific needs before going all-in on serverless.</em></p><p><em>Brock Lanoza creates product solutions at </em><a href="http://www.redshiftdigital.com/"><em>Redshift Digital</em></a><em>. When not pondering the finer points of human-computer interaction, he can be found shamelessly spam-posting pictures of Persian cats to the internet.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=972b5b9e49dd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/type-faster/how-to-call-multiple-serverless-micro-services-under-the-same-domain-972b5b9e49dd">How to Host Multiple Serverless APIs Under the Same Domain</a> was originally published in <a href="https://medium.com/type-faster">Type Faster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Shallow History of Humans and Communication Design]]></title>
            <link>https://medium.com/type-faster/a-shallow-history-of-humans-and-communication-design-f29f8095bb49?source=rss----55d1797f8f21---4</link>
            <guid isPermaLink="false">https://medium.com/p/f29f8095bb49</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[history]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[communication-design]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Ändrëw Fïtzpätrïck]]></dc:creator>
            <pubDate>Mon, 10 Jul 2017 16:16:18 GMT</pubDate>
            <atom:updated>2017-07-10T16:16:18.123Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Part One: The Beginning</strong></h3><p>After much deliberation, a decision was reached to begin this article at the beginning. This image is the beginning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*nip728nNMVSvWZqgJX05aw.jpeg" /><figcaption>The beginning</figcaption></figure><p>This is an image of the farthest distance ever captured in outer space. Distance in space is measured in light years so the farther you look into space, you will get a glimpse of what the universe looked like at that time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*U010fPfqeTNwcJhPEpchqA.jpeg" /><figcaption>Alpha Centauri</figcaption></figure><p>For instance, the closes star to Earth is Alpha Centauri. Alpha Centauri is actually larger than our sun and is approximately 4.3 light years away from Earth. This means that when we look at Alpha Centauri in the night sky what we are seeing is the light form of the star from 4.3 years ago.</p><p>The galaxies pictured in image 1 are 13 billion light years away. This is the beginning of everything as we know it. When you hear the term primordial soup, what is in Image 1 are the ingredients.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*l8idFQobOfJN30hGNJUq7g.jpeg" /><figcaption>The Earth</figcaption></figure><p>Somewhere about 9 billion years later, the earth shows up. Then sometime after that humans show up. In fact, if you take the past four or five billion years the earth has been in existence and compress that time down to one year, here’s what happens:</p><p><strong>January 1st</strong>: Our solar system and earth forms.<br><strong>April 1st</strong>: The first evidence of life like single celled organisms appear on April Fools Day. Coincidence? It can’t be the first time you have heard that this whole thing could be someones idea of a joke. <br><strong>April 30th</strong>: By the end of April, multi-celled organisms begin to appear but they are all just swimming around in the water.<br><strong>July 2nd</strong>: This is a test of the emergency life support system. The test is stating half the year has passed and there is still no life on land.<br><strong>Middle of July to November: </strong>Plants start to appear on land, fish crawl out of the ocean, mosquitos start flying, dinosaurs roam the earth, a catastrophic 100 million megaton meteor hits the Yucatan peninsula wiping out the dinosaurs.<br><strong>December 31, 12:00PM: </strong>With no dinosaurs left to snack on them, mammals have taken over and the first human like form arrives.<br><strong>December 31, 11:45PM: </strong>With mere minutes left to go, a Homosapien lights a fire, builds a stone wheel and kills something with a knife</p><p>Whether you believe humans were created by some otherworldly being that flicked us here with a pinky finger or humans crawled out of a swamp or a plague that rode in on a comet — you may argue that amongst yourselves at the lunch table.</p><p>Research has dated the first humans to have existed roughly 1 to 2 million years ago which brings us to:</p><h3><strong>Part Two: Humans</strong></h3><p>What set humans apart from other species occurred about 40,000 years ago. This image is from a cave in Spain called El Castillo. As you can see they may have just traced their hand on the wall but it is evidence of early creativity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*UtxeS4VCkzR04VPI8poWtg.jpeg" /><figcaption>El Castillo</figcaption></figure><p>The following image is from Lascaux cave in France from about 17,000 years ago. Humans begin to create a visual language. These cave paintings move away from tracing items to representations of what they are seeing. There have been many theories as to why cavemen started painting but there is no definitive answer. The top three theories so far are:</p><ol><li>They felt like it. Basically theres no reason for it, like graffiti in the bathroom.</li><li>People got high and started drawing. Possibly some sort of coming of age ritual took place and kids went into a shamanistic trance and freaked out on the wall.</li><li>A prehistoric encyclopedia. Away of keeping a record of what was witnessed and creating a way to communicate that experience.</li></ol><p>For the sake of this article, let’s go with theory number three. These cave paintings were a way to create a set of data, write this information down and have the ability to pass it along to another person easily and it went on like this for a while.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*h_SN6pGU-D_OE2vFGqhKxg.jpeg" /><figcaption>Lascaux Cave</figcaption></figure><h3>Part Three: Humans writing stuff in words on things.</h3><p>Around 3000BC, the ancient Sumerians invented Cuneiform. The Sumerians are located in Sumer, which is located between the Tigris and the Euphrates river near the Persian Gulf.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*YepTh1bo24vbnVz9yy-wvQ.jpeg" /><figcaption>Sumerians!</figcaption></figure><p>Cuneiform uses a reed stylus to make wedge shaped indentations in wet clay tablets. Combinations of these marks represented syllables that formed words. This language was primarily used by Akkadians and Sumerians to record business transactions, ownership rights and government records. So there you have it, the decline of civilization, as soon as humans are able to write somebody is either owed something or breaking the law. This image is a Sumerian Cuneiform clay tablet detailing the annual public works for the city of Umma from 2082BC. It is not only the transactions that are of note in these tablets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*9e4JO10lKVjCDM0t9uH-cA.jpeg" /><figcaption>2082BC — Sumerian Cuneiform clay tablet detailing the annual public works for the city of Umma.</figcaption></figure><p>There are no longer animals running wild on a wall. Recorded transactions seem to be compartmentalized into an organized system of columns and rows. So again, as soon as humans begin writing there seems to be a very compartmentalized organizational system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*l54QdGWppyqpIIJr2gJTrg.jpeg" /><figcaption>From Sumer to Egypt</figcaption></figure><p>Across the Arabian desert from Sumer to Egypt, the ancient Egyptians are the next civilization to develop a writing system. Instead of using marks to symbolize syllables like the Sumerians, the Egyptians used pictorial symbols to symbolize letters, syllables and names. Heiroglyphics can be read, left or right or up or down.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*v_6vJZMIi_9LPGp0WRNQhQ.jpeg" /><figcaption>Heiroglyphic can be read in different directions.</figcaption></figure><p>From the Egyptians we also have the first appearance of images mixed with script to illustrate their story to create a larger impact. The Egyptians were very prolific in their writing. They believed it was important to record and communicate information about religion, politics and government. They inscribed their stories on walls, temples, tombs, etc. Often these large images represented kings or gods and the script told their story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*xops3aNhssDxK8qVphm-fA.jpeg" /><figcaption>Large carvings of Egyptian gods mixed with text and large images.</figcaption></figure><p>After the Egyptians wrote on all the available walls and still had more to write in order to preserve more of their legacy, the Egyptians invented papyrus so instead of stabbing a reed into clay or carving into stone, the Egyptians invented pigment and used the reed to scribe a mixture of burnt organic materials and oil to write. The Egyptian papyrus writing was a cursive form of hieroglyphics called Hieratic script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0K_UdpOfPf05JJf-cGETGA.png" /><figcaption>Hieratic script on ancient Egyptian papyrus.</figcaption></figure><p>Notice there is still the compartmental division of ideas in the hieroglyphics and the Hieratic script.</p><p>We also have basically paper and ink. The process to create the papyrus and pigments were very complex and expensive but the material is way easier to roll up, keep in storage, and archive than a rock.</p><p>To visit the next civilization to develop writing, we have to go back across the Arabian desert on the other side of the Persian Gulf and hug the shore along the Arabian sea to enter the Indus Valley.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*cXJ4fyHJuo6C9jmogv-PgA.png" /><figcaption>From Egypt through Sumeria then over to The Indus Valley</figcaption></figure><p>At the same time cuneiform was in use, around 2500BC, thousands of soapstone seals from the Indus Valley have been discovered. Unfortunately, the Indus script has never been deciphered so nobody knows exactly what the seals were used for definitively. They may have been used for transactions with the script establishing quantities and ownership or possibly which animals needed to be sacrificed to please the souls of dead ancestors.</p><p>What is interesting about these seals is that there are the animals that resemble the early cave paintings combined with this far-out script that we assume is a language</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAhPxlPyB_I-EFTw_-kszQ.png" /><figcaption>Soapstone seals from the Indus Valley</figcaption></figure><p>These seals from the Indus Valley are another example of text and image but this seems to be the first time an image and text come together to represent a single idea in a single item.</p><p>Other cultures also developed new languages but the message is still carved into something and the ideas are still formatted in grid like rows or columns. Chinese, an extremely complex system of characters was first used about 1600BC. The Phoenician alphabet which is considered the first alphabet and very similar to Hebrew was first used about 1400BC. Arabic was first used approximately 500BC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xioz9SVfRyheGolf9kPTiw.png" /><figcaption>Arabic (left), Chinese (top right), Phoenician (bottom right)</figcaption></figure><h3>Part Four: Communication</h3><p>By 500BC, Egypt had cornered the market and most scribes were using papyrus to write on. Around 150BC, the Pharaoh Ptolemy V of Egypt refused to sell papyrus to King Eumenes of Perganum in Turkey. It wasn’t because there was a lack of papyrus or Eumenes owed Ptolemy anything. It was because the library of Perganum was getting to be too awesome.</p><p>Which brings us to the first head to head battle!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Vr_RNvGECWJEw7PuH_T8WQ.jpeg" /><figcaption>Paper Battle 1 — Ptolemy V vs. King Eumenes</figcaption></figure><p>Ptolemy was like hey buddy, screw you. Your library is getting better than Egypt’s so we are cutting off your Papyrus supply. Eumenes was like screw you Ptolemy, we’ll use parchment.</p><p>Papyrus plants only grew in Egypt so papyrus could only be manufactured in Egypt. Parchment was made from animal skin. Animals were everywhere, obviously. Preparing animal skins for writing has a very long history dating back again to Egypt. Compared to papyrus, parchment is really heavy and difficult to glue so you can’t get long scrolls like parchment.</p><p>Due to this conflict, Pergamon perfected the production of parchment. Due to the limited size and weight of parchment, pages were cut and the first books were created by King Eumenes in Turkey. Book were easier to flip back and forth and mark your spot. So parchment books are now the new trend for busy scribes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*aw9wbrRUlNVYVPwV1cZg9A.jpeg" /><figcaption>China</figcaption></figure><p>The next major advancement in our story brings us farther east to China. In China, people has a slightly different way of going about writing. Important documents are scribed on metal, jade, bamboo, bones which were all either crazy expensive or cumbersome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*KeRzdx4MghR3r7pZ4hgicg.jpeg" /><figcaption>Bone, bamboo and jade inscriptions</figcaption></figure><p>Around 150BC, a court eunuch names Cai Lun in the Eastern Han dynasty is credited with the invention of paper as well as the paper making process. The original recipe for paper was made from mulberry bark, bamboo, hemp and used fishing nets. Even though this new material was far lighter, less expensive and easier to write on than bones and bamboo, paper was not an immediate success. Legend has it that in order to impress people with the magical powers of paper, Cai Lun pretended to die, had himself buried in a coffin with a bamboo breathing tube. According to his instructions, people burned paper at his grave then he sprang up out of the ground perfectly alive.</p><p>After Cai Lun’s stunt mulberry paper gained instant popularity throughout Asia.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*pyVs6B57sVl_s6IFk6vHpg.jpeg" /><figcaption>Cai Lun</figcaption></figure><p>Around 220AD, woodblock printing is invented in China. It is mostly used for textiles because when text is involved, the characters need to be carved backwards. With this technique duplicate copies of the same document can now be made.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*XZTnix_iQ_1M9AFg-Opn1A.png" /><figcaption>Woodblock printing</figcaption></figure><p>In 751AD, Abbasid and Tang armies battle it out in the Talas River Valley to vie for control of the Syr Darya region of Central Asia. Chinese paper-makers were captured by Arabs in the Battle of Talas. Chinese paper-makers are captured and put to work in Samarkand, Uzbekistan making the Battle of Talas, Paper Battle Round 2! The paper-making process slowly spreads through the Muslim world and reaches Europe in the 12th century.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*f7SRztJJXoj0b4OuCzd3Gg.png" /><figcaption>Paper Battle Round 2.</figcaption></figure><h3>Part 5: Printing</h3><p>Moveable type is invented in China in 1040AD. The technique used porcelain tiles. Porcelain is very expensive. Ancient Chinese script contains thousands of characters that would need to be arranged by hand making the process extremely labor intensive. Moveable type in China is not all that popular.</p><p>By the 15th century, paper has made it’s way across Europe and books are being produced with various printing techniques. In 1440, Johannes Gutenburg perfects movable type with the printing press. His type is cast metal, not porcelain, and the Latin alphabet make it much easier to manage by hand. This remained the standard printing procedure for 550 years.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Yil9dj25DSow5vFdNPA0EA.jpeg" /><figcaption>The Gutenburg Printing Press (left), The Gutenburg Bible (right)</figcaption></figure><p>In order to demonstrate Gutenburgs invention… I know you really want Gutenburg to be buried alive but that didn’t happen. Gutenburg prints an affordable bible as an example of his printing press. This is the first major book printed using mass-produced movable metal type in Europe. The book is widely praised for its aesthetic and artistic qualities and immediately achieves iconic status. Other printing processes have cropped up through the years but no processes made an impact on the standard printing process more than the printing press. There’s mezzotint, aquatint, chromolithography, mimeograph, screen printing, inkjet, laser prints but all these processes are still delivering information to paper.</p><p>Then on October 29, 1969 a UCLA student named Charley Kline attempts to transmit the text “login” to a computer at Stanford over the Arpanet, a precursor to the internet. After the letters L and O were transmitted and received. The system crashed but “lo” and behold a new medium was born.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mjOAS9Y9kQVEGjkQe40_Tw.png" /><figcaption>The Arpanet at UCLA</figcaption></figure><h3><strong>Part 6: Recap</strong></h3><p>Technology is constantly being updated but the grid format of text and images, the way our brain receives information, remains unchanged from hieroglyphics to today’s cellphones.</p><p>in 3000 BC hieroglyphics used pictorial symbols to represent a language. today we use emojis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*prYlQxzedbDGzlxwsxz6_w.jpeg" /><figcaption>Hieroglyphics (left), Emojis (right)</figcaption></figure><p>Heiroglyphics also paired texts with images of gods and kings. Today we have superheros in comic books!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*fMjbP7Nwi3njqoKbQ-JbOQ.png" /><figcaption>Hieroglyphics (left), Superman comic book (right)</figcaption></figure><p>in 2500 BC, seals from the India represented a single idea with an image. Today we have memes!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*KRCFDc91lCb3sklKDcfUzA.png" /><figcaption>Soapstones from the Indus Valley (left), memes (right)</figcaption></figure><p>in 1440 AD, the Gutenberg bible sets the standard for printing.<br>Our designs for content on the internet is still based on a similar 12 column grid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXCdDT3gTxHRpGXO_q2YCA.png" /><figcaption>12 column grid on the Gutenberg Bible</figcaption></figure><p>Technology is changing faster than ever and we work hard to keep up but the basic format in which we receive and process written communication has not changed all that much since humans first put a reed to a clay tablet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NP7Zj37ab2zaTahETcjmiQ.png" /><figcaption>iOS layout compared to a Sumerian Cuneiform tablet.</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f29f8095bb49" width="1" height="1" alt=""><hr><p><a href="https://medium.com/type-faster/a-shallow-history-of-humans-and-communication-design-f29f8095bb49">A Shallow History of Humans and Communication Design</a> was originally published in <a href="https://medium.com/type-faster">Type Faster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Plotting a simple SVG]]></title>
            <link>https://medium.com/type-faster/plotting-a-simple-svg-67aa407fda87?source=rss----55d1797f8f21---4</link>
            <guid isPermaLink="false">https://medium.com/p/67aa407fda87</guid>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[gsap]]></category>
            <category><![CDATA[sketch]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Ändrëw Fïtzpätrïck]]></dc:creator>
            <pubDate>Sat, 01 Jul 2017 02:29:28 GMT</pubDate>
            <atom:updated>2017-07-10T16:16:41.505Z</atom:updated>
            <content:encoded><![CDATA[<p>We ran into a few glitches here the other day at <a href="http://www.redshiftdigital.com/">Redshift Digital</a> creating a GSAP animation with a simple SVG path. You would think with all the tools available this would not be too hard. Well, guess what? Sometimes there is too much technology and too many options. In order to help you avoid some of our mind boggled moments unraveling the vector mystery, here is a little workflow outlining part of the process.</p><p>The first hurdle was the asset for the SVG. This example, shows screenshots of Sketch. The asset to start our animation was a minefield of broken plots and dreams, disconnected paths and missed connections (Image 1). Exporting this SVG from Sketch and opening it in a text editor contains multiple paths, cryptic long numbers that are all transformed, translated and rotated. Plus, who knows what direction the thing is going in? Yes, direction is a thing since the animation goes from beginning to end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kmkn5_EN0tu51x1IKEanAQ.jpeg" /><figcaption>Image 1</figcaption></figure><p>Super messy SVG code from Image 1:</p><pre>&lt;svg viewBox=&quot;0 0 577 131&quot;&gt;<br>    &lt;g id=&quot;Nodes-v2&quot; stroke=&quot;none&quot; stroke-width=&quot;1&quot; fill=&quot;none&quot; fill-rule=&quot;evenodd&quot;&gt;<br>        &lt;g id=&quot;Artboard-Copy-13&quot; transform=&quot;translate(0.000000, -142.000000)&quot;&gt;<br>            &lt;g id=&quot;Group&quot; transform=&quot;translate(-12.000000, 142.000000)&quot;&gt;<br>                &lt;path d=&quot;M294.234899,100 C294.234899,83.4314575 280.818116,70 264.267676,70&quot; id=&quot;Oval-2&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; transform=&quot;translate(279.251288, 85.000000) rotate(-90.000000) translate(-279.251288, -85.000000) &quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M264.267676,130 C264.267676,113.431458 250.850893,100 234.300453,100&quot; id=&quot;Oval-2-Copy&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; transform=&quot;translate(249.284064, 115.000000) rotate(-270.000000) translate(-249.284064, -115.000000) &quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M517.234899,40 C517.234899,23.4314575 503.818116,10 487.267676,10&quot; id=&quot;Oval-2&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; transform=&quot;translate(502.251288, 25.000000) rotate(-90.000000) translate(-502.251288, -25.000000) &quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M487.267676,70 C487.267676,53.4314575 473.850893,40 457.300453,40&quot; id=&quot;Oval-2-Copy&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; transform=&quot;translate(472.284064, 55.000000) rotate(-270.000000) translate(-472.284064, -55.000000) &quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M0.991208961,130 L228.5,130&quot; id=&quot;Line-Copy-3&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;square&quot; stroke-dasharray=&quot;1&quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M295,70 L460,70&quot; id=&quot;Line-Copy-4&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;square&quot; stroke-dasharray=&quot;1&quot;&gt;&lt;/path&gt;<br>                &lt;path d=&quot;M518.5,10 L569.5,10&quot; id=&quot;Line-Copy-6&quot; stroke=&quot;#DDDDDD&quot; stroke-width=&quot;2&quot; stroke-linecap=&quot;square&quot; stroke-dasharray=&quot;1&quot;&gt;&lt;/path&gt;<br>                &lt;circle id=&quot;Oval-3-Copy-4&quot; fill=&quot;#BF3C95&quot; cx=&quot;579&quot; cy=&quot;10&quot; r=&quot;10&quot;&gt;&lt;/circle&gt;<br>            &lt;/g&gt;<br>        &lt;/g&gt;<br>    &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>The first thing needed is a clean path from beginning to end on an Artboard. Create that path on the Artboard in about the location of where you are going to need it in the design. Image 2 is an example of a clean path on an Artboard in Sketch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*k9LA9DJJ2RsSixE1R8hGnQ.jpeg" /><figcaption>Image 2</figcaption></figure><p>Ok, great! We have a nice clean simple path but when this path is exported from sketch, the G element in the SVG still has a transform applied.</p><p>Much cleaner SVG code from Image 2 with path selected:</p><pre>&lt;svg viewBox=&quot;0 0 573 120&quot; version=&quot;1.1&quot;&gt;<br>    &lt;g id=&quot;Page-1&quot; stroke=&quot;none&quot; stroke-width=&quot;1&quot; fill=&quot;none&quot; fill-rule=&quot;evenodd&quot; stroke-linecap=&quot;square&quot; stroke-dasharray=&quot;1,1&quot;&gt;<br>        &lt;g id=&quot;Artboard&quot; transform=&quot;translate(0.000000, -99.000000)&quot; stroke=&quot;#DCDCDB&quot; stroke-width=&quot;2&quot;&gt;<br>            &lt;path d=&quot;M0,218 L235,218 C251.569,218 265,205.552 265,189 C265,172.151 278.432,159 295,159 L461,159 C477.569,159 490,146.55 490,130 C490,113.451 504.432,100 521,100 L572,100&quot; id=&quot;1&quot;&gt;&lt;/path&gt;<br>        &lt;/g&gt;<br>    &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>This seems like it might not be a big deal but it is hurdle number two. You do not want SVG code to include a transform. Transforming the SVG is saying draw this path but move it over here. Animating an SVG with the <a href="https://greensock.com/morphSVG">GSAP MorphSVG plugin</a> is manipulating the path. If other animations are relying on this path, they are going to follow along the path but they will be below and over to the left or some other weird direction.</p><p>So how do you get a path from Sketch that is relative to the Artboard? This question took much longer to answer than I care to admit. I looked through preferences, <a href="https://stackoverflow.com/">Stack Overflow</a>, googled all kinds of related terms then accidentally figured it out. In Sketch, make only the working path visible (Image 2), select the Artboard and export the Artboard as the SVG instead of selecting and exporting one path.</p><p>Now when you open the SVG in a text editor, it still probably has some long numbers but it is a lot more digestible and there should no longer be any transforming going on.</p><p>Image 2 SVG code with Artboard selected (slightly edited):</p><pre>&lt;svg viewBox=&quot;0 0 1440 1050&quot;&gt;<br>  &lt;g&gt;<br>    &lt;path d=&quot;M0,218 L235,218 C251.569,218 265,205.552 265,189 C265,172.151 278.432,159 295,159 L461,159 C477.569,159 490,146.55 490,130 C490,113.451 504.432,100 521,100 L572,100&quot; id=&quot;1&quot;&gt;<br>    &lt;/path&gt;    <br>  &lt;/g&gt;<br>&lt;/svg&gt;</pre><p>Here’s the stuff you need to know for a good SVG path.</p><p>1. &lt;svg viewBox=”0 0 1440 250”&gt; The last two numbers are the width and height of the SVG. In the SVG tag, it’s also helpful to check out the <a href="https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/preserveAspectRatio">preserveAspectRatio</a> tag for alignment. SVG does not follow typical behavior for CSS rules.<br>2. &lt;g&gt; Create your own class or id here and use CSS for stroke, fill, colors, etc.<br>3. &lt;path d=M###,### L###,### C###,### ###,### ###,###&gt; Here’s the real meat of the SVG.</p><p><strong>What do all those letters and numbers mean in the path?</strong><br><strong>M###,###</strong> — This is the x, y position of the starting vector point.<br><strong>L###,###</strong> — This is the x, y of a straight line vector with no handles in the path.<br><strong>C###,### ###,###</strong> — This is the x, y position of a curved line. C numbers are the x, y of the bezier handle. The next set of numbers is the vector point.</p><p>Using this technique, changes can be made to the points in the Sketch file, and the x, y positions should correspond directly to the data in the D element of the SVG. (image 3)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*9qbKvMJSeqZ8Ue-PnF1mLw.jpeg" /></figure><p>Instead of re-exporting, opening in a text editor, finding which SVG to update and pasting code in the project, now only the numbers in the D element of the SVG need to be edited.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=67aa407fda87" width="1" height="1" alt=""><hr><p><a href="https://medium.com/type-faster/plotting-a-simple-svg-67aa407fda87">Plotting a simple SVG</a> was originally published in <a href="https://medium.com/type-faster">Type Faster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Javascript based media queries using React, Redux, and window.matchmedia]]></title>
            <link>https://medium.com/type-faster/js-media-queries-md-a18b41a9a28e?source=rss----55d1797f8f21---4</link>
            <guid isPermaLink="false">https://medium.com/p/a18b41a9a28e</guid>
            <category><![CDATA[react-redux]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[responsive-web-design]]></category>
            <dc:creator><![CDATA[Daniel Bernardi]]></dc:creator>
            <pubDate>Wed, 28 Jun 2017 22:38:11 GMT</pubDate>
            <atom:updated>2018-06-22T22:39:36.390Z</atom:updated>
            <content:encoded><![CDATA[<p>During a recent experiment, I thought it would be interesting to duplicate some of the css media query functionality inside of the jsx environment of our react stack. JSX actually lends itself quite well to this approach. React already opened the floodgates to combining our presentation layer with our logic layer. I theorized that it might be useful to pull much of our responsive work into the view as well.</p><p>This lead us down the path of recreating media queries as a series of javascript functions, allowing us to programmatically serve unique classes, components, and inline styles based on the viewports breakpoint state.</p><p>We had played with simpler versions of this in the past, namely attaching handlers to the window.resize event that check when the viewport size crossed our breakpoint thresholds, but it proved clunky and hard to manage, requiring a lot of boilerplate when you wanted to watch more than one or two breakpoints.</p><p>While something like this is workable:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f58a0ee39b33487f8e49072c3ebd54d/href">https://medium.com/media/6f58a0ee39b33487f8e49072c3ebd54d/href</a></iframe><p>It’s not very versatile, and can quickly become a nightmare when building a large scale web app with a dozen different breakpoints.</p><p>Luckily, a few tools became available that made this kind’ve work a lot more viable, so we went about developing a pattern that would be easy to use for small and large scale web apps alike. It made sense to integrate this pattern into our normal stack. Namely React and Redux.</p><p><strong>The problem:</strong> Serve dynamic content / layouts based on viewport size, without having to resort to assigning unique one-off classes to elements, as is typical in responsive work.</p><p><strong>The solution:</strong> Using Redux and window.matchmedia, we reproduce CSS’s basic media query functionality in javascript, allowing us to serve unique classes, components, and inline styles that swap as the breakpoints change. This allows us to create hyper modular — higher level css rules without having to account for a lot of the one-off styles typically necessary in responsive work.</p><p>We simply serve the appropriate classes for the matched media query. This allows us to write one set of modular classes, rather than a unique class per element that specifies all the css rules for each breakpoint.</p><p>For example, instead of something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87e10d05ec1d670ce207806e7e16c12c/href">https://medium.com/media/87e10d05ec1d670ce207806e7e16c12c/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6dfdbc42da8abaa8e03e0e94bfc71e87/href">https://medium.com/media/6dfdbc42da8abaa8e03e0e94bfc71e87/href</a></iframe><p>We can write something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/260e7a6556a072b4742db8acc64be47d/href">https://medium.com/media/260e7a6556a072b4742db8acc64be47d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7083ca9742f61eb7c6f136506d8eb2c5/href">https://medium.com/media/7083ca9742f61eb7c6f136506d8eb2c5/href</a></iframe><p>I’ll discuss the syntax further along, suffice it to say we’re now using a new setClass function to serve a different class based on the currently matched breakpoint. The compiled result that shows up in the DOM will be as such:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/124e9a88109a1325c2e8e6b775011eeb/href">https://medium.com/media/124e9a88109a1325c2e8e6b775011eeb/href</a></iframe><p>The main difference is that instead of creating a single .heading class that can only be used for headings, we create 3 modular classes that can be used anywhere on any element, and we control where and when they show up using a reproduction of the css media query functionality in our javascript. The media queries are successfully offloaded from the css file into the jsx file. This allows us to drastically reduce the size of our css files, as well as craft a more modular rather than element specific stylesheet.</p><h3>How it works</h3><h4>1. Create the AppWrapper</h4><p>Firstly, you’ll need an AppWrapper component. The only requirement for this component is that it mounts at the start of your app, and stays mounted until your app is closed. This component will house the event handler for your changing breakpoints, and will also communicate with your store to report the active breakpoints on initial mount as well as updating the store with the new breakpoint value as the window is resized</p><p>Create a new component called AppWrapper.jsx. It can start out fairly simple. Right now, just a basic component that returns its children wrapped in a div. It uses redux’s connect function to connect to the store. This will allow us to use this.props.dispatch in a later step.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb88c3efa5ecf8a4a27520914bbfbbc2/href">https://medium.com/media/fb88c3efa5ecf8a4a27520914bbfbbc2/href</a></iframe><h4>2. Create the responsiveHelpers file</h4><p>Next, create a simple utils file called responsiveHelpers.js and save it in a new utils folder. This is where we&#39;re going to house a few helper functions, as well as define our breakpoints. You can define whichever breakpoints you prefer. Just make sure to list them from largest to smallest (this is assuming a desktop first responsive system).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ff56f41ee8d84a8f027afffcf63bb64/href">https://medium.com/media/1ff56f41ee8d84a8f027afffcf63bb64/href</a></iframe><h4>3. Setting up our event handler</h4><p>Return to the AppWrapper file. We’re going to add our event handler and dispatch our actions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4c223f00f28cbb6e7373d5a5594946d/href">https://medium.com/media/b4c223f00f28cbb6e7373d5a5594946d/href</a></iframe><h4>4. Creating the action &amp; reducer</h4><p>Add the setActiveBreakpoint action to your actions file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7252750be70fe4d3b79736a86b6c0b57/href">https://medium.com/media/7252750be70fe4d3b79736a86b6c0b57/href</a></iframe><p>Next, add the breakpoint reducer to your reducers file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6eb36dce4501469a0c0357680704f16e/href">https://medium.com/media/6eb36dce4501469a0c0357680704f16e/href</a></iframe><h4>5. Creating the helper functions</h4><p>Return to the utils/responsiveHelpers.js file. We are now going to create a few helper functions that will allow us to interface with our new breakpoint system. First up, the setClass function that we used in the initial example. This function will accept two parameters, the first of which, classObj, is an object with key value pairs describing which strings should be returned for which matched breakpoints. The second parameter, breakpoint, will be the breakpoint object from the store that we dealt with in the previous section.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db2c38f1b48c5629b6025c6a5bd059fa/href">https://medium.com/media/db2c38f1b48c5629b6025c6a5bd059fa/href</a></iframe><p>Next, we are going to add two additional helper functions: breakpointIsGreaterThan and breakpointIsLessThan. These functions return a boolean and can be used inside ternery operators to conditionally load or hide components and jsx elements.</p><p>Firstly, let’s add a helper that will make these functions easier to use. This function simply allows us to use a string to represent the breakpoint parameter and queries it against the breakpoints object we created in step 2.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c765194f618f85304539c69bfbf4ec6/href">https://medium.com/media/8c765194f618f85304539c69bfbf4ec6/href</a></iframe><p>Now, the two helper functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab96a7d4216bed6cea01e4a17c905a9e/href">https://medium.com/media/ab96a7d4216bed6cea01e4a17c905a9e/href</a></iframe><h4>5. Putting it all together</h4><p>We are now ready to start using our new breakpoint system in our components. A bit of boilerplate needs to be added to any component that wants to make use the breakpoint system.</p><ol><li>The component must subscribe to the breakpoint object in the store.</li><li>The utils functions need to be imported from responsiveHelpers</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/850d3e2171c427e9dc6087595856e791/href">https://medium.com/media/850d3e2171c427e9dc6087595856e791/href</a></iframe><p>The setClass function is commonly used to return string classes, but can also be used anywhere else a string can be served. For example, another common use case is to responsively serve inline styles:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3e78a59d2f57193c80afb9f9b09be838/href">https://medium.com/media/3e78a59d2f57193c80afb9f9b09be838/href</a></iframe><p>The breakpointIsGreaterThan and breakpointIsLessThan functions are commonly used in conjunction with ternery operators, as well as within if / else statements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a0d44e1c7b828b91078babafa5872b3/href">https://medium.com/media/6a0d44e1c7b828b91078babafa5872b3/href</a></iframe><p>That’s pretty much it. These 3 functions are pretty versatile and should allow us to recreate much of the functionality of traditional css media queries.</p><h4>6. Browser support</h4><p>Browser support is pretty good. The only aspect that is of any concern is the use of the window.matchMedia API, which is supported in all modern browsers, going as far back as IE10.</p><p>IE9 and below will need an alternate solution. It is possible to attach the event handler to the window.resize event, in which case a generous debounce should be used to cut down on the amount of times the event is called during a resize.</p><p>I’m not recommending migrating 100% of your media queries into your JSX files. In our client projects, we have used this pattern to supplement traditional media queries, not replace them outright. It’s about giving us options, and in the end it has resulted in much smaller, easier to manage CSS files.</p><p>Daniel is a front-end engineer at [Redshift Digital](<a href="https://www.redshiftdigital.com/">https://www.redshiftdigital.com</a>) in San Francisco.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a18b41a9a28e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/type-faster/js-media-queries-md-a18b41a9a28e">Javascript based media queries using React, Redux, and window.matchmedia</a> was originally published in <a href="https://medium.com/type-faster">Type Faster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Watching a class for changes, in javascript]]></title>
            <link>https://medium.com/type-faster/watching-a-class-for-changes-in-javascript-ca861ab8df3e?source=rss----55d1797f8f21---4</link>
            <guid isPermaLink="false">https://medium.com/p/ca861ab8df3e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[observables]]></category>
            <dc:creator><![CDATA[Rick Takes]]></dc:creator>
            <pubDate>Thu, 15 Jun 2017 02:49:59 GMT</pubDate>
            <atom:updated>2017-06-15T17:26:12.840Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Td3I1v6xtfJdHAiKNO54HA.jpeg" /></figure><p>There are many cases in which it would be useful to watch a class and respond if it has been updated, either internally or externally. One example would be game update loops. If you are familiar with React, think of how `this.state` works and causes a re-render when updated.</p><p>Utilizing ES6 classes and a proxy / handler it is possible to pass a callback when instantiating the class. This callback will fire when a specified property is added or modified, essentially allowing us to subscribe to those changes.</p><p>Let’s jump into the code.</p><h3>Create the class</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66f15ac8f8472ce66ddc15c1dae7214e/href">https://medium.com/media/66f15ac8f8472ce66ddc15c1dae7214e/href</a></iframe><p>Nothing too special happening here. We create our class and set up a bit of logic to allow for default options and for options to be specified when the class is instantiated.</p><h3>Add the handler</h3><p>Next we’ll create our updateHandler which the proxy will use to process updates:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a582ab46ddb62f8692e9e90222a2c93e/href">https://medium.com/media/a582ab46ddb62f8692e9e90222a2c93e/href</a></iframe><p>Our update handler defines a function, set which we’ll use with proxy to intercept updates to the classes’ state and apply some additional logic. The set function takes four arguments: target , property , value , and receiver . For more on these checkout the docs on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/set">MDN</a>.</p><p>The notable lines above are:</p><pre>obj[prop] = value;<br>obj.onUpdate();</pre><p>The first sets the property and value, no surprises here. The second fires onUpdate which we’ll create next, along with adding the state and proxying the set function to our handler.</p><h3>Add state and proxy</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/202d61dd9bd5f7ab8c8951b6407e2ec8/href">https://medium.com/media/202d61dd9bd5f7ab8c8951b6407e2ec8/href</a></iframe><p>We’ve just created our state object and provided the updateHandler . We’ve also defined a function, classStateDidUpdate , and assigned it to onUpdate which we used above. classStateDidUpdate will fire after a value is set on classState pass the state object as an argument to a provided callback.</p><h3>All together now</h3><p>Putting it all together, we’ll instantiate our class and pass it the update callback:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68f63198d43028b0b79e35bc7725446e/href">https://medium.com/media/68f63198d43028b0b79e35bc7725446e/href</a></iframe><p>Now we have a function, updateWatcher , which will be called when the classState is updated on our newly instantiated class.</p><h3>Result</h3><p>To see it in action paste the above gist into the developer console and then type: ourClass.updateState(&#39;testProp&#39;, &#39;testValue&#39;) . You should get a response that looks like the following, confirming that the value was set and that our callback fired.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*NQyWpHF7gxqwMa7pytIKvQ.png" /><figcaption>Note the ‘test’ key with value ‘test-value’</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca861ab8df3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/type-faster/watching-a-class-for-changes-in-javascript-ca861ab8df3e">Watching a class for changes, in javascript</a> was originally published in <a href="https://medium.com/type-faster">Type Faster</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>