<?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[Stories by Lauren Tan on Medium]]></title>
        <description><![CDATA[Stories by Lauren Tan on Medium]]></description>
        <link>https://medium.com/@sugarpirate?source=rss-a4c91dcedec4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*zGpA4hZZjRb-yNIra34goA.jpeg</url>
            <title>Stories by Lauren Tan on Medium</title>
            <link>https://medium.com/@sugarpirate?source=rss-a4c91dcedec4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 18:44:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sugarpirate/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Exploring the Strongly Typed Graph]]></title>
            <link>https://medium.com/@sugarpirate/exploring-the-strongly-typed-graph-31fc27512326?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/31fc27512326</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Sun, 28 Oct 2018 01:53:04 GMT</pubDate>
            <atom:updated>2018-10-29T15:52:17.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9JZtMYLuKrpfQY6HQ_WEA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/m7q5iX4L7vQ?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Benjamin Hung</a> on <a href="https://unsplash.com/photos/CCKcwh7s9A4?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>The “Strongly Typed Graph” is something I’ve been thinking about lately. I believe it could significantly improve developer productivity in large, microservice heavy organizations.</p><p>To be clear, this is still an exploration. An early idea I wanted to throw out there. But before I dive into what it is and what it could solve, let me give you some context about our problem, and why I think this idea is compelling.</p><p><em>⚠️ Warning</em>: It may not solve the exact problem that you have. Read more and decide for yourself, this is not a silver bullet or a “best practice”.</p><p>👩🏻‍💻 I assume some basic knowledge of <a href="https://grpc.io/">gRPC</a>/<a href="https://thrift.apache.org/">Thrift</a>, <a href="https://graphql.org/">GraphQL</a> and <a href="https://www.typescriptlang.org/">TypeScript</a>/<a href="https://flow.org/">Flow</a>.</p><h3>Move fast and learn things</h3><p>I currently work in a large, microservice heavy organization. Microservices have worked well for us given our loosely coupled org structure. We optimize for rapid learning and innovation in our respective business sub-domains. The larger domain being entertainment, for content creation at scale. Think creating thousands of high quality shows (movies and TV series) a year, across domains such as financing, production, business/legal obligations, casting/staffing of productions, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*II3IKcf1BWtrT6cmbdSfJg.png" /><figcaption>“Organizations which design systems … are constrained to produce designs which are copies of the communication structures of these organizations.” — M. Conway</figcaption></figure><p>We moved fast, building a core set of applications in a few years. But, these applications were silos, and disconnected from each other. We would update something in one, and wonder why it wasn’t updated in the other.</p><p>This was the price of moving fast and breaking things. It was impossible at the time to understand what the larger domain was. In hindsight, these connections are obvious. But in the beginning, it was like foraging for a random selection of mushrooms in a forest. Only to later discover that they all share <a href="https://www.scientificamerican.com/article/strange-but-true-largest-organism-is-fungus/">deep, interconnected roots</a>.</p><h3>Everything is a graph</h3><p>Creating content is a creative process, and made possible by the collaboration of different business units. Creating a new show is like creating a startup. You worry about where the money is going to come from. Who’s the CEO and COO? Is the business model sound? How will we hire people to do the work?</p><p>In entertainment, it’s the same questions. How we will finance the show? Who will be the showrunner (for TV), or director (for movies)? Is the script any good? How will we cast actors and actresses, and hire the best grips, editors, camera operators, and more?</p><p>In moving fast, we were also able to learn fast. We learned that these sub-domains made up a larger graph. And that we needed to connect them together to truly push the business forward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*lsQ-lcLu2J080Ym1dpy-tw.png" /><figcaption>Example graph from neo4j movie dataset</figcaption></figure><h3>Move fast and grow the network</h3><p>We needed to ensure our data was consistent across domains, but allow teams to independently evolve their sub-domains. The challenge–the tension between correctness and productivity that is difficult to balance, especially in large organizations.</p><p>We want teams to be able to accelerate their rate of innovation, but in a way that makes the collective network stronger.</p><h4>End-to-end type coverage</h4><p>The idea of end-to-end type coverage is simple and compelling. It is the combination of strongly typed technologies such as gRPC/Thrift, GraphQL, and TypeScript/Flow across the stack, from backend to frontend. If you’re interested in learning more about type systems, check out my talk below at <a href="https://youtu.be/y3uXazpAdwo">React Rally 2018</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fy3uXazpAdwo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dy3uXazpAdwo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fy3uXazpAdwo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5c98ff6b532fea73dfa77bf3538b295/href">https://medium.com/media/d5c98ff6b532fea73dfa77bf3538b295/href</a></iframe><p>Type systems are not new inventions. You may have used a strongly typed language like Java, C#, Go, Rust, and more. The static type systems you’re familiar with give you compile time guarantees. They guarantee that the code <em>you</em> have written is type safe. They don’t guarantee that the services you <em>depend on</em> are type safe.</p><p>In other words, they can’t provide any runtime type guarantees (not the same as runtime type checking). You may trust that some JSON has <em>foo, bar</em>, and <em>baz</em> defined, but an external service could return otherwise. A <a href="https://github.com/gcanti/io-ts">TypeScript library</a> (<a href="https://github.com/gcanti/io-ts"><em>io-ts</em></a> by the amazing <a href="https://medium.com/u/bde030ef1bdb">gcanti</a>) does exist for a runtime type system, interestingly enough.</p><p>io-ts aside, having end-to-end type coverage won’t provide any runtime type guarantees. Services can and will fail in ways you don’t expect. An end-to-end type system is not meant to give you type safety at runtime boundaries, but it enhances type safety for dependencies at compile time.</p><p>Picture this. You’re at your editor, coding up a storm for a new client-side UI. A VS Code extension allows you to hook up to any GraphQL endpoint, and immediately receive type information. Because it’s subscribed to the endpoint, it can also alert you when fields you’re using break (their type changes, or they’re removed/deprecated). In real time.</p><h3>Highly Aligned, Loosely Coupled</h3><p>The “Strongly Typed Graph” builds upon end-to-end type coverage and connects diverse domains into a single graph. It gives teams near real-time visibility of how changes in the larger graph affect your entire organization. As a reminder, this architecture is still only an exploration!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y140aFlCjLSsU0iZQvYpLA.png" /><figcaption>Architecture for the Strongly Typed Graph</figcaption></figure><p>What’s exciting about this are just some of the possibilities at various levels in the organization:</p><ul><li>autocompletion in your editor/IDE while building client UIs. See new fields “come online” as other teams evolve the graph, right in your editor</li><li>understanding how long using a field in the graph will impact your page load time</li><li>pull request feedback when a change in your schema is going to break clients of that data</li><li>email/slack notifications when field(s) you rely on become deprecated or changed in a breaking fashion (type change or removal)</li><li>transform/map low level IDLs to product facing GraphQL schemas</li><li>visibility into how the larger graph evolves over time</li><li>(not in the diagram) orchestrate distributed writes across multiple systems</li></ul><p>There are a few major pieces to this proposed architecture. The two I want to highlight are the schema registry, and the domain graph itself.</p><h4>Schema registry</h4><p>The schema registry stores and handles the analysis of GraphQL SDLs (Schema Definition Language). Microservices push their schema changes to the registry before deployment. The registry tracks how schemas change over time and alerts users of specific fields whenever there are deprecations or removals. These alerts can surface through various hooks, for example in GitHub/Bitbucket pull requests, emails, Slack notifications, and more.</p><p>If you rely on a field from the domain graph, you should receive an alert if it’s deprecated or removed. You should also receive an alert when you make a change that will break clients.</p><h4>Domain graph</h4><p>The domain graph retrieves GraphQL SDLs from the schema registry, and stitches them together. Incoming requests include client metadata, so we can track field usage on a per client basis. Reads/writes should passthrough to the respective microservice. Being a single access point, this service must be highly available.</p><h3>How does this work in practice?</h3><p>The goal is to improve correctness and productivity across a large organization. Tooling still needs to be built, but some of these things (such as schema management) are already being worked on by <a href="https://apollographql.com/">Apollo</a>. For example, <a href="https://www.apollographql.com/engine">Apollo Engine</a> is a SaaS that they’re building that gives insights into performance, schema validation and so forth.</p><p>I haven’t seen this topic discussed heavily yet, so it’s still pretty early in the adoption curve. This is a <a href="https://www.youtube.com/watch?v=S93i9wuZRhA">video</a> that discusses the idea of an end-to-end type system. It’s one of the only resources on this topic I’ve found so far.</p><p>If you are building something similar, I would love to hear more about your experience.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31fc27512326" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Commit to Commit]]></title>
            <link>https://medium.com/art-of-engineering/commit-to-commit-a18befcb5e26?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a18befcb5e26</guid>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[commitment]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Wed, 28 Feb 2018 18:01:00 GMT</pubDate>
            <atom:updated>2018-02-28T18:01:00.960Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yVnUgLfOC_LoTjrjJCJHVA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/srd-rZ5fcFw?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Igor Ovsyannykov</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Commitment can be terrifying. Broken promises are the surest way down the waterslide of low morale.</p><p>When someone comes to you with a problem, don’t react immediately. Commit to commit, then follow up quickly. Give a specific date when you’ll get back to them with a commitment. “Thanks for the context about the bug, I’ll get back to you tomorrow morning with a decision on how we’ll move forward”.</p><p>Keep the window short. Hearing “I’ll get back to you” without the follow up will quickly lose the trust your customers have in your team.</p><p>This doesn’t only apply when speaking with customers. Whenever you need time to understand and think about a decision–commit to commit–be it your manager, your peers, or your parents.</p><h4>Move forward without hesitation</h4><p>Commitment is important, because it creates clarity around direction and priorities for your team. Your team can be better aligned around common objectives, and it develops an ability to learn from mistakes.</p><p>When you commit to commit, your team has a chance to understand what your customer is saying, why they’re feeling that way, and where they’re coming from. You get the chance to come back with a solid answer that the whole team has bought into.</p><p>In my next post, I plan to write about what I’ve learned <a href="https://twitter.com/patricklencioni">Patrick Lencioni</a>’s book, “The Five Dysfunctions of Team”. I’ll also share how my team applies it.</p><p>Thanks for reading! 😊</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a18befcb5e26" width="1" height="1" alt=""><hr><p><a href="https://medium.com/art-of-engineering/commit-to-commit-a18befcb5e26">Commit to Commit</a> was originally published in <a href="https://medium.com/art-of-engineering">Art of Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Engineer’s Guide to Communication]]></title>
            <link>https://medium.com/art-of-engineering/an-engineers-guide-to-communication-99180699a0e6?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/99180699a0e6</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[communication]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Mon, 26 Feb 2018 07:06:39 GMT</pubDate>
            <atom:updated>2018-02-27T04:31:40.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtpgypiNQaWKO6TJr1XkAw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/kGoHnMl01z0?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Abigail Keenan</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>It’s far too easy to be misunderstood. Trying to get your idea or point across to someone can often feel frustrating and difficult.</p><p>You’re not wrong for feeling like you, or they, just don’t get it. It’s tempting to believe that maybe you were never meant to be a good communicator, let alone a public speaker, or an engineering lead. Worse, you may think poorly of someone because they can’t seem to understand what you’re trying to say.</p><p>Communication is inherently lossy. What you don’t say is as important as what you do say. How you say it can matter more than what you actually say. It’s even lossier in writing. Communication will likely never be lossless, until we can communicate telepathically, I suppose.</p><p>That doesn’t mean you shouldn’t try–I’ve been awkward and shy my whole life, and being a good communicator takes extra effort on my part. But it’s important that I try, even if it’ll never be perfect. Things don’t get better without effort.</p><h4>“Computers are easy; people are hard”</h4><p>As an industry, we solve problems with technology. That’s what we were hired to do. The mistake is that we tend to also see communication and people issues as problems we can solve with technology. I’ve been personally guilty of this on more than one occasion.</p><p>Why should we learn how to communicate better? It’s because more often than not, software problems tend to be <a href="https://blog.fogcreek.com/all-software-problems-are-people-problems-interview-with-roy-osherove/">people problems</a>.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FgRHyhbYlBfw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DgRHyhbYlBfw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FgRHyhbYlBfw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/26285bac4cd1c2963fb9afcd41ccb3ae/href">https://medium.com/media/26285bac4cd1c2963fb9afcd41ccb3ae/href</a></iframe><p>It’s easy to believe that, if only we used <a href="https://queue.acm.org/detail.cfm?id=3185224">containers</a>, microservices, serverless, or <a href="https://github.com/kelseyhightower/nocode">nocode</a>–that just by using this new technology, we will solve all our problems. Take microservices, for example.</p><p>Netflix is famous for supposedly “writing the book” on microservices. You might be forgiven to think that Netflix is successful because we have a microservice architecture. And that if you use it too, you could be as successful.</p><p>No. There are <a href="http://worrydream.com/refs/Brooks-NoSilverBullet.pdf">no silver bullets</a>. There may never be one in our industry. If you’re not at Netflix’s size, microservices won’t help you, they will in fact slow you down with added complexity. Microservices are not a technical solution. They’re an organizational optimization. They are a way to allow teams to operate at scale, only if they are communicating effectively first.</p><h4>Listen first, understand second, speak last</h4><p>To communicate effectively, I practice a simple rule. When I speak with others, I seek to <a href="https://youtu.be/8l-YpiiBH4o?t=612">listen first, understand second, and speak last</a>.</p><p>When I listen first, I give others a chance to be heard. Everyone wants to be heard.</p><p>When I ask questions, I understand what they mean, where they’re coming from, and why they have the opinions that they have.</p><p>I speak last, because I get the benefit of hearing everyone’s opinion before I volunteer my own.</p><p>When you go to your next team meeting, give it a try. Don’t say the first thing that comes to your mind. You’ll get your turn.</p><p>In Netflix’s high trust culture, if we need to make a decision, one of us acts as the <a href="https://jobs.netflix.com/culture">informed captain</a>. In a team built on trust, we don’t wait for consensus. We disagree, and we commit. When the captain of any particular decision is reasonably confident of the right bet for us to take, they decide and we take that bet. But to gain commitment, it’s important to listen and understand first.</p><h4>Communicating non-violently</h4><h3>Nick Takayama on Twitter</h3><p>The hardest problem in computer science is not being an opinionated jerk about everything.</p><p>I have strong opinions about software. You may have them too. Some of us may even feel that not knowing about the link tag (and a laundry list of other things) makes you unworthy of our craft.</p><p>It’s fine to have strong opinions and judgments. If you want to communicate with someone though, if you want them to see what you see, you should seek to communicate <a href="https://medium.com/@eriktorenberg_/on-nonviolent-communication-33ca8c7ebfcb">non-violently</a>. If “violent” means acting in ways that result in hurt or harm, than much of how we communicate could be called violent communication.</p><p>When we lead with our judgments–discriminating, speaking without listening, judging who belongs “in our craft” and who doesn’t–people close up to you. You’ll never be able to let them see what you see, or think what you think, if you don’t take the time to understand what they see or think first. Have a little empathy.</p><p>If you’re right, all the better, because they’re more likely to accept what you say. It’s a <a href="http://firstround.com/review/power-up-your-team-with-nonviolent-communication-principles/">simple framework</a>.</p><ul><li>Observation — facts and data without judgement or evaluation</li><li>Feeling — state how you feel</li><li>Need — state your need underlying this feeling</li><li>Request — a specific action to address said need</li></ul><p>The most important part to me is in taking a step back to understand why I feel or judge something a certain way. The leap from observation to judgement happens very quickly. We might observe that someone on your team submits code without writing any tests. That’s fine. The issue is in quickly adding your judgement that they have no respect for the team.</p><p>Both of you would agree that they don’t write tests in their pull requests. It’s an objective fact. But before you rush to pass judgment, you should give them a chance to explain.</p><p>You could say something like: “When you submit a pull request without tests, it makes me feel worried that we’re introducing regressions.” This gives the person space and opportunity to provide new information. They might say, “I’m sorry, I’m unfamiliar with the testing framework, there was no documentation and I was afraid of asking.” You wouldn’t have known that if you didn’t ask. Now, you’ve uncovered an important issue and can work to solve it together.</p><p>Communicating well will make you a better engineer, and a better person. It’s certainly not easy. But it’s important that you try, even if it’ll never be perfect. Things don’t get better without effort.</p><p><em>Thanks to </em><a href="https://www.informedcaptain.com/"><em>Zach Wentz</em></a><em> for reviewing and for sharing “non-violent communication” with me.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99180699a0e6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/art-of-engineering/an-engineers-guide-to-communication-99180699a0e6">An Engineer’s Guide to Communication</a> was originally published in <a href="https://medium.com/art-of-engineering">Art of Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Skeleton Screen Loading in Ember.js]]></title>
            <link>https://medium.com/the-ember-way/skeleton-screen-loading-in-ember-js-2f7ac2384d63?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f7ac2384d63</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Wed, 11 Oct 2017 21:39:53 GMT</pubDate>
            <atom:updated>2017-10-11T21:39:53.733Z</atom:updated>
            <content:encoded><![CDATA[<p>Skeleton screen loading (also known as placeholder loading) is a technique that <a href="https://medium.com/ux-for-india/facilitating-better-interactions-using-skeleton-screens-a034a51120a5">enhances the perception</a> of loading in your application. Typically, the loading state of an application is indicated by some kind of loading spinner or progress bar. Unfortunately, this can sometimes backfire and cause the app to feel slower than it actually is.</p><p>The idea behind skeleton screens is instead to “<a href="https://developer.apple.com/ios/human-interface-guidelines/app-architecture/loading/">show content as soon as possible</a>”, by using a “skeleton” or placeholder representation of the actual UI in its place while content is being loaded. From what I’ve seen in the wild, this is typically a wireframe version of the UI with subtle animations, but there are no hard and fast rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*x3sau7_pLGRBTwK1bXGXhw.png" /><figcaption>Facebook’s skeleton screen loading</figcaption></figure><blockquote>Don’t make people wait for content to load before seeing the screen they’re expecting. Show the screen immediately, and use placeholder text, graphics, or animations to identify where content isn’t available yet. Replace these placeholder elements as the content loads. — Apple iOS Human Interface Guidelines</blockquote><p>I won’t delve into too much detail on the concept. In this post, I’d like to demonstrate how you can achieve skeleton screen loading in your Ember.js application.</p><h3>Don’t fetch your data in the route</h3><p>You’ve probably been told that you should always fetch data in the route, typically in the <a href="https://guides.emberjs.com/v2.16.0/tutorial/model-hook/">model hook</a>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb6e6d3363cd38fa59d29b2f455d48c9/href">https://medium.com/media/eb6e6d3363cd38fa59d29b2f455d48c9/href</a></iframe><p>The nice thing about this approach, is that an unresolved promise returned in this hook will trigger the route’s <a href="https://guides.emberjs.com/v2.16.0/routing/loading-and-error-substates/">loading substate</a>. This is usually where you would place your loading spinner component, for example. This is fine when you’re working with a non-query-param-enabled route, but if you do have to support query params or refresh the model based on some user input, you might notice <a href="https://ember-twiddle.com/b7489a0682f38df1f2d4a7aefe1eb9c4?openFiles=routes.application.js%2C&amp;route=%2F%3Fgreeting%3DHallo!">annoying UX</a> (ember-twiddle example) as a result of this behavior.</p><p>Whenever your user tries to change a query param linked value that refreshes the model, the model hook re-fires. If you’re trying to search for something, for example, this causes an unacceptable amount of jank.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FSarcasticSingleDolphin&amp;url=https%3A%2F%2Fgfycat.com%2Fgifs%2Fdetail%2FSarcasticSingleDolphin&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FSarcasticSingleDolphin-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="2880" height="1800" frameborder="0" scrolling="no"><a href="https://medium.com/media/c127e124ad855c372f61b88625d2fbf3/href">https://medium.com/media/c127e124ad855c372f61b88625d2fbf3/href</a></iframe><p>We can do better.</p><h3>Move data loading out of your route</h3><p>What we really want to avoid is the entire application transitioning to a loading substate whenever some data is loading. This is regardless of whether you use query params. In Ember’s loading substate, your app is no longer responsive. We should avoid that.</p><p>However, moving this out from the route raises important questions. Without the built-in logic for the loading substate, what can we do to avoid rebuilding it?</p><h4>ember-concurrency saves the day</h4><p>Instead of loading data in the route, you can do so in a controller or a component. I personally prefer using <a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">non-presentational components</a> to load data — I call them “loader” components, sometimes also known as container components.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a33074a13a375feaf76e7f62c35cbde1/href">https://medium.com/media/a33074a13a375feaf76e7f62c35cbde1/href</a></iframe><p>This approach also works with a controller, but you won’t have any lifecycle hooks to work with. Instead you’ll have an action call the <a href="http://ember-concurrency/">ember-concurrency</a> task that fetches data in response to some user input.</p><p>In its simplest form, a loader component is a tag-less component that performs an ember-concurrency task whenever some property being passed to it is changed. For example, this could be a query params hash, or other kind of user input. Then, all this loader component does is yield out specific properties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e6f698ebb2239cd00e0fb59f9815d01/href">https://medium.com/media/9e6f698ebb2239cd00e0fb59f9815d01/href</a></iframe><p>With ember-concurrency, we don’t have to rebuild the wheel to recreate the loading substate within our component. We can instead leverage its “<a href="https://ember-concurrency.com/#/docs/derived-state">derived state</a>” and change our UI accordingly. Here’s a simple example of how to use this loader component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f5d6c41a30c4ea631afbdedf66c072a/href">https://medium.com/media/8f5d6c41a30c4ea631afbdedf66c072a/href</a></iframe><p>With this change, we now have granular control over how our loading substate is rendered in our application. Most importantly, you’ll note that loading data this way will no longer block interactivity in your UI. Now, adding skeleton screens in its place is easy, thanks to the <a href="https://github.com/michalsnik/ember-content-placeholders">ember-content-placeholders</a> addon by <a href="https://github.com/michalsnik">Michał</a>.</p><p>Because the addon relies on ember-cli-sass, I wasn’t able to include it in my <a href="https://ember-twiddle.com/c0f98a5b62287d4a88fa80be65d3ba0d?openFiles=templates.application.hbs%2C">ember-twiddle demo</a>. I added a simple placeholder instead which provides a similar effect.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgfycat.com%2Fifr%2FWelltodoHeartyBabirusa&amp;url=https%3A%2F%2Fgfycat.com%2Fgifs%2Fdetail%2FWelltodoHeartyBabirusa&amp;image=https%3A%2F%2Fthumbs.gfycat.com%2FWelltodoHeartyBabirusa-size_restricted.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=gfycat" width="2880" height="1800" frameborder="0" scrolling="no"><a href="https://medium.com/media/4eda003f5bcc21565ffd904f6d6df957/href">https://medium.com/media/4eda003f5bcc21565ffd904f6d6df957/href</a></iframe><h3>Data loading with query params</h3><p>If you do use query params, you can still adopt the same approach. <a href="https://twitter.com/offirgolan">Offir</a> and I wrote an addon that improves upon the experience in working with query params.</p><p><a href="https://github.com/offirgolan/ember-parachute">offirgolan/ember-parachute</a></p><p>Instead of defining query params in <em>both</em> your route and controller, with this addon you can define them in one place as a query param map.</p><p>This map is the source of truth for your query params, and will generate a mixin that you can then add into your controller. The mixin adds very helpful properties and methods that makes working with query params a breeze! Once you’ve added ember-parachute to your app, you can move your query param configuration away from your route and into the controller.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d44077f1001883be27f095ccbed44f03/href">https://medium.com/media/d44077f1001883be27f095ccbed44f03/href</a></iframe><p>Because your route no longer fetches data, you can fetch data in your controller or component with an ember-concurrency task. This task is performed in response to user input, either via a component’s lifecycle hook, or by an explicit action call. Use the task’s derived state to determine the loading substate instead.</p><h3>What should I use the route for?</h3><p>In my applications, we still use the route for specific behavior, such as enforcing valid route (not query) params. I currently work on a calendar application, so visiting <strong>/2017/15</strong> is obviously not valid. We handle that validation logic in the route and redirect to a valid date instead.</p><p>Obviously, this approach isn’t aligned with what is recommended in the guides. Unfortunately, at this moment in time, there is no real answer into developing a solid skeleton screen experience with the status quo. This approach with ember-concurrency and moving data loading out of the route has worked well for us in the meantime, and I’m curious to hear what your thoughts and experiences are.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f7ac2384d63" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-ember-way/skeleton-screen-loading-in-ember-js-2f7ac2384d63">Skeleton Screen Loading in Ember.js</a> was originally published in <a href="https://medium.com/the-ember-way">The Ember Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Am Still Learning]]></title>
            <link>https://medium.com/@sugarpirate/i-am-still-learning-f61c765d657c?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f61c765d657c</guid>
            <category><![CDATA[women-in-tech]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[fear]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Tue, 30 May 2017 14:01:45 GMT</pubDate>
            <atom:updated>2018-10-31T06:13:09.469Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QpnpmtJuSS5-VXjNgSyOXw.jpeg" /><figcaption>via <a href="https://unsplash.com/?photo=g2hkt3bZq1g">Unsplash</a></figcaption></figure><h3>I’m afraid</h3><p>I was afraid when I started college in Australia, 4,000 miles away from home. I spent 3 years in vocational design school, and the thought of going back into academia was daunting. My grades were always terrible. Compared to my peers, I didn’t think I was smart enough.</p><p>I was afraid when we started a <a href="http://www.thepricegeek.com/">startup</a>. I didn’t know if I was making the right decision starting a business right out of college. Because neither of us could code, we spent our savings hiring a developer. They didn’t come through. Neither did our savings.</p><p>I was afraid when I started my first job after my startup failed. The only programming I had ever done was over-engineered Excel spreadsheets and some HTML and CSS. Going into my first job, I barely knew enough JavaScript to start work as a front-end developer.</p><p>I was afraid when I first started blogging about <a href="https://emberway.io/">Ember</a>. It was my first time learning how to use a framework (in any language). Who would bother reading?</p><p>I was afraid when <a href="https://medium.com/u/ee5764c1f8b9">Leah</a> and <a href="https://medium.com/u/dba87c29aad6">Tom</a> reached out to me to speak at <a href="http://2015.emberconf.com/">EmberConf</a>. I barely had any experience, and had never been to a conference, let alone speak at one.</p><p>I was afraid to choose <a href="https://facebook.github.io/react/">React</a>. It was a new job, and I really didn’t want to destroy their business if I messed up. Up till then, all I had done was Ember.</p><p>I was afraid when I started a new job in <a href="https://dockyard.com/">Boston</a>. Here I was, moving my life again, this time 10,000 miles away. I had to start my adult life over once more.</p><p>I was afraid going into my interview with Netflix. I don’t have a CS background. I can’t balance a binary tree to save my life. I was going to fail this interview spectacularly.</p><p>I was afraid when I was asked to take on the engineering manager role in my team. I’ve never been great with people and I love programming too much.</p><p>I’m afraid about writing this. As a woman in tech, I have a higher bar to climb to prove my worth. I already have something to prove, I don’t need one more.</p><p>And I’m going to keep being afraid. Trying something that seems out of reach is always frightening.</p><h3>I’m still learning</h3><p>I studied the hardest I ever did in <a href="https://www.monash.edu/about/who/history/sir-john-monash">college</a>, graduating in the dean’s list.</p><p>Starting a business is hard. We went through the startup roller-coaster with some of the best people we were fortunate enough to <a href="http://yorkbutterfactory.com/">meet</a>. We failed, but I learned enough programming to land a job.</p><p>My first mentor was <a href="https://medium.com/u/b645121b0865">Chris</a>. He taught me a ton. I can still vividly remember working with him through a thorny problem with JavaScript Promises. The way I approach programming these days still has some of his influence.</p><p><a href="https://www.homely.com.au/">Homely.com.au</a> still uses some of my initial legwork to get them going with React.</p><p>My <a href="https://medium.com/@sugarpirate">blog</a> is the best thing I have ever done for my career. In <a href="https://www.youtube.com/watch?v=TlU0m18Pr-Y">2015</a>, I spoke at EmberConf. As well as <a href="https://www.youtube.com/watch?v=lP9ap-AKBAM">2016</a>. And <a href="https://www.youtube.com/watch?v=ln_DvmQsvis">2017</a>. <a href="https://dockyard.com/">DockYard</a> remains one of the best places I’ve worked at.</p><p>I got the job at Netflix. It’s awesome, and I’m always hiring. I won’t ask you CS trivia questions.</p><p>I’m now the engineering manager for the Talent Innovation Engineering team at Netflix. I hired and lead an 11 strong team to reinvent the way Netflix discovers and manages talent in the entertainment industry.</p><p>I’m no longer afraid about having to “prove my worth”. I’ve proven it many times over. I’ll never stop learning, and I want to help others do the same.</p><h3>Learning from fear</h3><p>I’ve come to learn that <a href="http://100dayswithoutfear.com/">fear</a> is something to be yearned for. If you’re not afraid, you’re too comfortable. Your best work happens when you’re in that sweet spot of being just uncomfortable enough.</p><p>Surround yourself with stunning people. That’s the only way you’ll learn anything.</p><h3>amelia abreu on Twitter</h3><p>I used to describe myself as self taught... but it&#39;s a fake idea.&quot; @anildash @jennschiffer</p><p>Public speaking was my greatest fear. It might be yours too. Now, my greatest fear is that I will grow too comfortable.</p><p>Whatever it is you’re afraid of doing next, know that you’re not alone. To be afraid is to be human. When you’re afraid, it’s a great signal that you’re on to a learning opportunity.</p><p>Learn to welcome fear. Learn <em>from </em>fear<em>. </em><a href="https://twitter.com/_shreve/status/866819372924493826">No one learns and develops skills in a bubble.</a></p><p>Now repeat after me:</p><blockquote>“I am still learning”</blockquote><p>Thanks to <a href="https://medium.com/u/5bfa9a44b697">Sam French Stewart</a> and <a href="https://twitter.com/mrated">Michael Soutar</a> for reviewing.</p><p>Note: Ancora imparo, or “I am still learning”, is the motto of my alma mater.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f61c765d657c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rise From the Ashes — Incremental APIs With Phoenix]]></title>
            <link>https://medium.com/@sugarpirate/rise-from-the-ashes-incremental-apis-with-phoenix-b08cd66bd142?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b08cd66bd142</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[phoenix]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Fri, 12 Aug 2016 17:26:46 GMT</pubDate>
            <atom:updated>2017-05-12T20:56:45.747Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9mWCn3ndLnXnhzydvWqfpA.jpeg" /><figcaption>via <a href="https://unsplash.com/?photo=Rdsc2L517iQ">unsplash</a></figcaption></figure><p>Much has been said about the <a href="http://elixir-lang.org/">Elixir</a> language and the <a href="http://www.phoenixframework.org/">Phoenix framework</a> —Phoenix’s <a href="http://www.phoenixframework.org/blog/the-road-to-2-million-websocket-connections">performance</a> <a href="https://dockyard.com/blog/2015/11/18/phoenix-is-not-rails">without compromise</a> makes it a compelling choice in a world where problems are increasingly concurrent and <a href="https://dockyard.com/blog/2016/08/09/phoenix-channels-vs-rails-action-cable">real-time</a>.</p><p>Despite Phoenix’s attractiveness, chances are you have business requirements that disallow you from dropping work on existing APIs that still need to be supported. And so you might consider Phoenix no longer viable, and dismiss it to your ever-growing list of shiny toys to check out — <em>someday.</em></p><p>What if we could incrementally replace our legacy API with Phoenix, one endpoint at a time? We could make a compelling argument by showcasing performance and maintainability gains, without committing to a rewrite.</p><p>In science fiction (and perhaps someday reality), transforming an uninhabitable planet into an inhabitable one is known as <em>“</em><a href="https://en.wikipedia.org/wiki/Terraforming"><em>terraforming</em></a><em>”</em>, or literally “Earth-shaping”. It’s an apt metaphor for a little <a href="https://github.com/elixir-lang/plug">plug</a> I co-authored with <a href="https://twitter.com/_danmcclain">Dan McClain</a>.</p><p><a href="https://github.com/poteto/terraform">poteto/terraform</a></p><p>Using Terraform, you can create a Phoenix app that handles one or more endpoints, and forward un-handled requests to your legacy API. If some network latency is not a significant issue, you might find this plug useful.</p><h4>Discovery</h4><p>The basic idea is this — if a route is defined on our Phoenix app, we’ll handle the request. If it’s not, we forward the request on, and send its response back to the user.</p><p>In your Phoenix app, every incoming connection goes through a pipeline that you can readily examine at <strong>lib/my_app/endpoint.ex</strong>. You can see how a connection flows through the different plugs specified in this file. The connection is then piped into the router:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a803e31086f2fa0aa1590dd38d7fcc46/href">https://medium.com/media/a803e31086f2fa0aa1590dd38d7fcc46/href</a></iframe><h4>Terraforming the legacy API</h4><p>By adding the Terraform plug to your router, it will then re-route those missing route connections to a plug that you define. And because this plug uses <a href="https://hexdocs.pm/plug/Plug.Router.html"><strong>Plug.Router</strong></a>, you have an elegant DSL in which you can handle them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b29a3484f69a46938f22a6713ca358fe/href">https://medium.com/media/b29a3484f69a46938f22a6713ca358fe/href</a></iframe><p>Basic example aside, we’d probably want to do an actual request on your API, and you can do so by writing a client for it. There are <a href="https://github.com/h4cc/awesome-elixir#third-party-apis">many ways</a> to do it, and I’ve had success in doing so with <a href="https://github.com/edgurgel/httpoison">HTTPoison</a> and its <a href="https://hexdocs.pm/httpoison/HTTPoison.Base.html">Base</a> module. For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9af2976691d53a23f780d984fb5dc400/href">https://medium.com/media/9af2976691d53a23f780d984fb5dc400/href</a></iframe><p>And here is what a client might look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5a690d47135d31159d2a2421427161a7/href">https://medium.com/media/5a690d47135d31159d2a2421427161a7/href</a></iframe><p>This forwards all un-handled GETs to our legacy API via our client, and sends the response back with the right headers as well. Since this is just a plug, you have access to the connection, so you can easily handle things like sessions and auth as well.</p><h4>What about performance?</h4><p>I ran some unscientific benchmarks on my 2014 13&quot; MBP, and the results between the route backed by a Phoenix controller and our Terraform handler were insignificant.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1320d4b202b99e1083710f6cebb3d14/href">https://medium.com/media/c1320d4b202b99e1083710f6cebb3d14/href</a></iframe><p>This was done via <a href="https://github.com/JoeDog/siege">Siege</a>, with 255 concurrent connections doing 40 parallel requests each. That said, there will obviously be additional latency from having the Phoenix app send and return responses from your older API, so use your best judgement.</p><h4>Give it a spin</h4><p>Is <a href="https://pragprog.com/book/phoenix/programming-phoenix">Phoenix</a> as productive, reliable, and fast as many claim? With Terraform, trying out Phoenix on your current API is almost risk-free. Handle a single, simple endpoint and compare it with the performance and developer experience of your current stack. You can also view a <a href="https://github.com/poteto/reverse_proxy">simple demo of Terraform in action here</a>.</p><p>Thanks for reading, and see you at <a href="http://elixirconf.com/">ElixirConf</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b08cd66bd142" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Component dependency injection in Ember.js]]></title>
            <link>https://medium.com/the-ember-way/component-dependency-injection-in-ember-js-a46a39a5d30a?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a46a39a5d30a</guid>
            <category><![CDATA[how-to]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Tue, 28 Jun 2016 17:01:02 GMT</pubDate>
            <atom:updated>2016-08-29T00:18:16.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Iftnel6ZoumTunHZPztyiw.jpeg" /><figcaption>Manik Rathee (via <a href="https://unsplash.com/photos/a8YV2C3yBMk">unsplash</a>)</figcaption></figure><p>The <a href="http://martinfowler.com/articles/injection.html">Dependency Injection</a> (DI) pattern is a subset of <a href="http://martinfowler.com/articles/injection.html#InversionOfControl">Inversion of Control</a>, and is a useful technique for decoupling the creation of a dependency from the object itself. Don’t let the terminology scare you though! DI is really just <a href="http://www.jamesshore.com/Blog/Dependency-Injection-Demystified.html">giving an object its instance variables</a>.</p><p>For example, below is a simple example of the <strong>Player</strong> class being implicitly coupled to the <strong>Bag</strong> class. The <strong>Player</strong> is responsible for creating the dependent objects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ecb446346ea9c37e1002c2e35123aa0/href">https://medium.com/media/2ecb446346ea9c37e1002c2e35123aa0/href</a></iframe><p>Although the example is simple, it’s fairly easy to see that this implementation could be difficult to test in isolation, as you now need to know about the <strong>Bag</strong> class in the <strong>Player</strong> class’ test. DI can help us here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/95990933fbc7e0ab01f149ba1decb9e9/href">https://medium.com/media/95990933fbc7e0ab01f149ba1decb9e9/href</a></iframe><p>In the second example, we “inverted control” of the player’s inventory, and now we pass the storage object instance at runtime. This means that in our test, we can simply stub the inventory object out:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88ec1ad7bed342adfb41cd9c6efc8850/href">https://medium.com/media/88ec1ad7bed342adfb41cd9c6efc8850/href</a></iframe><p>The <strong>Player</strong> class no longer needs to know anything about the <strong>Bag</strong>, and also allows other kinds of storage object classes to be used. Great!</p><h4>Component Dependency Injection</h4><p>I recently realized that the DI pattern can also be used to great effect in Ember components. For example, let’s say you have a container or parent component that uses multiple child components:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/adb4e4510310006f4b0a6bd55ed4e619/href">https://medium.com/media/adb4e4510310006f4b0a6bd55ed4e619/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/52352516edbce13b8e65a3ba46fbef8a/href">https://medium.com/media/52352516edbce13b8e65a3ba46fbef8a/href</a></iframe><p>The parent component <strong>edit-location</strong>’s primary responsibility is to provide UI to edit a location. It could have actions defined on it, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e136129379a0da08f14d99b871ba26d6/href">https://medium.com/media/e136129379a0da08f14d99b871ba26d6/href</a></iframe><p>The <strong>google-map</strong> component provides UI for the user to drop a marker on a map, and adjust the radius around the marker by using the radius control. Needless to say, that UI interaction is quite difficult to test, and is tested in the <strong>google-map</strong> component test itself. Because the <strong>edit-location</strong> component is tightly coupled to its child components, testing it is no easy task. We need to make sure all the child components are setup just right, which introduces a lot of boilerplate in our component integration test.</p><h4>Not my concern</h4><p>In this scenario, the <strong>edit-location</strong> component itself shouldn’t need to concern itself with <em>how</em> the <strong>latLng</strong> and <strong>radius</strong> arguments are passed into its actions. The drag and drop UI is a concern of the <strong>google-map</strong> component, and as such should be tested in its own component integration test.</p><p>Using DI, we can decouple the <strong>edit-location</strong> component from its child components, and clean up our tests. This technique is currently only possible with <a href="http://emberjs.com/blog/2016/01/15/ember-2-3-released.html#toc_contextual-components">contextual components</a> due to the use of the <strong>component</strong> and <strong>hash</strong> helpers, which were made available in <a href="http://emberjs.com/blog/2016/01/15/ember-2-3-released.html">Ember 2.3.0</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba1af60e8f3139bcc0cb0294e4be579e/href">https://medium.com/media/ba1af60e8f3139bcc0cb0294e4be579e/href</a></iframe><p>We’ve passed in a hash of the child components using the <strong>hash</strong> and <strong>component</strong> helpers. This effectively inverts control to the template that calls the <strong>edit-location</strong> form:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10e4d8b276f6649cf02b99dc2815edac/href">https://medium.com/media/10e4d8b276f6649cf02b99dc2815edac/href</a></iframe><p>Install the test helper here:</p><p><a href="https://github.com/poteto/ember-test-component">poteto/ember-test-component</a></p><pre>ember install ember-test-component</pre><p>Now, in our tests, we’ll need to write a little test helper (or use the addon above) to create a dummy component we can use to no-op (do nothing). Credit goes to <a href="https://twitter.com/runspired">@runspired</a> for nudging me in the right direction:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ac9fd160cf6261218058a47aaf4e6b7/href">https://medium.com/media/1ac9fd160cf6261218058a47aaf4e6b7/href</a></iframe><p>This test helper registers a fake component in the container, making it available for us to use in our component integration test:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e643695c0da3c427ea441bd05bceb662/href">https://medium.com/media/e643695c0da3c427ea441bd05bceb662/href</a></iframe><p>Now we can test the <strong>edit-location</strong> component itself without worrying about setting up child components. That said, DI still allows us to test those child components integrating with <strong>edit-location</strong>, in a more controlled environment:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ba39450d677060619491be06eae669a8/href">https://medium.com/media/ba39450d677060619491be06eae669a8/href</a></iframe><p>I hope you find this useful! It’s not a silver bullet by any stretch, but DI can help you write better isolated components and simplify your tests.</p><p>Until next time! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a46a39a5d30a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-ember-way/component-dependency-injection-in-ember-js-a46a39a5d30a">Component dependency injection in Ember.js</a> was originally published in <a href="https://medium.com/the-ember-way">The Ember Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bringing Ecto Changesets into Ember.js]]></title>
            <link>https://medium.com/the-ember-way/bringing-ecto-changesets-into-ember-js-8e665ec70ab6?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e665ec70ab6</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ecto]]></category>
            <category><![CDATA[addons]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Fri, 17 Jun 2016 23:47:26 GMT</pubDate>
            <atom:updated>2016-06-19T01:45:23.064Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iYUneIH0OuXqcwUh-dFjCw.jpeg" /><figcaption>Justin Luebke (via <a href="https://unsplash.com/photos/SmAiLn-nnJg">unsplash</a>)</figcaption></figure><p>The past month or so, I’ve been working on an <a href="http://elixir-lang.org/">Elixir</a> and <a href="http://www.phoenixframework.org/">Phoenix</a> API for a client. I am blown away by how nice it is working with Elixir and functional programming (FP) concepts. FP feels more intuitive and less prone to “shoot yourself in the foot” scenarios compared to OOP. In fact, I try to use functional approaches wherever possible in JavaScript as well.</p><p>That isn’t to say that one is better than the other, but in my experience less unexpected behavior occurs in FP. It turns out whole classes of bugs disappear when embracing immutability and pure functions.</p><h4>Ecto Changesets to the Rescue</h4><p>In Elixir, we use <a href="https://github.com/elixir-ecto/ecto">Ecto</a>, a DSL for writing queries and interacting with databases. One of the core concepts in Ecto is the <a href="https://hexdocs.pm/ecto/Ecto.Changeset.html">changeset</a> — an atomic collection of changes. Changes are validated and checked against database constraints (such as uniqueness) before casting. This ensures that we catch invalid data in the app layer before insertion into the database. Ecto is often confused with <a href="http://rubyonrails.org/">Rails</a>’ <a href="http://guides.rubyonrails.org/active_record_basics.html">ActiveRecord</a>, but it isn’t an ORM, and shouldn’t be used like one.</p><p>The idea for bringing changesets into Ember occurred to me while I was working on a new client app. An edit page featured 3 forms, all bound to the same model. Each hidden form had separate “toggle”, “save” and “reset” actions. Using <a href="https://github.com/martndemus/ember-form-for">ember-form-for</a> and <a href="https://github.com/offirgolan/ember-cp-validations">ember-cp-validations</a>, this turned out to be harder than I thought. Editing one form would immediately update the model with 2-way bindings. This was a poor user experience, since you might edit more than 1 form at a time, but want to separate saves and resets.</p><h4>Changesets in Ember</h4><p>In my mind, I could see a solution using changesets. Each form would have a separate changeset, so changes (and validations) would be independent. It turns out that this approach works really well, and I’m happy to announce that you can <a href="https://github.com/poteto/ember-changeset">install it today as an addon</a> with:</p><pre>ember install ember-changeset<br>ember install ember-changeset-validations</pre><p><a href="https://github.com/poteto/ember-changeset">poteto/ember-changeset</a></p><p>I wrote the addon with compatibility in mind, so it’s easy to wire up with your favorite validation library. The simplest way to incorporate validations is to use <a href="https://github.com/poteto/ember-changeset-validations/">ember-changeset-validations</a>, a companion addon. It has a simple mental model, and there are no observers or CPs involved — just pure, plain JavaScript functions.</p><p><a href="https://github.com/poteto/ember-changeset-validations">poteto/ember-changeset-validations</a></p><p>Let’s take a look at how <a href="https://github.com/poteto/ember-changeset">ember-changeset</a> is implemented, and we’ll also demonstrate how they align with Ember’s Data Down Actions Up (DDAU) philosophy.</p><h4>Virtual Properties with unknownProperty and setUnknownProperty</h4><p>The core concept behind ember-changeset is the definition of <strong>unknownProperty</strong> and <strong>setUnknownProperty</strong>. These methods are invoked (if present) in <strong>Ember.get</strong> or <strong>Ember.set</strong> whenever an Ember Object does not define a property. Ruby developers would be familiar with this behavior via the <strong>method_missing</strong> method. A colleague I used to work with wrote an excellent <a href="https://emberway.io/metaprogramming-in-emberjs-627921395299#.8m07o1i8u">blog post</a> on this topic, please check it out if you’re interested in finding out more!</p><p>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1246e5a7527492afb30f4d7bff4e8d6/href">https://medium.com/media/d1246e5a7527492afb30f4d7bff4e8d6/href</a></iframe><p>When a <strong>Person</strong> is created, trying to <strong>get</strong> or <strong>set</strong> a property other than <strong>firstName</strong> and <strong>lastName </strong>will invoke the <strong>unknownProperty</strong> and <strong>setUnknownProperty</strong> methods respectively:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a57b40d7ebda594057f6c8e5ad461dff/href">https://medium.com/media/a57b40d7ebda594057f6c8e5ad461dff/href</a></iframe><p>These two methods allow us to <em>proxy</em> our changeset to the actual model, meaning we can hold back changes but still forward <strong>get</strong>s to the model.</p><h4>Storing Changes</h4><p>Our changeset needs a reference to the underlying model, as well as an internal list of changes to be applied. We can set this up in the <strong>init</strong> method of our object, which is invoked whenever a new instance is created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c73739a4f1c0e930a1561dcdefbefca4/href">https://medium.com/media/c73739a4f1c0e930a1561dcdefbefca4/href</a></iframe><p>We want to be able to forward <strong>get</strong>s to <strong>_content</strong>, but hold back <strong>set</strong>s on <strong>_changes</strong>, and this is easy enough to set up via virtual properties:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6557b72cd9b42f6bc2019f74b63b1612/href">https://medium.com/media/6557b72cd9b42f6bc2019f74b63b1612/href</a></iframe><p>Since a changeset should only allow valid changes to be set, we validate the change using the <strong>validateFn</strong> function that was passed in to the changeset factory. If a change is valid, we add it to the hash of changes in <strong>_changes</strong>, and if it’s invalid and returns an error message, we add it to the hash of <strong>_errors</strong>.</p><p>Of course, there are more implementation details than that, but the concept remains unchanged. After defining a simple public API for using changesets, there wasn’t too much more code to add! For example, this is how you would use a changeset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca0f93b31fe934e77e3ac8810048a300/href">https://medium.com/media/ca0f93b31fe934e77e3ac8810048a300/href</a></iframe><p>Rolling back changes, and even merging them, becomes trivial with a changeset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c737e875b6e9f88bd84810a58a28ddb/href">https://medium.com/media/4c737e875b6e9f88bd84810a58a28ddb/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/19b2eb186c4a36202b1e185dfbe1fffc/href">https://medium.com/media/19b2eb186c4a36202b1e185dfbe1fffc/href</a></iframe><h4>Data Down Actions Up, Not 2-Way Bindings</h4><p>One of the reasons DDAU is so strongly emphasized in Ember 2.x is because it helps us avoid shooting ourselves in the foot with 2 way bindings (2WBs). 2WBs were the “killer feature” of many JavaScript frameworks when they first debuted. As client side applications matured and became more sophisticated, developers realized that 2WBs were more harmful than useful. 2WBs led to instability and difficult debugging in the form of cascading changes, and <a href="https://facebook.github.io/react/">React</a> was the first library to attempt to solve this problem.</p><p>React’s breakthrough was in the use of a virtual DOM, a representation of the actual DOM as a tree-like data structure. Diffing the changes between the virtual and real DOM paved the way for the complete removal of 2WBs — the application simply re-renders whenever there is a change in value.</p><p>This continues to be a simpler mental model, and just like Elixir (and other functional languages), eliminates a whole class of bugs. DDAU in Ember.js is built upon the same idea, that data should flow one way.</p><p>Using changesets in Ember takes the DDAU philosophy used in rendering into the realm of interacting with client side view models. Instead of 2WBs, changesets allow one way data flow to a model, ensuring that they are always valid, and eliminating a whole class of synchronization headaches.</p><h4>Is This Real Life?</h4><p>When I dropped in <strong>ember-changeset</strong> and <strong>ember-changeset-validations</strong> into my client app, it instantly clicked with the way I’ve been writing Ember, using DDAU. My complex forms now have independent validations and changes, and I no longer need to worry about saving an unintended change in one form when I submit another.</p><p>Because <strong>ember-changeset</strong> can be used directly in place of an ember-data model, using it with a form library like <strong>ember-form-for</strong> is trivial using the <strong>changeset</strong> helper:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0252b3c2198186bd1be2114ca342708f/href">https://medium.com/media/0252b3c2198186bd1be2114ca342708f/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a575b1a42a48565aafa9f4d9d5bd785/href">https://medium.com/media/1a575b1a42a48565aafa9f4d9d5bd785/href</a></iframe><h4>Validating Changesets</h4><p>Validation becomes even simpler with changesets. Throughout Ember’s history, we have largely relied on addons like <a href="https://github.com/DockYard/ember-validations">ember-validations</a> which make extensive use of observers. Newer libraries like <a href="https://github.com/offirgolan/ember-cp-validations">ember-cp-validations</a> use computed properties (CPs) instead, but that still relies on 2WBs.</p><p>Using <strong>ember-changeset</strong> and <strong>ember-changeset-validations</strong> you can take a functional approach with validations. A validator function is passed into the changeset, that is invoked whenever a property is set. This validator function then looks up the appropriate validator (say <strong>presence</strong> or <strong>format</strong>) on the validation map, and returns <strong>true</strong> or an error message.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af8bd976d62769e4b6970e1e10877038/href">https://medium.com/media/af8bd976d62769e4b6970e1e10877038/href</a></iframe><p>A validator like <strong>validatePresence</strong> is simply a function that returns a function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b782cfbd22dff367f921dc83cca43f9c/href">https://medium.com/media/b782cfbd22dff367f921dc83cca43f9c/href</a></iframe><p>Which is simpler to reason about compared to an OOP implementation that relies on extending base classes and holding on to state. Because validation maps are simply POJOs, composing validators is intuitive:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c1eeed2f1710a2d9fb46b2cbdb1c1b2c/href">https://medium.com/media/c1eeed2f1710a2d9fb46b2cbdb1c1b2c/href</a></iframe><p>You can easily import other validations and combine them using <strong>Ember.assign</strong> or <strong>Ember.merge</strong>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2517c6096bbe4f5307f4c32c1c214cb5/href">https://medium.com/media/2517c6096bbe4f5307f4c32c1c214cb5/href</a></iframe><p>This approach lets you build up validations independent of the model. Ember Data models aren’t 1 to 1 representations of server-side records, they’re View Models. This means we shouldn’t need to validate them the same way we would a server-side model. For example, you might have <strong>User</strong> models in your application, and some of these users might have different roles that require different validation. Best of all, we don’t need to use observers or CPs!</p><h4>The Only Constant is Change</h4><p>I hope you enjoyed reading about the concept and implementation of changesets in Ember. DDAU on your models will make your life simpler and your app easier to reason about! Work is still on-going on these addons, so please try them out and let me know if you have any issues or feedback.</p><p>As always, thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e665ec70ab6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-ember-way/bringing-ecto-changesets-into-ember-js-8e665ec70ab6">Bringing Ecto Changesets into Ember.js</a> was originally published in <a href="https://medium.com/the-ember-way">The Ember Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Declarative Templating in Ember with Composable Helpers]]></title>
            <link>https://medium.com/the-ember-way/declarative-templating-in-ember-with-composable-helpers-a70f01d67165?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a70f01d67165</guid>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Thu, 21 Apr 2016 17:24:46 GMT</pubDate>
            <atom:updated>2016-06-18T20:58:03.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mK8I3vf9Mbr24mrlakaj5g.jpeg" /></figure><p><a href="https://emberway.io/route-closure-actions-in-ember-js-d0a7a37a5d1b#.ce4ri08c6">Previously</a>, I mentioned that Ember’s new <strong>Helper</strong> implementation landed in <a href="http://emberjs.com/blog/2015/06/12/ember-1-13-0-released.html#toc_new-ember-js-helper-api">1.13</a>. In my opinion, helpers are one of the most useful, yet least talked about features in Ember.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL4eq2DPpyBblc8aQAd516-jGMdAhEeUiW&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DlP9ap-AKBAM%26list%3DPL4eq2DPpyBblc8aQAd516-jGMdAhEeUiW&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FlP9ap-AKBAM%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/27580a0230da59e56eaa00e795ac7020/href">https://medium.com/media/27580a0230da59e56eaa00e795ac7020/href</a></iframe><p>In my EmberConf 2016 talk on Idiomatic Ember, I spoke about helpers in detail, showing how they can be used to power up and essentially extend <a href="http://handlebarsjs.com/">Handlebars</a> with custom functionality. These helpers can then be used to allow declarative templating — a style of templating by composing actions, and giving templates more responsibility with regards to presentational logic.</p><p>Together with fellow DockYarder <a href="https://twitter.com/Martndemus">Marten Schilstra</a>, we’ve created the <a href="https://github.com/DockYard/ember-composable-helpers">ember-composable-helpers</a> addon. It’s a package of declarative helpers that lend themselves naturally for composition, and using it can help remove boilerplate code in your app. You can install it today with:</p><pre>ember install ember-composable-helpers</pre><p>One of my favorite helpers in the addon is the <strong>pipe</strong> helper (and its closure action cousin, <strong>pipe-action</strong>). This lets you declaratively compose actions in your template, instead of creating many variants in your Component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0235a6d43bb00a3f5e86265fc633ba4b/href">https://medium.com/media/0235a6d43bb00a3f5e86265fc633ba4b/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6fd317434f67e28252e756953171b95/href">https://medium.com/media/b6fd317434f67e28252e756953171b95/href</a></iframe><p>This pipe helper was inspired by Elixir’s pipe operator, which lets you write the following:</p><pre>A(B(C(D(E), &quot;F&quot;), &quot;G&quot;), &quot;H&quot;)</pre><p>As a series of data transforms:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abf6f247020b7d5ae9404d97fb3ffc32/href">https://medium.com/media/abf6f247020b7d5ae9404d97fb3ffc32/href</a></iframe><p>Using the pipe operator, we can naturally express how <strong>E</strong> is passed to the <strong>D</strong> function, then the return value of that function is passed into <strong>C</strong> as its first argument, and so on. I think we can agree that the pipe version is a lot easier to read!</p><h4>If only you knew the power of the Helper</h4><p>You can think of a helper as a primitive <strong>Keyword</strong> construct used by Ember and HTMLBars to extend the ordinary expressions provided by Handlebars. At its most basic level, the Handlebars library is responsible for compiling the <strong>hbs</strong> language down to HTML:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6935d0d3dd68f981f3e0d5856ef62646/href">https://medium.com/media/6935d0d3dd68f981f3e0d5856ef62646/href</a></iframe><p>Ember and HTMLBars then builds on top of this, adding useful keywords like <strong>action</strong>, <strong>mut</strong>, <strong>get</strong>, and <strong>hash</strong>. In fact, all the familiar keywords you’ve been using (everything from <strong>each</strong> to <strong>component</strong>) are <a href="http://emberjs.com/api/classes/Ember.Templates.helpers.html">actually HTMLBars helpers under the hood</a>!</p><p>Ember Helpers operate at a higher level compared to HTMLBars helpers, but can also be used as a way to let you create new keywords in Ember, effectively allowing you to extend templating with custom behavior.</p><h4>It depends</h4><p>More experienced or conservative developers might see this as a red flag: while making this framework construct available to end-users is useful, it can also open up potential for abuse.</p><p>For example, in Elixir, macros can be used to extend the language, but aren’t recommended unless you <em>really</em> need to. In fact, this has been informally codified in the excellent <a href="https://pragprog.com/book/cmelixir/metaprogramming-elixir">Metaprogramming Elixir</a> book by <a href="https://twitter.com/chris_mccord">Chris McCord</a> — “Rule 1: Don’t Write Macros”.</p><p>Fortunately, helpers aren’t quite as powerful as Elixir macros, and play an important role in the Ember programming model. Unlike a macro, which lets you reach down to the AST, using an Ember helper to extend presentational logic is OK <em>as long as we don’t abuse it</em>, and that distinction is where experience comes into play. So use helpers responsibly.</p><h4>Get your logic off my lawn</h4><p>Some people may feel uneasy using addons containing helpers because of the misconception that it introduces too much logic in their templates, and that they prefer to keep their templates logic-free.</p><p>As a best practice, we should strive not to have complicated logic in our templates, and when your sub-expression looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2568584a59615385c3fcf58dbf6511c9/href">https://medium.com/media/2568584a59615385c3fcf58dbf6511c9/href</a></iframe><p>It’s a sign that you’re better off using a computed property.</p><p>On the other hand, keeping your templates 100% logic-free is really hard — you’re likely already using a logical helper like <strong>if/else</strong> or <strong>unless</strong>. It can be easy to lose sight of the fact that the amount of logic in your template lies on a spectrum, and is not a strict dichotomy.</p><h4>Back to the future</h4><h3>Edward Faulkner on Twitter</h3><p>@samselikoff @raytiley I think we need a story for composing helpers directly out of other helpers.</p><p>ember-composable-helpers doesn’t significantly increase the amount of logic in your templates — in fact, if used correctly, it encapsulates presentational logic within these helpers, and in many cases can help you eliminate now redundant code in your Components or Controllers.</p><p>For example, you might have written something like this in your app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/506fd6c9a9909dfde614ff6571126e41/href">https://medium.com/media/506fd6c9a9909dfde614ff6571126e41/href</a></iframe><p>It’s quite common to have “intermediary” CPs in your Component that you then use in some other CP. Using ember-composable-helpers lets you compose that directly in the template, where the intent becomes incredibly clear:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c6388dd9142f65e8955c9a743ef40a0/href">https://medium.com/media/0c6388dd9142f65e8955c9a743ef40a0/href</a></iframe><p>You can think of a composable helper as a kind of computed property macro that you can use and compose directly in your template. And since you can compose sub-expressions in Ember, these can become powerful constructs to reduce boilerplate code in your application.</p><p>With that said, remember not to get too carried away with deeply nesting helpers!</p><h4>The Principle of Least Power</h4><p>Also known as the Rule of Least Power, this principle can be generally applied as:</p><blockquote>Given a choice of solutions, pick the least powerful solution capable of solving your problem. (<a href="http://www.lihaoyi.com/post/StrategicScalaStylePrincipleofLeastPower.html#philosophy-principle-of-least-power">source</a>)</blockquote><p>This rule originated in 2006, from a <a href="https://www.w3.org/2001/tag/doc/leastPower.html">W3C TAG Finding</a> written by Tim Berners-Lee and Noah Mendelsohn.</p><blockquote>Computer Science in the 1960s to 80s spent a lot of effort making languages which were as powerful as possible. Nowadays we have to appreciate the reasons for picking not the most powerful solution but the least powerful. The reason for this is that the less powerful the language, the more you can do with the data stored in that language. If you write it in a simple declarative from, anyone can write a program to analyze it in many ways.</blockquote><p>This principle is one of the <a href="https://twitter.com/wycats/status/665713741258821633">core ideas</a> that drives Ember and its adoption of Handlebars / HTMLBars over something infinitely more complex in the form of React’s JSX.</p><h3>Edward Faulkner on Twitter</h3><p>@samselikoff Yup, this is principle of least power at work. Templates are powerful but not infinitely so. Rules out huge class of problems.</p><p>This principle is the same reason why you wouldn’t write an eval helper and insert arbitrary JavaScript into your templates. You <em>could</em>, but <em>should you?</em></p><h4>Exercise best judgment</h4><p>As with all programming tools, it’s important to exercise best judgment and use them responsibly.</p><blockquote>Just because you can do something doesn’t mean that you should.</blockquote><p>A well written view layer means that templates should be as declarative as possible (communicate intent clearly), and not that we should avoid logic altogether. That said, we’re not advocating for moving all your logic into your template — again, it’s not a dichotomy, but a spectrum.</p><p>If you’d like to see how the addon is being used, <a href="https://twitter.com/katherinlaine">Katherin Siracusa</a> wrote an excellent <a href="https://m.alphasights.com/composable-helpers-and-route-actions-two-ember-add-ons-you-should-know-655cf39fd9de#.y63wvqjpm">blog post</a> about how she uses ember-composable-helpers at <a href="https://www.alphasights.com/">AlphaSights</a>:</p><blockquote>This pattern, of performing some significant, data-changing action and subsequently performing a more ancillary, short-term state-like action, keeps arising in our application. Using […] composable-helpers, we can take care of this in a fairly straightforward way, without much duplication and without having to worry about unintended side effects.</blockquote><p>You can also join in the discussion on our Slack channel <a href="https://ember-community-slackin.herokuapp.com/">#e-composable-helpers</a>.</p><p>As always, thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a70f01d67165" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-ember-way/declarative-templating-in-ember-with-composable-helpers-a70f01d67165">Declarative Templating in Ember with Composable Helpers</a> was originally published in <a href="https://medium.com/the-ember-way">The Ember Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Route Closure Actions in Ember.js]]></title>
            <link>https://medium.com/the-ember-way/route-closure-actions-in-ember-js-d0a7a37a5d1b?source=rss-a4c91dcedec4------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0a7a37a5d1b</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[addons]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Lauren Tan]]></dc:creator>
            <pubDate>Thu, 21 Apr 2016 17:08:25 GMT</pubDate>
            <atom:updated>2016-06-18T20:58:14.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KU2Kul8ITrOeXD8u7weS4Q.jpeg" /></figure><p>In my <a href="https://emberway.io/ember-js-goodbye-mvc-part-1-21777ecfd708#.cigfu5es3">previous post</a>, I wrote about moving singleton state in Controllers into Services that back components. This means being able to lighten the responsibility of Controllers in your application, and in some cases even remove them completely. However, a common pain point that remains for many is that it isn’t really clear what <em>should live</em> on a Controller, if anything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*tvgwFdy2_WAIdc_kvd_Hqw.png" /><figcaption>(No, they’re not)</figcaption></figure><p><a href="https://twitter.com/locks">Locks</a> has written an excellent <a href="https://locks.svbtle.com/controllers-are-dead-long-life-controllers">blog post</a> on this sometimes controversial topic, and I expanded upon it a little in my <a href="https://emberweekend.com/episodes/like-stealing-candy-from-a-baby">podcast episode</a> with Ember Weekend. <a href="https://twitter.com/erikch">Erik Hanchett</a> also did a video demo showcasing what I mentioned:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FovgDR2qAl-Q%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DovgDR2qAl-Q%26feature%3Dyoutu.be%26a&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FovgDR2qAl-Q%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/cc3c4013f00b2a068fdeaec3a7500556/href">https://medium.com/media/cc3c4013f00b2a068fdeaec3a7500556/href</a></iframe><p>Basically, you still require a Controller if you use query parameters, and in certain cases of bubbling actions.</p><p>One reason that is commonly suggested as an argument for using Controllers is that when Routable Components land, it would be a simple rename from Controller to Component. However, if you’ve read my earlier post and listened to the podcast / watched the video above, you’ll know that Routable Components are stateless like ordinary Ember Components. Controllers, on the other hand, are stateful, which means that the transition won’t be so simple.</p><p>That said, I wouldn’t go out of your way to creatively avoid using Controllers, and would <strong>only remove them if it makes sense to do so</strong>. You can ease the transition by extracting your stateful logic into a service, and leaving the stateless logic in your Controller (or Component).</p><h4>Sending closure actions directly to the route</h4><p><a href="https://dockyard.com/blog/2015/10/29/ember-best-practice-stop-bubbling-and-use-closure-actions">Closure actions</a> are probably one of my favorite additions to Ember. Instead of casting string actions into the void and praying that something is listening, we can instead use an action like we would any other JavaScript function. This means that we can do useful things like curry arguments, utilize return values, and all of the other good stuff we expect from a regular JS function call.</p><p>For example, the following action is implicit in that you have no idea where the action actually lives — it could be on a component, controller or route.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49078e7068589476e775cdbb0292641e/href">https://medium.com/media/49078e7068589476e775cdbb0292641e/href</a></iframe><p>Unfortunately, Ember’s in a bit of an awkward transition phase right now. Without bringing in an addon (or making a custom helper), it’s not possible to use a closure action directly from the route — it would have to be defined on the Controller.</p><p>If you wanted to remove Controllers from your application, then you would have to resort to using string based actions instead of closure actions. This seems like a lose-lose situation, so I worked together with <a href="https://twitter.com/rwjblue">rwjblue</a> to turn his <a href="http://jsbin.com/jipani/edit?html,js,output">jsbin spike</a> into a working addon.</p><p><a href="https://github.com/dockyard/ember-route-action-helper">ember-route-action-helper</a> lets you use closure actions defined on the route in your templates, meaning that many Controllers that only exist to implement actions can now be removed. You can install it today with:</p><pre>ember install ember-route-action-helper</pre><p>And to use it, you can just use <strong>route-action</strong> in place of <strong>action</strong> inside of your route’s template, like so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6a6817a65f5dbb195311cd28d746d37/href">https://medium.com/media/c6a6817a65f5dbb195311cd28d746d37/href</a></iframe><p>This addon gives you all the goodness of closure actions, and is a great way of taking steps to future proof your Ember application. When Routable Components do land, and actions work correctly, then upgrading your app simply becomes a search and replace for <strong>s/route-action/action</strong>.</p><h4>Power up your Handlebars templates with Helpers</h4><p>Helpers are a really nice way of extracting utility functions that you can use in your application. You can create class based Helpers, like ember-route-action-helper, or simple pure-function ones using <a href="http://emberjs.com/api/classes/Ember.Helper.html#method_helper">Helper.helper</a> like the one used in <a href="https://github.com/poteto/ember-toggle-helper">ember-toggle-helper</a>.</p><p>Pure-function helpers are simple to grok and understand, so a look at addons like <a href="https://github.com/jmurphyau/ember-truth-helpers">ember-truth-helpers</a> is sufficient to understand them.</p><p>ember-route-action-helper uses the class based implementation, which must define a <strong>compute</strong> method. This is then invoked every time one of the positional arguments to the helper changes.</p><p>Under the hood, the <strong>route-action</strong> helper retrieves the router from the application instance as a computed property, then locates the function reference from the currently active routes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbb589f548f0906772655af98b5a7cd2/href">https://medium.com/media/cbb589f548f0906772655af98b5a7cd2/href</a></iframe><p>The action and the handler (route) is then returned, and wrapped with a closure action, which allows us to do all the nice stuff we expect from any other closure action in Ember. By returning a function in a helper, you can essentially “decorate” the action helper with some custom functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/53b67af882588e93e0aa6e8a180d6f82/href">https://medium.com/media/53b67af882588e93e0aa6e8a180d6f82/href</a></iframe><p>And because Helper classes are just like any other class in Ember, you can do the usual things like inject services, define computed properties, and so on. Here’s a contrived example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a59885f6ff389e542e84f7fc7e71b9ad/href">https://medium.com/media/a59885f6ff389e542e84f7fc7e71b9ad/href</a></iframe><p>The simplified Helper class was introduced in <a href="http://emberjs.com/blog/2015/06/12/ember-1-13-0-released.html#toc_new-ember-js-helper-api">1.13</a>, and are an excellent addition to Ember. In my next post, I’ll talk a little bit more about them and how we can use them to replace certain CPs.</p><p>Until next time, thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0a7a37a5d1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/the-ember-way/route-closure-actions-in-ember-js-d0a7a37a5d1b">Route Closure Actions in Ember.js</a> was originally published in <a href="https://medium.com/the-ember-way">The Ember Way</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>