<?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 Daniel Gynn on Medium]]></title>
        <description><![CDATA[Stories by Daniel Gynn on Medium]]></description>
        <link>https://medium.com/@danielgynn?source=rss-ccaa8143db3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tqqWUhgIjuHGLv9XtKswIQ@2x.jpeg</url>
            <title>Stories by Daniel Gynn on Medium</title>
            <link>https://medium.com/@danielgynn?source=rss-ccaa8143db3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 13:38:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielgynn/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[JSConf & CSSConf Budapest 2016 — A Short Summary]]></title>
            <link>https://medium.com/@danielgynn/jsconf-cssconf-budapest-2016-a-short-summary-a2d97519f172?source=rss-ccaa8143db3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2d97519f172</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[conference]]></category>
            <dc:creator><![CDATA[Daniel Gynn]]></dc:creator>
            <pubDate>Thu, 26 May 2016 11:44:14 GMT</pubDate>
            <atom:updated>2016-06-30T08:29:08.472Z</atom:updated>
            <content:encoded><![CDATA[<p>This year I was lucky enough to attend my first full-length JavaScript and CSS conference, which also meant I was able to travel to Budapest. The conference was hosted at the <a href="http://akvariumklub.hu/">Akvarium Klub</a>, which is an <em>underwater</em> nightclub located right in the city centre.</p><p>In this blog post, I’ll discuss some of my personal highlights from both conferences. I’ll also include some of the photographs I took from around the city. More of my photography from Budapest can be found <a href="https://www.flickr.com/photos/danielgynn/sets/72157665845574314">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f82sNHDESLRlbVZo.jpg" /></figure><h3>Day One — Progressive Web Apps Workshop</h3><p>On Tuesday, the day before the conference began, there were a number of workshops held, included with the regular tickets. There were lots of cool workshops to choose from, but I decided to attend the ‘Crash Course to Progressive Web Apps’ by <a href="https://usefulthink.com/jsconf.bp-intro/">Nolan Lawson</a>.</p><p>A progressive web app combines the best of web and native experiences, and can be promoted by the browser. This means that a PWA has the capability to work offline, can be launched from the home screen, allows push notifications, background sync, and has many other characteristics that native apps provide. Progressive Web Apps use <a href="http://www.html5rocks.com/en/tutorials/service-worker/introduction/">service workers</a> to build these rich offline experiences. A service worker is basically just a script that runs in the background to allow features to run that don’t need any page or user interaction.</p><p>Progressive web apps have been <a href="https://remysharp.com/2016/03/18/progressive-web-apps-the-long-game">talked</a> <a href="https://www.youtube.com/watch?v=cmGr0RszHc8">about</a> <a href="https://www.youtube.com/watch?v=srdKq0DckXQ">a lot</a> lately, and it was really cool to explore this new technology by looking at Nolan’s <a href="https://www.pokedex.org/">pokedex.org</a> example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*joLG91U8md2BAqKn.jpg" /></figure><h3>Day Two — CSSConfBP</h3><p>So the first conference day was the CSSConf, hosted by master of ceremony <a href="https://twitter.com/serrynaimo">Thomas Gorissen</a>, who came up with some new meanings for CSS — Centering Shit, Sometimes. There were many great talks at CSSConfBP and I came away with lots of great tips to improve my CSS skills at work. Here is the full list of talks:</p><ul><li>CSS Animations, Orchestrated — David Khourshid (<a href="http://slides.com/davidkhourshid/deck-17#/">Slides</a>)</li><li>Shedding Light on the Shadow DOM — David Berner (<a href="https://speakerdeck.com/daveordead/shedding-light-on-the-shadow-dom">Slides</a>)</li><li>The Super Mario Bros. Principle — Stefan Baumgartner (<a href="https://speakerdeck.com/ddprrt/the-super-mario-bros-principle">Slides</a>)</li><li>The New CSS Layout — Rachel Andrew (<a href="http://www.slideshare.net/rachelandrew/css-conf-budapest-new-css-layout">Slides</a>)</li><li>Simple Accessible — Estelle Weyl</li><li>CSS Modules, CSS Variables &amp; the Future of Reusable CSS — Glen Maddern (<a href="https://speakerdeck.com/geelen/css-modules-css-variables-and-the-future-of-reusable-css">Slides</a>)</li><li>Responsive Web Applications with Container Queries — Jonathan Snook</li><li>Schrodinger’s Website: Using Sass to Build Indeterminate, User-generated Websites — Jackie Balzer</li><li>Visual Regression testing for CSS — Kevin Lorenz (<a href="https://speakerdeck.com/verpixelt/visual-regression-testing-with-javascript">Slides</a>)</li><li>The Componentisation of the Web — Andrey Sitnik</li><li>In the Wild — Tim Holman</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hWVaMT9XYXXcKLmq.jpg" /></figure><h3>Layouts with Grid and Flexbox</h3><p>One of my favourite talks from the CSSConf was about ‘The New CSS Layout’ by <a href="https://twitter.com/rachelandrew">Rachel Andrew</a>. In the talk, Rachel was discussing new ways of building page layouts in CSS that improve upon older methods such as using floats, table displays and messy markup from frameworks (Bootstrap).</p><p>Using tools such as <a href="https://css-tricks.com/snippets/css/complete-guide-grid/">Grid</a> (for 2D layout) and <a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/">Flexbox</a> (for 1D layout) will automatically allow layouts to be responsive and flexible by default and can allow more precise control of vertical and horizontal alignment. I really like using Flexbox to simplify laying out elements on a page and find the minimal syntax to be a really nice alternative to adding endless amounts of &lt;div class=”col-md-12&quot;&gt; to child elements.</p><pre>.parent { <br>  display: flex; <br>} </pre><pre>.child { <br>  flex: 1 1 250px; <br>}</pre><p>For example, this shorthand example would allow all of the child elements, defined within the parent, to be equally spaced across a row with a default size of 250px each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z_LILyuHtj_E9BZP.jpg" /></figure><h3>Modular and Reusable CSS</h3><p>Another personal highlight from CSSConfBP was a talk called ‘CSS Modules, CSS Variables and the Future of Reusable CSS’ given by <a href="https://twitter.com/glenmaddern">Glen Maddern</a>. In his talk, Glen spoke about how we should be building better components rather than relying on tools to make our current components ‘themeable’. He was also talking about how components should respond to their environment, meaning that externals should not be overriding the components.</p><blockquote><em>“Layout is the concern of the </em>parent<em>”</em></blockquote><p>Glen also reiterated Rachel’s point on using tools such as Flexbox to create layouts using parent wrappers, rather than specifying grid columns on the child elements. We should also make sure to use variables to create strong, reusable custom properties in our CSS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wRIODyD-FVKtgoeb.jpg" /><figcaption>City Rainbow</figcaption></figure><h3>Day Three &amp; Four — JSConfBP</h3><p>The JSConf was hosted by <a href="https://twitter.com/jaffathecake">Jake Archibald</a>, from the Google Chrome team, who did a great job of keeping everybody entertained. We were really looked after at the conference with lots of food and excellent coffee provided by <a href="http://www.bloomberg.com/">Bloomberg</a>.</p><p>Here is the list of talks from <strong>day one</strong>:</p><ul><li>What Everybody Should Know About NPM — Laurie Voss (<a href="http://slides.com/seldo/jsconf-budapest#/">Slides</a>)</li><li>The Hitchhiker’s Guide to all things Memory in JavaScript — Safia Abdalla (<a href="http://slides.com/captainsafia/memory-in-javascript#/">Slides</a>)</li><li>Encrypt the Web for $0 — Yan Zhu</li><li>Why Performance Matters — Denys Mishunov (<a href="https://speakerdeck.com/mishunov/why-performance-matters">Slides</a>)</li><li>Natural User Interface using JavaScript — Princiya Sequeira</li><li>Event Sourcing your React-Flux Applications — Maurice de Beijer (<a href="http://www.slideshare.net/mauricedb/eventsourcing-your-reactredux-applications">Slides</a>)</li><li>Internet of Cats — Rachel White</li><li>The other Side of Empathy — Nick Hehr (<a href="https://speakerdeck.com/hipsterbrown/the-other-side-of-empathy-jsconf-budapest">Slides</a>)</li><li>We ❤ Music and the Web — Tim Pietrusky &amp; Martin Schuhfuss</li></ul><p>And the list of talks from <strong>day two</strong>:</p><ul><li>The Formulartic Spectrum — Suz Hinton</li><li>Building an Offline Page for theguardian.com — Oliver Joseph Ash (<a href="https://speakerdeck.com/oliverjash/building-an-offline-page-for-theguardian-dot-com-jsconf-budapest-may-2016">Slides</a>)</li><li>High Performance in the Critical Rendering Path — Nicolas Bevacqua (<a href="https://speakerdeck.com/bevacqua/high-performance-in-the-critical-path">Slides</a>)</li><li>Offensive and Defensive Strategies for Client-Side JavaScript Security — Anand Vemuri</li><li>Changing Live Audio with the Web Audio API — Sam Bellen (<a href="http://sambego.github.io/pedalboard-presentation/#/">Slides</a>)</li><li>Science in the Browser: Orchestrating and Visualising Neural Simulations — Rob Kerr</li><li>HTTP/2 is Coming! Unbundle all the Things?! — Stefan Baumgartner (<a href="https://speakerdeck.com/ddprrt/2-is-coming-unbundle-all-the-things">Slides</a>)</li><li>Down the Rabbithole: JS in Wonderland — Claudia Hernandez (<a href="https://speakerdeck.com/claudiahdz/down-the-rabbit-hole-javascript-in-wonderland">Slides</a>)</li><li>Works on my Machine, or the Problem is Between the Keyboard and the Chair — Lena Reinhard</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pr5qMm5UMKuvgW-w.jpg" /><figcaption>Akvarium Klub Lighting</figcaption></figure><h3>NPM Tips &amp; Tricks</h3><p>One of the great talks from the JSConf was given by the CTO of NPM, <a href="https://twitter.com/seldo">Laurie Voss</a>. <a href="http://slides.com/seldo/jsconf-budapest#/">Laurie’s talk</a> was the first of the JSConf and featured lots of great tips that NPM users can utilise to improve their development workflows.</p><p>Laurie spoke about how you should not have to write anything in your project’s package.json file yourself, as you can use npm init to generate this for you. It is also possible to create a npm-init.js file at the root of your project’s directory, containing some setup configurations to further manage the package.json file of your project.</p><p>There were also lots of tips on how to use npm commands to improve your development workflow, including:</p><pre>$ npm install --cache-min 999999 <br># ensure local installs </pre><pre>$ npm publish --tag <br># publish package and push tags </pre><pre>$ npm deprecate <br># safer alternative to unpublish </pre><pre>$ npm outdated &amp;&amp; npm update <br># check and update outdated dependencies</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p6EpCl7gWPRQz1av.jpg" /><figcaption>Parliament Building</figcaption></figure><p>Another key point I took away from the conference was about web app performance. There were a couple talks around this subject from <a href="https://twitter.com/mishunov">Denys Mishunov</a> on ‘Why Performance Matters’ and <a href="http://www.danielgynn.com/budapest/">Nicolás Bevacqua</a> on ‘High Performance in the Critical Rendering Path’.</p><p>Denys was talking about how performance is not about mathematics, but more about perception, how a user <em>perceives</em> your app to be performing. This is quite an important point, and it’s very useful to think of reducing the time in which the user is waiting ‘passively’.</p><p>Nicolás’ talk was more on the technical side of improving performance and provided some tools to help do this. First, it’s important to know what’s going on, and this can be measured using tools such as the Chrome DevTools Audits and Google’s <a href="http://www.danielgynn.com/budapest/developers.google.com/speed/pagespeed/insights/">PageSpeed Insights</a>. PageSpeed Insights is also available as an <a href="https://www.npmjs.com/package/psi">NPM module</a>.</p><pre>$ npm install -g psi<br>$ psi danielgynn.com</pre><p>It can be useful to set a performance budget to track the impact of every commit, which can be setup using a <a href="https://github.com/tkadlec/grunt-perfbudget">Grunt task</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gKrrkJ_ChHHL6tTt.jpg" /><figcaption>View over the River Danube</figcaption></figure><h3>Empathy</h3><p>A really important issue that several people spoke about at JSConfBP was empathy and how being empathetic to other developers can vastly improve the tech industry as a community. <a href="https://twitter.com/ohhoe">Rachel White</a> spoke about how trying new things can be scary because of things such as fear of rejection and imposter syndrome, and how we could improve this by being more empathetic to people trying new things. Rachel’s talk was inspiring as she had learned several completely new tools to build a <a href="http://imcool.online/robokitty/">Node based cat feeder that works over the web</a> and gave an awesome live demo of this in action.</p><p><a href="https://twitter.com/HipsterBrown">Nick Hehr</a> reiterated some of Rachel’s points, and spoke about how giving constructive and positive feedback is a much better way of helping someone on their project, rather than ranting at someone when something doesn’t work as expected.</p><p>Possibly the most well-received talk of the entire conference was from <a href="https://twitter.com/lrnrd">Lena Reinhard</a> and was called ‘Works On My Machine — or the Problem is between Keyboard and Chair’.</p><blockquote><em>“Privilege is the human version of ‘works on my machine’”</em></blockquote><p>Lena was talking about how the tech industry should look at ‘debugging’ itself and improve on being empathetic to others to increase creativity, diversity and inclusion. There were also lots of ideas on how we can improve ourselves to help debug the system:</p><ol><li><strong>Educate yourself</strong>, about systemic issues and oppression</li><li><strong>Practice empathy</strong> because we need it to be good designers and developers</li><li><strong>Work on humility</strong>, because none of us are Unicorns</li><li><strong>Understanding Privileges</strong>, and use them for good</li><li><strong>Address biases</strong>, and establish policies to address them</li><li><strong>Listen</strong>, and actively look for voices outside of your networks</li><li><strong>Amplify others’ voices</strong>, and speak less</li><li><strong>Work on diversity</strong>, because it’s our moral obligation</li><li><strong>Work on inclusion</strong>, to make spaces welcoming and safe</li><li><strong>Give, our knowledge</strong>, time, technical skills, money</li><li><strong>Work on being allies</strong>, constantly</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7q0FZD1rajk4Mg9v.jpg" /><figcaption>Hero Square</figcaption></figure><h3>Closing</h3><p>I had a great time in Budapest and managed to meet and talk to lots of cool people. The organisers and volunteers did a really great job and managing the event and making it a really great experience for all of us. The speakers were also really great, and I learned a lot of new things which I can use to build myself as a developer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0HhQ7p1SF-wPO_6f.jpg" /><figcaption>Airport Sunset</figcaption></figure><p><em>Originally published at </em><a href="http://www.danielgynn.com/budapest/"><em>www.danielgynn.com</em></a><em> on May 26, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2d97519f172" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Ember.js Components]]></title>
            <link>https://medium.com/@danielgynn/understanding-ember-js-components-920271c15ba0?source=rss-ccaa8143db3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/920271c15ba0</guid>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Daniel Gynn]]></dc:creator>
            <pubDate>Mon, 07 Dec 2015 20:31:00 GMT</pubDate>
            <atom:updated>2016-06-30T08:42:16.550Z</atom:updated>
            <content:encoded><![CDATA[<p>Web developers must work within the limits of the available HTML elements to build the foundations of their web projects. <a href="http://webcomponents.org/">Web components</a> are a new web standard that allow developers to extend the current HTML specification to create custom and reusable elements that better serve their project’s requirements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtqlbmOOJB3L8FPmXdz_eg.jpeg" /></figure><p>The <a href="http://emberjs.com/">Ember.js</a> framework closely follows the <a href="http://w3c.github.io/webcomponents/spec/custom/">W3C’s specification</a> in their implementation of <a href="http://guides.emberjs.com/v2.2.0/components/defining-a-component/">components</a>, which is important as web components are expected to be a big part of the <a href="https://infinum.co/the-capsized-eight/articles/web-components-building-blocks-of-the-future-web">future of the web</a>.</p><p>If you’re unfamiliar with what exactly web components are, you can check out my previous post on <a href="http://www.danielgynn.com/intro-to-web-components/">‘An Introduction to Web Components’</a>.</p><h3>Web Components in Ember.js</h3><p>Ember components consist of two parts: some JavaScript and a <a href="http://colintoh.com/blog/htmlbars">HTMLBars</a> template. The JavaScript component file defines the behaviour and properties of the component. The behaviours of the component are typically defined using <a href="http://guides.emberjs.com/v2.2.0/components/triggering-changes-with-actions/">actions</a>. The HTMLBars file defines the markup for the component’s UI. By default the component will be rendered into a ‘div’ tag element, but a different element can be defined if required. Another great thing about templates in Ember is that other components can be called inside of a component’s template.</p><p>To call a component in an Ember app, you must use {{curly-brace-syntax}}. By design, components are completely isolated which means that they are not directly effected by any surrounding CSS or JavaScript, although the component’s input can be defined by setting attributes.</p><h3>Generating a Component with Ember-CLI</h3><p>In this article I am going to demonstrate a basic Ember component for displaying ‘Pokemon profiles’. The component will render a simple component displaying a Pokemon’s image with some relevant data about that specific Pokemon.</p><p><a href="http://ember-cli.com/">Ember-CLI</a> is the Ember command line tool, it can be used to generate Ember projects with a ‘strong conventional project structure’. We can also use it to generate new Ember components inside the project.</p><p>You’ll need to install Ember-CLI globally on your machine.</p><pre>$ npm install -g ember-cli</pre><p>You can use the CLI to generate new projects, which will install all the required dependencies and then run ‘ember server’ to run the ember application locally.</p><pre>$ ember new ember-components <br>$ cd ember-components <br>$ ember server</pre><p>If your app was created successfully and you head over to <a href="http://localhost:4200/">localhost:4200</a> you should be presented with a heading that says ‘Welcome to Ember’.</p><p>Once the Ember app has been generated and successfully run, a new component can be generated using the following command.</p><pre>$ ember g component pokemon-profile<br>version: 1.13.13 <br>installing component <br>create app/components/pokemon-profile.js <br>create app/templates/components/pokemon-profile.hbs <br>installing component-test <br>create tests/integration/components/pokemon-profile-test.js</pre><p>This will create the required .js and .hbs files needed to define the component, as well as an Ember integration test (which I’ll cover later in another article).</p><p>The components name needs to include a hyphen. This is an Ember convention, but it is an important one as it’ll ensure there are no naming collisions with future HTML elements. Again, this is Ember trying to keep as close to the web component spec as possible.</p><h3>The Component Template</h3><p>To speed things up I am going to include the latest version of the <a href="http://getbootstrap.com/getting-started/">Bootstrap CSS library</a> to the projects app/index.html file. This will create some basic styling for the demo.</p><pre>// app/index.html <br>... <br>&lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css&quot; integrity=&quot;sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7&quot; crossorigin=&quot;anonymous&quot;&gt; <br>...</pre><p>If we simply wanted to display some static information to the page we could just write a small block of HTML without having to create a component. If we wanted to reuse the same code block, but display different information, we could use a component and set some expressions to display the correct data that has been passed into it.</p><p>In the app/templates/components/pokemon-profile.hbs file we can create some basic markup to display the profile of a Pokemon when the component is called.</p><pre>&lt;div class=&quot;col-lg-4 col-sm-6 col-xs-12 text-center&quot;&gt; <br>  &lt;h2&gt;{{name}}&lt;/h2&gt; <br>  &lt;h4&gt;{{type}} type - #{{number}}&lt;/h4&gt; <br>  &lt;p&gt;{{profile}}&lt;/p&gt; <br>  &lt;img src=&quot;{{image}}&quot; class=&quot;img-rounded img-responsive&quot; alt=poke-image width=&quot;500px&quot;&gt; <br>&lt;/div&gt;</pre><p>The {{name}}, {{type}}, {{number}}, {{profile}} and {{image}} are Handlebars expressions which will be used to receive and display the data to display when the component is called.</p><h3>Passing Data to the Component</h3><p>To allow the component to display the data properly, we need to pass it in. There is a longstanding debate in the Ember community over <a href="http://emberigniter.com/should-components-load-data/">whether or not components should load data</a>. For the purposes of this article, the data will be passed in manually for each of the properties placeholders.</p><p>In the app/templates/application.hbs file we can call the component as many times as desired and pass in relevant data for each attribute. Here we are going to add three pokemon-profile’s.</p><pre>... <br>{{pokemon-profile image=&quot;http://cdn.bulbagarden.net/upload/thumb/2/21/001Bulbasaur.png/500px-001Bulbasaur.png&quot; name=&quot;Bulbasaur&quot; type=&quot;Grass&quot; number=&quot;001&quot; profile=&quot;Bulbasaur (Japanese: フシギダネ Fushigidane) is a dual-type Grass/Poison Pokémon. It evolves into Ivysaur starting at level 16, which evolves into Venusaur starting at level 32.&quot; }} </pre><pre>{{pokemon-profile image=&quot;http://cdn.bulbagarden.net/upload/thumb/7/73/004Charmander.png/500px-004Charmander.png&quot; name=&quot;Charmander&quot; type=&quot;Fire&quot; number=&quot;004&quot; profile=&quot;Charmander (Japanese: ヒトカゲ Hitokage) is a Fire-type Pokémon. It evolves into Charmeleon starting at level 16, which evolves into Charizard starting at level 36.&quot; }} </pre><pre>{{pokemon-profile image=&quot;http://cdn.bulbagarden.net/upload/thumb/3/39/007Squirtle.png/500px-007Squirtle.png&quot; name=&quot;Squirtle&quot; type=&quot;Water&quot; number=&quot;007&quot; profile=&quot;Squirtle (Japanese: ゼニガメ Zenigame) is a Water-type Pokémon. It evolves into Wartortle starting at level 16, which evolves into Blastoise starting at level 36.&quot; }} <br>...</pre><p>I have taken the data from the <a href="http://bulbapedia.bulbagarden.net/wiki/Main_Page">Bulbapedia</a> Pokemon database. Now if you view the app in the browser again at <a href="http://localhost:4200/">localhost:4200</a> in the browser, you will see a very simple page displaying the components with the data we passed in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DFV9ZxMFzVeNmyL2.png" /></figure><h3>Adding Interactivity with Actions</h3><p>Ember components can also use {{action}} helpers. In this example we can create a simple button that, when clicked, will either show or hide the Pokemon’s data.</p><pre>… <br>&lt;div class=&quot;col-lg-4 col-sm-6 col-xs-12 text-center&quot;&gt; <br>  {{#if isShowing }} <br>    &lt;h2&gt;{{name}}&lt;/h2&gt; <br>    &lt;h4&gt;{{type}} type - #{{number}}&lt;/h4&gt; <br>    &lt;p&gt;{{profile}}&lt;/p&gt; <br>    &lt;button {{action &#39;profileHide&#39;}} class=&quot;btn btn-primary&quot;&gt;Hide profile&lt;/button&gt; <br>  {{else}} <br>    &lt;img src=&quot;{{image}}&quot; class=&quot;img-rounded img-responsive&quot; alt=poke-image width=&quot;500px&quot;&gt; <br>    &lt;button {{action &#39;profileShow&#39;}} class=&quot;btn btn-primary&quot;&gt;Show profile&lt;/button&gt; <br>  {{/if}} <br>&lt;/div&gt; <br>…</pre><p>The updated component template contains some new HTMLBars expressions that determines whether the profile is showing or not, and whether to display the ‘show profile’ button or ‘hide profile’ button. To define the behaviour of these new expressions, we need to edit the JavaScript file for the component.</p><pre>import Ember from &#39;ember&#39;; </pre><pre>export default Ember.Component.extend({ <br>  isShowing: false, <br>  actions: { <br>    profileShow() { <br>      this.set(&#39;isShowing&#39;, true); <br>    },</pre><pre>    profileHide() { <br>      this.set(&#39;isShowing&#39;, false); <br>    }, <br>  }, <br>});</pre><p>By default, the isShowing variable is set to false, which means that the image will be displayed above the button to ‘show profile’. When the ‘show profile’ button is clicked, the profileShow() function is called which sets the isShowing variable to true and will display the Pokemons profile instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vMUSkeqCf384PXhw.png" /></figure><h3>Customising Components with JavaScript</h3><p>Ember components can also be customised using their corresponding JavaScript file. Here you can define the tag that the element will compile to, what class names it should have and bind data atributes to the component as well.</p><p>A good example of this is a tweet-button component, where you would want to use an anchor tag element and set the class name to ‘twitter-share-button’. Let’s generate a simple tweet-button component using Ember-CLI.</p><pre>$ ember g component tweet-button</pre><p>The <a href="https://dev.twitter.com/web/javascript/loading">Twitter documentation</a> says that to create a tweet button some JavaScript is needed to be added to the projects index.html file.</p><pre>… <br>&lt;script&gt; window.twttr=(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],t=window.twttr||{};if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src=&quot;https://platform.twitter.com/widgets.js&quot;;fjs.parentNode.insertBefore(js,fjs);t._e=[];t.ready=function(f){t._e.push(f);};return t;}(document,&quot;script&quot;,&quot;twitter-wjs&quot;)); <br>&lt;/script&gt; <br>…</pre><p>If you then open the JavaScript file that was generated for the component at app/components/tweet-button.js you are able to set the customisations for the component.</p><pre>import Ember from &#39;ember&#39;; </pre><pre>export default Ember.Component.extend({ <br>  tagName: &#39;a&#39;, <br>  classNames: &#39;twitter-share-button&#39;, <br>  attributeBindings: [&#39;data-url’, &#39;data-text’, &#39;data-size’, &#39;data-hashtags&#39;], <br>});</pre><p>Here we have simply set the HTML tag to an anchor a, the class name to ‘twitter-share-button’ and set attribute bindings for the url, text, size and hashtags of the tweet we want to send out when the button is clicked.</p><p>Now, back in the app/templates/application.hbs file we can call the tweet-button component with the required attributes.</p><pre>… <br>{{tweet-button <br>  data-url=&#39;http://www.danielgynn.com/understanding-ember-components&#39; <br>  data-text=&#39;understanding ember components&#39; <br>  data-size=&#39;large&#39; data-hashtags=&#39;emberjs&#39; <br>}} <br>…</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BnNWXVyeV2ChlEO8.png" /></figure><h3>Conclusion</h3><p>I really feel that web components are going to have a strong presence on the web in the near future, and it’s good to see JavaScript frameworks adopting them. Ember is closely following the W3C conventions for web components and there is some speculation that they are soon to be replacing ‘<a href="http://guides.emberjs.com/v2.2.0/controllers/">controllers</a>’ in Ember.</p><p>Hopefully this basic introduction was helpful in gaining an understanding of how web components work in an Ember app.</p><p>I am planning on writing more on Ember routing and Ember Data in the near future, so look out for those. If you have any suggestions, questions or general comments please leave a comment on this post or <a href="http://twitter.com/danielgynn">send me a tweet</a>.</p><p><em>Originally published at </em><a href="http://www.danielgynn.com/understanding-ember-components/"><em>www.danielgynn.com</em></a><em> on December 7, 2015.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=920271c15ba0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>