<?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[Ember JS - Medium]]></title>
        <description><![CDATA[Articles about the framework for creating ambitious web applications. - Medium]]></description>
        <link>https://medium.com/ember-js-framework?source=rss----9a12a902a6f5---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Ember JS - Medium</title>
            <link>https://medium.com/ember-js-framework?source=rss----9a12a902a6f5---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 14:31:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/ember-js-framework" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[An Agile Design Manifesto for EmberJS]]></title>
            <link>https://medium.com/ember-js-framework/an-agile-design-manifesto-for-emberjs-faae08ce7869?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/faae08ce7869</guid>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Hugh Francis]]></dc:creator>
            <pubDate>Sun, 28 Jun 2015 10:22:54 GMT</pubDate>
            <atom:updated>2015-04-02T16:24:36.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gUF7WndiN4fXHPfpvQdWww.jpeg" /></figure><h2>An Agile Design Manifesto</h2><h4>(for Ember.js)</h4><p>I recently did a talk on this topic at EmberNYC, and Emmett Shine (<a href="https://twitter.com/emmettshine">@emmettshine</a>), my old boss at <a href="http://ginlane.com/">Gin Lane Media</a> in NYC encouraged me to distill it into a Medium post.</p><h3>Ember NYC on Twitter</h3><p>Seeing a sweet demo from @_HHFF and hearing how Ember supports agile design. pic.twitter.com/GXdTJt8bCk</p><p>So! I just finished a shiny new web app with NYC’s Gin Lane Media for <a href="https://order.sweetgreen.com/">sweetgreen</a>, a culinary lifestyle brand dedicated to smartly-sourced, seasonal food — it’s <em>easily </em>the best work of my career. Not because it’s stable and pretty <em>(it is!</em>), but because of how we approached the build — and in particular, how we ran design in parallel to development.</p><p><a href="https://instagram.com/p/yKXJ--kBjy/">If you live in NY, DC, Philly, Boston, Virginia &amp; Maryland, @sweetgreen&#39;s awesome online ordering is now live for EVERY location!!!! The healthiest UX ever 🍃</a></p><p>Before I get into the nuts and bolts of our process, it’s important to chat about why <strong>Ember is better for design iteration</strong> (at least in an agency setting) than most other javascript frameworks &amp; libraries.</p><blockquote><em>This is not about data immutability or render speeds. This is about running a better business through a deeper understanding of technology.</em></blockquote><p>Things like React, Flux, Backbone and jQuery (amongst many others) fall into the category of “<strong>progressive enhancement</strong>”. They’re libraries that bolt on to a server rendered template, and allow it to do things it couldn’t do before. On the surface, this seems great — you add bit and bobs to the good old browser environment, and only use what you need.</p><p>However, as an ambitious project matures, so does the UI, and it’s requirements. So you reach out and grab another library that does another thing, and then write some <strong>~simple~</strong> code to make <strong>library X</strong> work nicely with <strong>library Y</strong>.</p><h3><strong>Progressive Enhancement sucks when there’s churn in the project’s maintainers.</strong></h3><h3>Tom Dale on Twitter</h3><p>Progressive Enhancement: Zed&#39;s Dead, Baby. http://tomdale.net/2013/09/progressive-enhancement-is-dead/ ...</p><p>Leaving a team with a <strong>Fat Slab of Custom Code™</strong> that bolts libraries together, and then bolts those libraries to the browser and API means a brittle, unmaintainable codebase.</p><blockquote><em>Custom code in an agency setting is a huge liability (unless you’ve got some amazing employee retention, or infinite time, that is…)</em></blockquote><p>Enter technologies like Ember, Meteor, Angular and others. Instead of enhancing the browser with a slice of functionality, they act more as a full application stack that runs in the browser environment, and provide developers with a shared solution for common tasks (routing, presentation logic, data fetching + modeling, and so on).</p><blockquote>“At some point recently, the browser transformed from being an awesome interactive document viewer into being the world’s most advanced, widely-distributed application runtime.” <strong>— </strong><a href="http://tomdale.net/2013/09/progressive-enhancement-is-dead/"><strong>Tom Dale</strong></a></blockquote><p>In exchange for this enormous productivity boost, you’ll lose some low level control over the browser’s fabric. Experienced developers are usually uncomfortable with this, but that’s happened before…</p><blockquote>*cough, Rails*</blockquote><p>Something that isn’t immediately obvious, however, is how quickly an opinionated framework can help you identify patterns and core themes throughout your work.</p><p>Rails helped us do this with service layer programming — and now Ember is helping us uncover hidden workflow efficiencies for the user interface.</p><blockquote><em>Whether you agree with it’s opinions or not, an opinionated framework surfaces non-obvious efficiencies for both the codebase and business.</em></blockquote><p>Sam Selikoff’s (<a href="https://twitter.com/samselikoff">@samselikoff</a>) Ember Conf 2015 is illuminating:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FiwPsNTkyCcA%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiwPsNTkyCcA&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FiwPsNTkyCcA%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/e807a04cf681e15fc2a1c91fa5c997fa/href">https://medium.com/media/e807a04cf681e15fc2a1c91fa5c997fa/href</a></iframe><h3>How to wield Ember’s View Hierarchy</h3><p>Ok! Back to Agile Design.</p><p>Something that is generally glossed over in blog posts, meetups, screencasts and everywhere people talk about Javascript is Ember’s predictable view hierarchy. It something only a full application environment can provide — <strong><em>and it’s enormously powerful</em></strong>.</p><p>For the sweetgreen project, we ran design and development in parallel. We’d never done that before, but because we knew Ember’s internal presentation rules, we were able to develop a standardized approach to describing UI elements with CSS, so that all interface code was uniform across the project.</p><h3>CSS Is Hard.</h3><p>In the past, we would organize our CSS semantically.</p><p>It would make sense for a few weeks at the start of the project, but as it evolved and the designs changed, we would have to do big refactors just to move a piece of markup to a different part of the page, zig zagging between multiple markup &amp; CSS files. It was chaos, but it felt unavoidable.</p><blockquote>“It’s a, erm, toggle thingy outer wrapper, right? Call it that!” — <strong>Me, circa 2012</strong></blockquote><p>Erik Bryn (<a href="https://twitter.com/ebryn">@ebryn</a>) did an exciting lightning talk (<em>more on that talk below</em>) at EmberConf2015 about managing CSS in Ember.</p><blockquote><em>His main point, however, is that CSS is hard — because it is global.</em></blockquote><p>Like anything that is global, if you’re making changes without a complete understand of the entire codebase, you can never be entirely sure that your changes won’t have unintended side effects… <strong>unless you have a solid set of conventions in place for managing that “global-ness”, of course</strong>.</p><h3>Organize SCSS by Route &amp; Component</h3><p>We organize SCSS by Route &amp; Component. Ember guarantees that certain templates will only be on the page once, and certain templates will only ever be nested in others.</p><p>We can use this to our advantage!</p><p><em>For the sake of this example, let’s say you needed a primary flash queue for the entire application, and a secondary flash queue specific to the Posts Show route, with a different background color.</em></p><h4>Here’s the templates:</h4><ul><li><strong>templates/application.hbs</strong></li></ul><pre>{{flash-messages queue=&quot;system-wide&quot;}}<br>{{outlet}}</pre><ul><li><strong>templates/posts.hbs</strong></li></ul><pre>&lt;div id=&quot;posts&quot;&gt;<br>  {{outlet}}<br>&lt;/div&gt;</pre><ul><li><strong>templates/posts/show.hbs</strong></li></ul><pre>&lt;div id=&quot;posts-show&quot;&gt;<br>  {{flash-messages queue=&quot;individual-posts&quot;}}<br>&lt;/div&gt;</pre><h4>Here’s the Flash Messages Component</h4><ul><li><strong>components/flash-messages.js</strong></li></ul><pre>import Ember from &quot;ember&quot;;</pre><pre>export default Ember.Component({<br>  classNames: [&#39;flash-messages&#39;]<br>});</pre><h4>Here’s the CSS:</h4><ul><li><strong>stylesheets/app.scss</strong></li></ul><pre>@import &quot;components/*&quot;;<br>@import &quot;routes/*&quot;;</pre><ul><li><strong>stylesheets/components/_flash_messages.scss</strong></li></ul><pre>/* <br>Base Styling for the Flash Messages component - how it will appear globally.<br>*/</pre><pre>.flash-messages {<br>  background-color: $default-flash-color;<br>}</pre><ul><li><strong>stylesheets/routes/_posts.scss</strong></li></ul><pre>/* <br>Global Styling for the &quot;Posts&quot; resource.  It&#39;s an ID because it&#39;s guaranteed to only ever appear on the page once.</pre><pre>Thanks Ember!<br>*/</pre><pre>#posts {<br>  @import &quot;show&quot;;<br>  @import &quot;new&quot;;<br>  @import &quot;edit&quot;;<br>}</pre><ul><li><strong>stylesheets/routes/posts/_show.scss</strong></li></ul><pre>/* <br>Styling here is specifically for this on the &quot;Show&quot; route of the &quot;Posts&quot; resource.  </pre><pre>Most likely, it&#39;s empty, but it&#39;s a good place to override the global appearance of components, and ensure those changes are contained to this route only. <br>*/</pre><pre>#posts-show {<br>  .flash-messages {<br>    background-color: $posts-show-flash-color;<br>  }<br>}</pre><h3>Style Tiles</h3><p>Because we knew we were going to iterate quickly on the visual design of the app — we needed a sane way for parts of the app to be a) designed and b) implemented.</p><p>We approached the designs by exploding the wireframes down into their atomic components, and designing “Style Tiles” for each one. This meant that we had mini style guides for each little component, and the developer could simply piece together these parts to create more complex components and layouts with ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7157GQZ1lxzZImaNKfYEbQ.png" /></figure><h3>Interactive Styleguide</h3><p>Joseph Bergdoll (<a href="https://twitter.com/josephbergdoll">@josephbergdoll</a>) , one of the two designers on the project is a <strong>CSS grand maester</strong>, and we wanted to leverage his skill without having to onboard him to the entire Ember ecosystem.</p><p>We built a live sandbox route in the Ember App that he could work from. Whenever a new Ember component was built, we’d add it to the “styleguide” route, so that Joseph could build out the nitty gritty visual detail and interaction style, without having to delve too deep into real application code.</p><p><em>It’s still live in production here:</em></p><h4><a href="https://order.sweetgreen.com/styleguide"><strong>order.sweetgreen.com/styleguide</strong></a></h4><h3>LayerVault</h3><p><a href="https://layervault.com/">First of all, R.I.P LayerVault.</a> In case you haven’t used it, it essentially works like Github for images, PSDs, AIs, Sketch Files, and more.</p><p>It became an extremely sophisticated tool (<a href="https://github.com/layervault/ember-cli-stripejs.git">that also used Ember CLI in places of their interface</a>). It really took the pain out of asking designers to bounce out the latest versions of their work, and made design iteration feel breathless for all involved.</p><p>We’re upset that the service is shutting down — it was a god send for our process. I’m excited to see what Kelly (<a href="https://twitter.com/KellySutton">@KellySutton</a>) and the team do next (and what they can open source from their learnings!).</p><h3>LayerVault on Twitter</h3><p>Learn how @ginlane, our latest customer to provide a testimonial, uses LayerVault in their agile process. - http://bit.ly/1Acdq0n</p><h3>Looking toward Ember 2.0</h3><p>We’re definitely not the first people to pick up on Ember’s “design friendliness”. Ember is being used all around the web to create brilliant User Experiences. Here’s a collection of people who are realizing it’s power in the UX world:</p><h4>EmberConf2015</h4><p><strong>More than half of the EmberConf2015 talks were focused directly on Design and User Experience</strong>. That is no mistake. The folks behind Ember (emphasis on folks - not companies) are aware that the <em>“perfect javascript framework</em>” is not wholly based on metrics like performance, etc.</p><blockquote><em>More than half of the EmberConf2015 talks focused directly on Design or User Experience.</em></blockquote><p>Instead, they understand that javascript “best practices” are a moving target, and while Ember strives to be a snapshot of those, the best way to provide value at a conference is to <strong>focus on something the JS community at large can agree on</strong>.</p><p>Lauren Tan (<a href="https://twitter.com/sugarpirate_">@sugarpirate_</a>) compiled EmberConf2015 resources here:</p><p><a href="https://github.com/poteto/emberconf-2015">poteto/emberconf-2015</a></p><p>She also spoke at EmberConf2015 — and her talk is fantastic.</p><h4>ember-component-css</h4><p>Erik Bryn, AKA the “Human HTMLBars Hype Machine” (his words <a href="https://twitter.com/EmberNYC">@EmberNYC</a> 2014) did a fantastic little talk about CSS at EmberConf2015.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FT1zxaEKeq3E%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DT1zxaEKeq3E&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2FT1zxaEKeq3E%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/5a626fd7bb15b4ab953d83fcf988dfb5/href">https://medium.com/media/5a626fd7bb15b4ab953d83fcf988dfb5/href</a></iframe><p>Changes in Ember 2.0 and innovations downstream from Ember CLI are going to mean that it will make a ton of sense to store your CSS right next to your logic file, and template file for a given component.</p><pre>- components<br>   |<br>    - flash-messages<br>      |<br>       - template.hbs<br>       - component.js<br>       - styles.css</pre><p>Erik has created an Ember CLI Addon that encapsulates that workflow. I’d encourage you to try it out as soon as possible! This is the type of thinking we need to bring CSS into 2015.</p><p><a href="https://github.com/ebryn/ember-component-css">ebryn/ember-component-css</a></p><h4>Thoughtbot: Ember is for Designers</h4><p>This article from Thoughtbot (<a href="https://twitter.com/thoughtbot">@thoughtbot</a>) is fantastic.</p><h3>thoughtbot on Twitter</h3><p>Ember is for Designers http://robots.thoughtbot.com/ember-is-for-designers ... by @drapergeek</p><h3>Ember is Kool Aid</h3><p>Ember is extraordinarily powerful — for those that drink the Kool Aid.</p><p>Like how it acts in the browser, it’s a “whole hog” type of thing — if you decide to use it, for best results, that should be the only paradigm you use.</p><p>If you adopt Ember for your business horizontally, for now, keep in mind that it’s a long play. Slowly but surely you’ll start to notice that the same feature that took your devs 3 weeks to build a year ago for a different project is taking a few days now. You’ll notice that the visual changes your designer wants aren’t accidentally breaking things on different pages. You’ll notice that fixes from one client will directly benefit another.</p><p>And with all of that, your build times will decrease, and margins will stay strong. I’m sure Dockyard (<a href="https://twitter.com/DockYard">@DockYard</a>) can attest to that.</p><blockquote><em>For now however, please just order a </em><a href="https://order.sweetgreen.com/"><em>sweetgreen</em></a><em> salad, and know that that salad was 7 months worth of Ember.JS in the making.</em></blockquote><p><a href="https://instagram.com/p/yM6F9eFCyo/?taken-by=sweetgreen">a healthy dose of eye candy - check out our new mobile-friendly online ordering experience at order.sweetgreen.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=faae08ce7869" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ember-js-framework/an-agile-design-manifesto-for-emberjs-faae08ce7869">An Agile Design Manifesto for EmberJS</a> was originally published in <a href="https://medium.com/ember-js-framework">Ember JS</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Gulp.js to ember-cli]]></title>
            <link>https://medium.com/@cullymason/from-gulp-js-to-ember-cli-450f1ffb1967?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/450f1ffb1967</guid>
            <dc:creator><![CDATA[Cully Mason]]></dc:creator>
            <pubDate>Tue, 13 May 2014 22:19:05 GMT</pubDate>
            <atom:updated>2014-05-14T17:44:03.353Z</atom:updated>
            <content:encoded><![CDATA[<h4>a how &amp; why</h4><blockquote>Full disclaimer: I am not pretending to be an expert, so I am open to your input. Be nice ☺</blockquote><p>Today started out frustrating. I reviewed some code several times that I had written and it looked correct. I kept getting the same errors over and over again. Despite my best efforts, I couldn’t even get my Ember app to render. I decided to close everything, take a break and revisit this later. Right as I was closing all of my windows and tabs, I realized something infuriating — I had mistyped something in a handlebars template earlier and gulp just quit. There was no warning. Just a silent error. Why wouldn’t it just keep trying to compile until I fixed the error? This was not the first time this had happened.</p><p>My first intuition was just to find some <a href="https://www.npmjs.org/package/gulp-plumber">plugin</a> (thanks @<a href="https://twitter.com/jonkoops">JonKoops</a>) that would fix this problem as I’m sure I am not the first this has happened to. However, I had just watched a <a href="http://confreaks.com/videos/3307-emberconf2014-software-productivity-and-ember-ember-cli">video</a> of <a href="https://twitter.com/stefanpenner">Stefan Penner</a> on <a href="https://github.com/stefanpenner/ember-cli">ember-cli</a> and it looked promising. It looked like it solved the problem mentioned above and also it looked like it would address a few more of my fears of switching away from gulp.</p><p>I was apprehensive to switch to ember-cli. Truthfully, I had a build solution that worked, it just didn’t work well. And ember-cli is still considered a work in progress. What if I spend a bunch of time switching code to only end up in a similar situation? At least I am familiar with the the situation I am in now. Also, ember-cli was built on top of <a href="https://github.com/broccolijs/broccoli">broccoli</a>. I know many people are in love with broccoli, but would it really be worth learning yet another build tool? And I know es6 is cool, but my project doesn’t implement it at all. I am not that familiar with it in the first place. How hard would it be to convert all of my old code to use it?</p><p>I decided to only give myself the first half of the day to try to convert my project from a custom gulpjs build to an ember-cli build. If I could not get it done, I would just try using it on some future project.</p><p>In less than 4 hours I had completely replicated the project with ember-cli. And it worked.</p><p>Am I happy I switched to using ember-cli? Was it worth it? Absolutely. Here’s why:</p><h3>Installation is a breeze</h3><pre><strong>npm</strong> install -g ember-cli</pre><pre><strong>ember</strong> new <em>projectName</em><br><strong>cd</strong> <em>projectName</em><br><strong>ember</strong> server</pre><p>done. With just a few commands, My project had been scaffolded, any dependencies had been brought in with <a href="http://bower.io/">bower</a>, those dependencies as well as your source code were compiled with broccoli, a server was started and it has autoload built in. As a bonus, all of your code is scrubbed with jshint (which quickly reminded me that I don’t like to use semicolons). I do not know if it gets any easier than that.</p><h3>ES6 and the Ember Resolver are awesome</h3><p>Like I mentioned earlier, I was scared to dive into the foreign world of ES6. What is a transpiler anyway? But if you take the time to read through the <a href="http://iamstef.net/ember-cli/">ember-cli</a>, you will realize that with the help of the Ember Resolver, the changes you will have to make are pretty common sense. Plus the <a href="https://github.com/cavneb/loom-generators-ember-appkit">generators</a> built into ember-cli give you a pretty good starting point. Let’s walk through a simple example.</p><p>Say you wanted to create a controller for the comments section for a given post for your app. So you type:</p><pre>ember generate controller post/comments</pre><blockquote>This messed me up when I first started. Notice how you don’t type ‘ember generate <strong>postComments</strong>’<em> </em>but <strong>post/comments</strong><em>.</em> Anything that is nested in your app will be nested in the command.</blockquote><p>It will ask you whether you want to create an array controller, object controller or neither. Once you make your choice, under the controllers folder, ember-cli will create a folder named <em>post</em> and a file named <em>comments.js.</em> If you open up the <em>comments.js</em> file, you will see the following:</p><pre>var PostCommentsController = Ember.ObjectController.extend({</pre><pre>});</pre><pre>export default PostCommentsController;</pre><p>Which isn’t much different than what I am used to:</p><pre>App.PostCommentsController = Ember.ObjectController.extend({</pre><pre>});</pre><p>Once I realized how similar the code was, a majority of my move to ember-cli was just a copy and paste job with a few caveats:</p><ol><li>The <a href="http://iamstef.net/ember-cli/#naming-conventions">naming convention</a> is a bit different than what I am used to. If something in your app is multiple words, name the file with hyphens, and inside the app use camelCase. <strong>Also, all filenames are lowercase</strong>. So if you want to create a route called “My Awesome Site”, the file would be called my-awesome-site.js and you would export MyAwesomeSiteRoute.</li><li>Because you aren’t putting everything in the global App namespace, things like mixins are handled a little differently. Say you wanted to write a mixin to ensure that the comments from the controller above are filterable. So you would type <em>ember generate mixin filterable. </em>Of course under the<em> mixins/filterable.js </em>you get this:</li></ol><pre>var filterable = Ember.Mixin.create({});<br>export default filterable;</pre><p>To use it, you need to <em>import</em> it into your controller file. So it looks like this:</p><pre><strong>import filterable from “appName/mixins/filterable”;</strong></pre><pre>var PostCommentsController = Ember.ObjectController.extend(<strong>filterable</strong>,{<br>});<br>export default PostCommentsController;</pre><p>If you look at the <a href="http://iamstef.net/ember-cli/#using-modules">docs</a>, there are a few ways to import your mixins, helpers and such. I found what made the most sense was to base your path on what you called your app.</p><blockquote><strong><em>Note:</em></strong> <em>If you forgot what you called your app, you can see under your index.html file in the statement </em>window.projectName = require(‘<strong>project-name</strong>/app’)[‘default’].create(ENV.APP);</blockquote><h3>When your controller has needs</h3><p>If you have a controller that depends on another controller, you typically type:</p><pre>needs: [‘postComments’]</pre><p>As stated in the <a href="http://iamstef.net/ember-cli/#naming-conventions">docs</a>, because of the way files are nested using ember-cli, you would need to make a few minor changes:</p><pre>needs: [<strong>“post/comments”</strong>],<br>postComments: Ember.computed.alias(‘controllers.post/comments’)</pre><p>and whenever you need it, you can use it like any other property:</p><pre>var commentsController = this.get(‘postComments’);</pre><h3>What about ember-data?</h3><p>When you create a new project, the beta for ember-data is included and using it is <a href="http://iamstef.net/ember-cli/#ember-data">well documented</a>.</p><h4>Creating Models</h4><p>The ember-cli generator does not include models but it is straight forward to create yourself. If you wanted to create a Post model, you would create a post.js file in the models folder that looks like this</p><pre>export default DS.Model.extend({<br>// attributes go here<br>});</pre><p>With only that code, how does Ember know that it is a Model for a Post? The Ember resolver is smart enough to know that since you placed post.js in the Models folder, that it must be a Model named Post. In fact, this works for other parts of your app like your Controller and Route files.</p><h4>Adapters and Serializers</h4><p>Even though ember-cli didn’t generate folders for adapters or serializers, you can create them yourself. An adapter for your Post model would reside in app/adapters/post.js. Application wide adapters and serializers will be contained in the their appropriate folders in a file named application.js.</p><h4>Fixtures</h4><p>Because my project had previously been in production, I didn’t need to use the fixture adapter, but I have previously. I would say this is probably where the documentation is a bit lacking (or I probably just missed it) but nonetheless here is how to get up and running with fixtures:</p><ol><li>I created an <em>application.js</em> in the <em>app/adapters</em> folder that contains a single line: <em>export default DS.FixtureAdapter.extend();</em></li><li>Lets say you need fixtures for A Task Model. Under your <em>app/models</em> directory, you would create a file called <em>task.js </em>that looks like this:</li></ol><pre>var Task = DS.Model.extend({<br> title: DS.attr(‘string’),<br> description: DS.attr(‘string’),<br>});</pre><pre><strong>Task.reopenClass({<br> FIXTURES: [<br> { id: 1, title: ‘Title A’, description: ‘Body A’, owner: 1 },<br> { id: 2, title: ‘Title B’, description: ‘Body B’, owner: 2 }</strong></pre><pre><strong> ]<br>});</strong></pre><pre>export default Task;</pre><p>After that, you are up and running with fixtures.</p><h3>Bower is your friend again</h3><p>I think bower, in concept, is awesome. I always start out using it. But unfortunately, as my project becomes larger I tend to forget about it. Because you don’t use globals with ember-cli I was a bit worried how using outside scripts would work. As it turns out, it is very straight forward. In my current project I use a <a href="https://github.com/SheetJS/js-xls">tool</a> that reads excel files. In order to use it, I use bower to pull in the dependency. Then in my Brocfile, tell broccoli where it can be found like so:</p><pre>app.import(‘vendor/js-xls/xls.js’);</pre><p>And that was it.</p><h4>Using Ember.js Beta</h4><p>Ember-cli only pulled in 1.5.1. No problem. I just opened up my bower.json and changed the ember line to:</p><pre>“ember”: “<strong>1.6.0-beta.3</strong>&quot;</pre><p>and it just worked.</p><h3>Done?</h3><p>Once I was done converting my code I simply typed <em>ember build</em> and all of my code was compiled and minified into a <em>dist</em> directory.</p><h3>Theres more..</h3><p>But, this is getting a bit long. Really switching to ember-cli from a tool like grunt or gulp is very painless. The biggest “hurdle” if you want to call it that, was naming everything appropriately and in true Ember.js style, the error messages are extremely helpful. The best part is that through the migration to ember-cli, I ended up with code that was better organized and cleaner. Also, the build times are insanely fast.</p><p>Even better, after I got done converting my project, I had an idea for a component that I never really hammered out because I didn’t want to go through the hassle of setting up a new project for just a component. With ember-cli, that was just a generator away.</p><h3>The road ahead</h3><p>There are a few things that I didn’t fully get to try or figure out but will investigate in the future:</p><ul><li><strong>Testing</strong>. I know this is bad, but I never really fooled with it on my ember apps because it took so much time to set up. At first glance, ember-cli appears to offer a very approachable way to get into testing. Several of the generators also generate a test file.</li><li><strong>SASS/CSS/Bootstrap</strong> I just ran out of time. I know ember-cli can <a href="http://iamstef.net/ember-cli/#asset-compilation">do it</a>, but for now I just included bootstrap inside my app/styles folder.</li></ul><p>Hopefully this will help others make the same migration I have. I cannot see myself going back to anything else. The pace at which ember-cli is improving is insane and is only getting better. If you have any questions, please feel free to reach out to me on <a href="https://twitter.com/cullymason">Twitter</a>. I am by no means an expert, but I will do my best. As always Ember has an excelent support community and there is a very useful #ember-cli channel on freenode.</p><p>Cheers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=450f1ffb1967" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Ember helper for CSS and testautomation.]]></title>
            <link>https://medium.com/@xjrlokix/an-ember-helper-for-css-and-testautomation-abdb71016bcc?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/abdb71016bcc</guid>
            <dc:creator><![CDATA[Ben Fredericson]]></dc:creator>
            <pubDate>Thu, 08 May 2014 17:57:41 GMT</pubDate>
            <atom:updated>2014-05-08T20:48:14.204Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/desat/multiply/blue/60/overlay/blue/1*KCdEmdMY659FTcFUr6MiBQ.jpeg" /></figure><h4>Add the current Route name to the body tag</h4><p>I am currently writing a larger Ember.js application with a lot of different pages. I didn’t find a good way to set a layout for each page based on the Route I am in.</p><p>Here is a JSBIN example: <a href="http://jsbin.com/xeganopi/2/edit">http://jsbin.com/xeganopi/2/edit</a></p><p>One way would be to write the current route name to the body. This way, I could write my CSS classes like this:</p><blockquote>body.my_posts { … }<br>body.post { … }<br>body.account{ … }</blockquote><p>This makes even more sense when you structure your CSS with SASS or LESS into clean modules. In Ember, you just have to extend the Route object after your Ember.Application.create.</p><blockquote>Ember.Route.reopen({ … });</blockquote><p>Extend the two main methods beforeModel and afterModel.</p><blockquote>beforeModel: function(transition){<br>var path = Ember.get(transition, ‘targetName’); Ember.$(‘body’).attr(“class”, path.replace(/\./g, ‘_’) );<br>}</blockquote><p>This will set the name of the current loading Route to the body (or html) tag. Now add another call to the afterModel.</p><blockquote>afterModel: function(model, transition) {<br>Ember.$(‘body’).addClass(‘loaded’);<br>}</blockquote><p>Why the “loaded” in the afterModel? When you make an AJAX call in the model function which returns a promise, you might want to show an indicator. Once the model is loaded, the afterModel event will add the class to the body tag. This helps you to define certain CSS classes for loaded and not loaded styles. This will also help you, if you use Selenium or other testautomation to determine if a page is fully loaded or not.</p><p>Here is a JSBIN example: <a href="http://jsbin.com/xeganopi/2/edit">http://jsbin.com/xeganopi/2/edit</a></p><p>Keep in mind, you need to call the this._super(); method every time you add these methods to a new Route. Otherwise you will overwrite the methods in the Ember.Route.reopen.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abdb71016bcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Drag and Drop Image Upload w/ Ember JS]]></title>
            <link>https://medium.com/@mgphotoworks/drag-and-drop-image-upload-w-ember-js-c19e99f9823c?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/c19e99f9823c</guid>
            <dc:creator><![CDATA[Mahonri Gibson]]></dc:creator>
            <pubDate>Tue, 22 Apr 2014 17:56:22 GMT</pubDate>
            <atom:updated>2014-05-05T17:44:56.374Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/desat/multiply/grey/60/overlay/grey/1*uSwJjAOITldbEeMfIj4avQ.jpeg" /></figure><h4>Multiple file upload with preview</h4><p>I want to start this out with the disclaimer that I am no Ember.js expert, in fact I am very much a beginner, both to Ember.js and JavaScript frameworks in general. I’m writing this tutorial largely to help myself learn, and if I can help anybody else out in the process, so much the better. With that said, if I haven’t scared you off, let’s start this learning process together.</p><p>This tutorial assumes you have a basic understanding of how Ember works, I won’t dive into subjects such as setting up the application or how the router works.</p><blockquote><a href="http://jsfiddle.net/mahonrig/Wq6De/19/">If you would like to see the end result before we get started, I’ve set up a jsfiddle here.</a></blockquote><p>The fiddle isn’t the prettiest, since I’m going to focus on the functionality, but all it needs is some css styles to integrate it into your site, however you please.</p><h4>The Plan</h4><p>We’re going to implement a system so that when a user drops one or more image files onto a specified area of the screen, a shadow box will fade in containing a large view of each of the images, with input fields for various information (in this example just a title) and buttons for canceling or submitting.</p><p>Once either the cancel or submit buttons are pressed, that image will fade out, with the next image moved up into it’s place. It’s also possible to scroll through the images, submitting them in whichever order you please.</p><p>When submitted, the client will send an XHR background request to the specified server, which will save the image, and return JSON which then gets pushed to the Ember store. Once all images have been saved or canceled, the shadow box fades back out, returning you to the site.</p><h4>Implementation</h4><p>We’ll start out with the handlebars templates, since they’re simple and straightforward. Include the following at the top of your main application template, below the body tag:</p><pre>&lt;div class=&#39;shadowBox&#39;&gt;{{view App.NewImagesContainer}}&lt;/div&gt;</pre><p><em>App.NewImagesContainer</em> will be an empty <em>ContainerView</em>, which is used whenever you want to be able to programmatically add or remove views, which we’ll be doing, adding and removing separate views for each of the images that are dropped. You can get more details <a href="http://emberjs.com/api/classes/Ember.ContainerView.html">here</a> if you would like.</p><p>We don’t want this to show up yet, so also include the following css in your stylesheet:</p><pre>.shadowBox {<br> display: none;<br> position: fixed;<br> top: 0; left: 0;<br> background-color: rgba( 0, 0, 0, .8);<br> overflow: scroll;<br> z-index: 500;<br>}</pre><p>Next, add in the following template scripts:</p><pre>&lt;script type=&quot;text/x-handlebars&quot; data-template-name=&quot;dropbox&quot;&gt;<br> &lt;div class=&quot;dropBox&quot;&gt;Drop Here&lt;/div&gt;<br>&lt;/script&gt;</pre><p>Above is the template for the drop box area, and you can also add the following to your main application template (or any of your templates) wherever you would like the dropbox to appear:</p><pre>{{view App.DropBoxView}}</pre><p>Below is the template for the display of each of the new images. It’s this template and view that will be added and removed from the application for each photo.</p><pre>&lt;script type=&quot;text/x-handlebars&quot; data-template-name=&quot;newImageDetails&quot;&gt;<br>  &lt;div class=&quot;newImageDetails&quot;&gt;<br>     &lt;img class=&quot;newImage&quot; {{bind-attr src=&quot;view.src&quot;}} /&gt;&lt;br /&gt;<br>     {{view Ember.TextField value=view.title}}<br>     &lt;button type=&quot;button&quot; {{action &quot;cancel&quot; target=&quot;view&quot;}}&gt;Cancel&lt;/button&gt;<br>     &lt;button type=&quot;button&quot; {{action &quot;submit&quot; target=&quot;view&quot;}}&gt;Submit&lt;/button&gt; <br>   &lt;/div&gt;<br>&lt;/script&gt;</pre><p>Above we have a couple things going on, the preview of the image is inserted, with it’s <em>src</em> attribute bound to <em>view.src. </em>Next is an <em>Ember.TextField </em>with the value set to <em>view.title. </em>If you would like to collect more information about each image, you can add additional text fields, setting each value to a <em>view.variable</em>. After that are two buttons, which have actions targeting the view (otherwise the actions get sent to the current controller, which we won’t be using here).</p><p>I have these two templates styled in the following way, feel free to adjust for your uses:</p><pre>.dropBox {<br> height: 150px;<br> width: 200px;<br> text-align: center;<br> font-size: 2em;<br> background-color: #333;<br> margin-top: 50px;<br>}</pre><pre>.newImageDetails {<br> margin: 0 auto;<br> padding: 5%;<br> width: 90%;<br> text-align: center;<br> z-index: 200;<br>}</pre><h4>The Views</h4><p>Alright, time to actually use some javascript. First we’ll add the <em>ContainerView</em> to wherever you keep your view related code (views.js etc.)</p><pre>var container = Ember.ContainerView.extend({<br> observeLength: function(){<br>   if (this.get(&#39;length&#39;) &gt; 0){<br>     $(&#39;.shadowBox&#39;).width($(window).width())<br>     .height($(window).height())<br>     .fadeIn();<br>   } else {<br>     $(&#39;.shadowBox&#39;).fadeOut();<br>   }<br> }.observes(&#39;length&#39;)<br>});</pre><pre>App.NewImagesContainer = container.create();</pre><p>What I’m doing here is extending the default <em>ContainerView</em> with a function observing the length of the container, that controls whether or not the shadowbox is displayed. Whenever a view is added or removed from this container, it will check to see if the shadow box should appear or dissapear. The last line creates an instance of our extended container into <em>App.NewImagesContainer.</em></p><pre>App.DropBoxView = Ember.View.extend({<br> templateName: &#39;dropbox&#39;,<br> dragEnter: function(event) {<br>   event.preventDefault();<br> },</pre><pre> dragOver: function(event) {<br>   event.preventDefault();<br> }, </pre><pre>});</pre><p>The above is the initial setup for our DropBoxView, which should be included in your template wherever you would like the dropbox to appear. We need to set functions to handle the dragEnter/Over functions, or funky stuff happens that prevents the actual drop from happening. These functions are also the perfect place to provide some feedback to the user when dragging, such as changing the background of the target area. Here’s the code for the drop event, which should be inserted just after the dragOver function.</p><pre>drop: function(event) {<br> event.preventDefault();<br> var files = event.dataTransfer.files;<br>  /* Loop through each dropped image */ <br>  for (var i = 0; i &lt; files.length; i++){<br>   if (files[i].type.match(&quot;image.*&quot;)) {<br>     /* Push a new view representing our photo to the container within the shadowbox */<br>     App.NewImagesContainer.pushObject(<br>       App.NewImagesView.create({<br>         file: files[i],<br>       })<br>     );<br>    }<br>  }<br>},</pre><p>First, we’re grabbing the array of files dropped from the event object and storing it in our <em>files</em> variable. After that, we loop through the array, checking each file to see if it’s an image. If so, we’re then pushing a <em>NewImagesView </em>(which we haven’t added yet)<em> </em>into our <em>NewImagesContainer</em> with it’s <em>file</em> attribute set to the current file in the loop.</p><p>Next is the start of our <em>NewImagesView</em>:</p><pre>App.NewImagesView = Ember.View.extend({<br> templateName: &#39;newImageDetails&#39;,<br> title: &#39;Untitled&#39;, /* Default title */<br> src: &#39;&#39;, /* Image src */<br> /* file: is set upon create during drop event */<br> /* For file preview, get the image data */<br> setsrc: function(){<br>   var that = this;<br>   var reader = new FileReader();<br>   reader.readAsDataURL(this.get(&#39;file&#39;));<br>   reader.onload = function(imgsrc){<br>     that.set(&#39;src&#39;, imgsrc.target.result);<br>   }<br> }.observes(&#39;file&#39;).on(&#39;init&#39;),</pre><pre>});</pre><p>Here we set what template is used, our default title, and a function that observes <em>file</em> which loads a new <em>FileReader</em> object to get the image data within the <em>file</em> attribute, and set that to the <em>src</em> attribute. This will fire as soon as the new view is created. Next is our cancel action:</p><pre>actions: { <br>  /* remove image */<br> cancel: function(){<br>   App.NewImagesContainer.removeObject(this);<br> },<br>}</pre><p>This simply removes the view from the container. If this was the last view, the container will fade the shadow box back out. Now let’s setup our submit function.</p><pre>submit: function(){<br> var that = this;<br> var formData = new FormData();<br> formData.append(&#39;file&#39;, this.get(&#39;file&#39;));<br> formData.append(&#39;title&#39;, this.get(&#39;title&#39;));</pre><pre> xhr = new XMLHttpRequest();<br> xhr.open(&#39;POST&#39;, &#39;/image/new&#39;);</pre><pre> xhr.onload = function() {<br>   var response = JSON.parse(xhr.responseText);<br>   App.Image.store.push(&#39;image&#39;, {<br>     id: response.id,<br>     title: response.title,<br>     largeFile: response.largeFile,<br>     mediumFile: response.mediumFile,<br>     smallFile: response.smallFile,<br>     thumbFile: response.thumbFile<br>   });<br>   /* Remove our view object */<br>   App.NewImagesContainer.removeObject(that); <br> }</pre><pre> /* Send out our request */<br> xhr.send(formData);<br> <br>}</pre><p>This is a pretty big chunk, but lets walk through it. First we create a new <em>FormData</em>, then append our file and title into it (include any other fields you may have created). We then create a new <em>XMLHttpRequest</em>, and open it to send a POST request to our endpoint. The <em>xhr.onload</em> function handles the response that we get back from the server. Here I show an example of how I handled it in my application. The server resizes and stores the image, adds it to the database, then returns JSON with the id and other data that my Image model needs. I grab this data from the <em>responseText</em>, and push it into my store, and Ember helpfully propagates the new data throughout the application. After that, we remove this view from the container.</p><p>And that’s it. That’s all you’ll need client side to implement a drag and drop image preview and upload with Ember. Hopefully I’ve helped someone out there who’s having difficulty using Ember. Again, the working fiddle for this example is <a href="http://jsfiddle.net/mahonrig/Wq6De/19/">here</a>.</p><p>Please feel free to comment or message me with any questions / comments / critiques. I would love if anybody has a way to improve this code, I’m always looking to learn.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*NYfQi27PD_Y1TOyeVjFnOg.jpeg" /></figure><p>Mahonri Gibson is a photographer and boat bum, who recently redesigned his <a href="http://mgibsonphotoworks.com/">photographic portfolio</a> as a single page Ember application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c19e99f9823c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to build a realtime chatting app with Firebase and EmberJS from Scratch]]></title>
            <link>https://sterlingcobb.medium.com/how-to-build-a-realtime-chatting-app-with-firebase-and-emberjs-from-scratch-8ef614acf820?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/8ef614acf820</guid>
            <dc:creator><![CDATA[Sterling Cobb]]></dc:creator>
            <pubDate>Mon, 21 Apr 2014 21:20:15 GMT</pubDate>
            <atom:updated>2014-04-21T21:22:44.815Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/desat/multiply/grey/60/overlay/grey/1*3e4xdupK16KCCqQFoWcg3w.png" /></figure><h4>Includes a video and step by step guide</h4><iframe src="https://cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DoJgfnXRF8PM&amp;src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FoJgfnXRF8PM%3Ffeature%3Doembed&amp;type=text%2Fhtml&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/96740c8725ca39bfafdc776b3bae7a25/href">https://medium.com/media/96740c8725ca39bfafdc776b3bae7a25/href</a></iframe><p>I recently gave a talk at our local EmberJS meetup here in SLC about using firebase with EmberJS. I didn’t record the presentation so thought it would be nice to include a video with a code walkthrough on how someone might go about doing this.</p><h4><strong>Things to know before doing this</strong></h4><ul><li>Basic EmberJS</li><li>Javascript</li></ul><h4><strong>Things I’ll be covering</strong></h4><ul><li>How firebase works (their reference system etc)</li><li>How to build a custom EmberJS array proxy</li><li>How to sync data to firebase using said emberJS array proxy</li></ul><h4><strong>How Firebase Works</strong></h4><p>Firebase is a realtime data storage that allows you to create client side applications and make API calls to their service instead of writing your own sever. This is really cool because not only do you not have to write a server, but you can also take advantage of their real time data hooks. I’m not sure of their actual implementation because I haven’t been able to find anywhere where they mention how it actually works however I’m assuming it uses WebSockets+Flash and other fallbacks kind of like socket.io</p><p>In firebase you can store strings, numbers, booleans or child data (javascript objects). The first thing you do in firebase is grab a reference to a location in your data. For instance, your data might be stored at <a href="https://samplechat.firebaseio-demo.com/users">https://SampleChat.firebaseIO-demo.com/users</a> so you would grab a location Reference at that url. I could go further into how this works but firebase did a great job creating docs about how everything works. I’ll make notes along the way to make sure nothing is too confusing. <a href="https://www.firebase.com/docs/">Firebase Documentation</a></p><h4><strong>EmberJS array proxies</strong></h4><p>For this project, we are going to create an EmberJS array proxy. Here are the official EmberJS docs. <a href="http://emberjs.com/api/classes/Ember.ArrayProxy.html">Array Proxy Docs</a>. Feel free to review that. Array proxies are custom EmberJS arrays that you can use in your application. We need this so we can sync our data in our application with the data in firebase.</p><h3>Ok! Finally! Lets get started!</h3><h4>Create the application</h4><p>We are going to start with the Ember App Kit. I found it to be the easiest way to get started writing real EmberJS applications. In this tutorial, I’ll be using my App Kit Repository that I’ve set up to support Stylus out of the box as well as it has all of the html and styles for our Mr. Chat application all ready build. Download it here: <a href="https://github.com/fourcolors/appkit-mrchat">https://github.com/fourcolors/appkit-mrchat</a> After downloading it, in your terminal do a:</p><pre>npm install</pre><p>once that has finished do</p><pre>grunt server</pre><p>NOTE!: You must have grunt-cli installed. You may need to manually install it with:</p><pre>npm install -g grunt-cli</pre><p>After the server has started you should be able to go to <a href="http://localhost:8000/">http://localhost:8000</a> and see something that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*UirTHMqnRFm4LtUGyu9OBA.png" /><figcaption>Make sure there aren’t any other servers running on the 8000 port or else you will have conflicts.</figcaption></figure><h4><strong>Create a firebase account</strong></h4><p>I won’t spend a lot of time explaining this but go to <a href="http://www.firebase.com/">www.firebase.com</a> then create an account. You need to then create a new firebase application under their system. This will be the firebase app you are syncing your data to.</p><h4><strong>Starting with the routes</strong></h4><p>It’s best practice to start with the router in EmberJS. In our application, we will be using the index.hbs template so we don’t need to worry about the router. By default, this template will be called when emberJS opens. Go ahead and open app -&gt; templates -&gt; index.hbs You will see it has all of the html the page needs plus some commented out items we will be using later. If you open app -&gt; routes -&gt; index.js you will see a route file ready to use. This is where we are going to pass our custom Array (Embers ArrayProxy) into our controller. This is also where we are going to create our reference. Create something that looks like this:</p><pre>export default Ember.Route.extend({<br> model: function() {<br>   // code goes here<br> }<br>});</pre><h4><strong>Creating the custom ArrayProxy</strong></h4><p>Normally, we would return an EmberJS array that would be consumed by the controller however we need to create a custom array that will hold on to our ‘ref’ (firebase reference) and pull/push data to firebase when things are changed. That way, we can keep our data in sync with firebase as things change in our EmberJS application. To do this, lets create a new folder called <strong>lib </strong>in app -&gt; lib</p><p>Then create a file called <strong>messages.js </strong>in the lib folder. app/lib/messages.js Finally, we will make a blank ArrayProxy using ECMA6 type models. If you are’t familiar with that type of module, educate thy self! <a href="http://www.2ality.com/2013/07/es6-modules.html">Awesome explanation</a> Your file should look like this:</p><pre>// app/lib/messages.js<br>export default Ember.ArrayProxy.extend({<br> // Custom code will go here <br>});</pre><p>Ok now we need to make this thing actually work. What we are going to do is create a property called “ref” on this array that will be the reference url to our firebase data. When “ref” is set, we want to pull down all of the messages from the firebase servers so we have some initial data. We then want to create a custom function on this object that handles pushing data to firebase. Lets see how this might look.</p><pre>// app/lib/messages.js<br>export default Ember.ArrayProxy.extend({<br> ref: null,<br> loadContent: function(){<br> var _this = this;</pre><pre> this.ref.on(‘value’, function(snapshot){<br>   var messages = _.map(snapshot.val(), function(value, key){<br>   value.id = key;<br>   return value;<br> });</pre><pre> _this.set(‘content’, messages);</pre><pre> });</pre><pre> }.observes(‘ref’),</pre><pre> pushMessage: function(message){<br>   this.ref.push(message);<br> }<br>});</pre><p>Ok so there is a bit going on here so let me explain. First we set ref to null. This is because we want to be able to reuse this array for may different refs. We will set the ref of this array in the route. Next, loadContent. A lot is going on here but its only doing two things, pulling data from firebase, then re-formatting that data into a form ember can use. Lets take a look at the this in two parts.</p><pre>var _this = this;</pre><pre>this.ref.on(‘value’, function(snapshot){<br> // deleted the code in here so you don’t get confused :p<br>});</pre><p>In firebase, given a reference, you can do ref.on(‘value’, function(snapshot){}); This will return a snapshot of data at that reference point given the ‘value’ event. The value event happens when 1. the event is first created (aka initialized) and 2. When a new child is added to that reference point. Note that a “snapshot” isn’t the actual data. You need to do snapshot.val() for it to return the actual firebase data.</p><p>The inner part of the function takes care of formatting the JSON like data you get back from firebase into an array of data with keys.</p><pre> var messages = _.map(snapshot.val(), function(value, key){<br>   value.id = key;<br>   return value;<br> });</pre><pre> _this.set(‘content’, messages);</pre><p>Lastly we set the array proxies ‘content’ which is the values the array will actually use.</p><p>The observes(‘ref’) part ensure that we pull data down whenever ‘ref’ is changed.</p><p>The last part of this array proxy is the pushMessage part</p><pre>pushMessage: function(message){<br>  this.ref.push(message);<br>}</pre><p>In firebase, you can do ref.push(foo) to push data to their servers. Our array should be able to handle this so does. NOTE: you might be wonder, “Hey Sterling, thats fine and all but don’t we need to also push the message to the ArrayProxy?” and the answer is no, why? Well, once we push the message to firebase, our ref.on(‘value’, ….) code will detect that something was added and update the array with the proper content. Make sense?</p><h4><strong>Back to the router</strong></h4><p>Ok now we have our custom array, we can put it all together and make it work. Open up app/router/index.js We are going to use our new array here. First we need to import our messages module we created then use it. It should look like this</p><pre>// app/routes/index.js<br>import Messages from &#39;appkit/lib/messages&#39;;</pre><pre>export default Ember.Route.extend({<br> model: function() {<br>   var messages = Messages.create({});<br>   messages.set(&#39;ref&#39;, new Firebase(&quot;<a href="http://your-firebase-app.firebaseio.com/messages">http://your-firebase-app.firebaseio.com/messages</a>&quot;));</pre><pre> return messages;<br> }<br>});</pre><p>Notice we are creating a new array then setting that array’s reference with our firebase reference. Awesome. So you might be wondering, “Sterling, why the hell don’t you just set the reference on initialization?” Good question, I wanted to do that too but it turns out when you initialize the new array proxy setting it’s content wasn’t possible unless you pass it in on create. Please if anyone know how to do this, just message me, I’m interested.</p><h4><strong>Lastly, hook up the template and controller</strong></h4><p>We want to hook up the template and controller so we can display the messages and enter something in to actually hit the firebase servers. Lets start with the template. Open up index.hbs Delete the placeholder html input fields and uncomment the ember handlebars input helpers. Your index.hbs file should now look something like this</p><pre>&lt;div class=”container”&gt;<br> &lt;h1 class=”text-center”&gt;Mr. Chat&lt;/h1&gt;<br> &lt;div class=”stash”&gt;&lt;/div&gt;</pre><pre> &lt;div class=”chatbox jumbotron”&gt;<br> &lt;ul id=”messageList”&gt;<br>   {{#each}}<br>     &lt;li&gt;{{username}} -&gt; {{message}}&lt;/li&gt;<br>   {{/each}}<br> &lt;/ul&gt;<br> &lt;/div&gt;</pre><pre> &lt;form {{action “sendMessage” on=”submit”}} class=”form-inline” role=”form”&gt;<br>   &lt;div class=”form-group pull-left” style=”width:18%; margin-right:2%;”&gt;<br>   &lt;label class=”sr-only” for=”username”&gt;Username&lt;/label&gt;<br>     {{input value=username type=”text” class=”form-control” id=”username” placeholder=”Username”}}<br>   &lt;/div&gt;<br>   &lt;div class=”form-group pull-left” style=”width:80%;”&gt;<br> &lt;div class=”input-group”&gt;<br>   {{input value=message id=”message” name=”message” type=”text” class=”form-control” placeholder=”Message”}}<br>   &lt;span class=”input-group-btn”&gt;<br>     &lt;button class=”btn btn-success” type=”submit”&gt;Send&lt;/button&gt;<br>   &lt;/span&gt;<br>   &lt;/div&gt;<br> &lt;/div&gt;<br> &lt;/form&gt;<br>&lt;/div&gt;</pre><p>We need to create the controller action to handle the sendMessage event we described in the .hbs. To do this, open up index.js in app/controllers/index.js and replace it with this:</p><pre>var IndexController = Ember.ArrayController.extend({<br> actions:{<br>   sendMessage: function(){<br>     this.get(‘model’).pushMessage({‘username’: this.get(‘username’), ‘message’: this.get(‘message’)});<br> this.set(‘message’, ‘’);<br>   }<br> }<br>});</pre><pre>export default IndexController;</pre><p>All we are doing here is grabbing the model we previously created, our array proxy, and calling the pushMessage method we created on that array proxy. We grab the username and message data and push it to our application. We then clear everything.</p><p>Here is a link to the completed branch git with everything put together. <a href="https://github.com/fourcolors/appkit-mrchat/tree/finished">https://github.com/fourcolors/appkit-mrchat/tree/finished</a></p><h4>Conclusion</h4><p>There are obvious better ways to do this. One of the annoying parts of this approach is the need to constantly add your firebase domain name to routers. You should instead have a solution where you define your base domain name once. Beyond that, that information should be defined someone in a model layer, not the router. This however is a nice quick way to get into firebase without over architecting yourself into a hole. I highly recommend you look at <a href="https://github.com/rlivsey/fireplace">Fireplace</a> which is what I now use for my applications. It has a lot of great features that even EmberFire has yet to implement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ef614acf820" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Migration to Ember.js]]></title>
            <link>https://medium.com/@cullymason/my-migration-to-ember-js-bf0c155f7cfb?source=rss----9a12a902a6f5---4</link>
            <guid isPermaLink="false">https://medium.com/p/bf0c155f7cfb</guid>
            <dc:creator><![CDATA[Cully Mason]]></dc:creator>
            <pubDate>Sat, 16 Jan 2016 17:57:42 GMT</pubDate>
            <atom:updated>2014-04-24T16:53:50.623Z</atom:updated>
            <content:encoded><![CDATA[<h4>and how I convinced my team to “switch”.</h4><p>This started as a brief outline but has turned out to be rather lengthy. I started to go back and simplify but I would rather be comprehensive so that maybe other people could benefit from my journey. I am a little wary to share this because I do not want to get caught in a flame war between what seems like 2000 different frontend frameworks. In the end, I chose Ember.js and and I’d like to share my non overly technical reasoning as to why. But first..</p><h3>Some back story…</h3><p>Just over two years I was hired as an IT intern to help develop an in-house project management web application. The app was initially created a few years ago by a couple of college students as a summer project. As with most projects, it quickly ballooned beyond a simple summer project and, in consequence, a full time employee was hired to develop it. What that employee, my boss currently, did not realize was the app consisted entirely of spaghetti code and quick fixes. For what I am sure seemed like an eternity, he rebuilt the app in a framework. I won’t say which one. Not my favorite framework. But, considering he did most of this in his free time and essentially built everything twice until all of the previous functionality was duplicated, it is hard to complain. Especially as a new hire. Especially as an intern.</p><p>I was hired around a week after “version 2.0&quot; was launched. My job initially was to prototype some interfaces and flows and was pretty much given free reign as far as front end development. In fact, the biggest rule was <strong>Don’t Touch the Backend</strong>. My first assignment was to design an admin interface for an online training section for new employees.</p><p>The assignment started on the “summer project” level. It would just be a list of files that an employee would need as a new hire. Easy. Static site. However, like the project management app before, it grew and became increasingly complicated. Not all of those the files applied to every employee. How would anyone know if they read them? What if they were videos and not files? Who would manage these files? What if there were questions?</p><p>The simple was not simple anymore.</p><h3>The road to Ember.js</h3><p>As the full scope of my assignment grew, it became increasingly clear that I would need something more than jQuery. <em>More than jQuery</em> was a completely foreign idea to me and my team. But as long as I followed the golden rule of not touching the backend, I was free to explore. I quickly found Backbone and relatively quickly built around 30% before I hit a road block. Backbone just wasn’t enough. Categories contained files that were verified by quizzes that had varying pass rates which could be reset by different people. I could not even fathom wiring all of those things together. Also, I had written a gigantic app.js file which was a complete bear to go back through. I needed another upgrade and quickly. After some light research, I was choosing between using Backbone with a handful of extensions/plugins/helpers, Angular and Ember. I want to share how and why I ended up choosing Ember and how that decision made Ember an easy choice for my team’s future projects.</p><h4>I am not a smart man…</h4><p>I consider myself decently proficient at programing but I am, by no means, an expert. I do not know all of the best practices nor do I have the time to learn all of them. Often time a simple Google search is not enough. This was exponentially more true when it came to Javascript.</p><p>One of the more frustrating parts of using Ember initially, but the better part long term, is that it is extremely opinionated. Though things can be overridden and modified, life is a lot easier when you think of things and write things the Ember way. And the Ember way isn’t a bad way. Each time I dug into why Ember was doing things a certain way, I found that it was grounded in a reason that was well thought out and forward thinking. I found that I did not have to know volumes of best practices or the best ways to structure an app; Ember is built on those out of the box. Once you learn the Ember way, you get those for free.</p><p>Better still, when you receive some code written in Ember, you know where to start and generally what to expect.</p><h4>Community</h4><p>I am sure there are more elegant ways to say this, but the community that surrounds Ember is kickass and it may be the biggest reason I ended up using it. Ember is often criticized for its initial learning curve and for me it was no exception. After I wrestled with Ember for around two weeks, I posted a random tweet about how frustrated I was. I woke up the next day with several replies wanting to help. I was taken back. If it weren’t for those replies, I probably would have given up on Ember that day. Instead, a jsbin later, my problem was solved and I was back to building my app. This was not a <a href="http://www.reluctantgourmet.com/fluke-or-flounder-what-is-the-difference/">fluke</a> situation. Nearly every time I reached out for help, whether it be on twitter, Stack Overflow or even Reddit, the community was warm and helpful. Several times even members of the Ember core team took time to answer my frequently noob level questions. In short, the community made it feel like a team of people were helping me on this project.</p><h4>Trust the Docs and Source Code</h4><p>I hate reading docs and source code. Not because I hate reading, but I hate reading things written poorly and often the docs and source code seem like an after thought. Or even worse they seem to be written for people who already understand and are just there for reference. Usually when someone says “look at the Docs” as an answer, I would consider it a lost cause. For those of you who have not read the Ember <a href="http://emberjs.com/api/">API</a> in a while, do yourself a favor and do it. And if that is a bit over your head, read the <a href="http://emberjs.com/guides/">guides</a>. They have come a long way, and I wish that I had these available when I first started.</p><h4>Start small</h4><p>One of the great things about using a frontend framework is that you can start small without scrapping your existing ecosystem. Ember is designed to be versatile yet still remain powerful. The accounting team went rogue and set up their own foreign backend with MSSQL (true story)? No problem. Want build a small section of your app in Ember and leave the rest? I hope you do. That is what I did and the people that used those sections noticed. And it did not burden the people responsible for the backend. They actually prefer it now. Either they specify how something spits JSON out or I do. It doesn’t matter to me. And combining these small sections together was just a matter of changing the router and a few files. I was able to start small and grow.</p><h4>You can actually be at the cutting edge</h4><p>The ember core team is adamant about minimizing breaking changes with each new release (which they aim to do every 6 weeks I believe). What does this mean for you? You can have new features without worrying about it breaking what you have already written. I wanted to start using <a href="http://emberjs.com/guides/routing/query-params/">Query Parameters</a> in some code that I had written a few months ago. I swapped out the older version for the newest version and everything worked. Actually I am convinced it is quite a bit faster. And they are continuing to make it better.</p><h4>This is really the tip of the iceberg…</h4><p>There are a lot of specific things like the routed computed properties that I did not get to touch on but really make this framework powerful. Also, things like the <a href="https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi">Ember Inspector</a> and <a href="https://github.com/emberjs/data">Ember-Data</a> are insanely useful. And projects like <a href="https://github.com/tildeio/htmlbars">HTMLBars</a> and the <a href="https://github.com/stefanpenner/ember-cli">ember-cli</a> show that Ember is only getting better.</p><h3>In conclusion</h3><p>There are flaws in every framework/tool but Ember has thus far proven to be the best fit for where I work and I hope this has at least persuaded you to take a look at Ember. I cannot promise that it will be the right fit, but I’ll try my best to help if you have any questions or concerns. If I cannot, as I said earlier, you have the strength of an awesome community at your disposal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf0c155f7cfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>