<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://bridgetownrb.com/" version="1.2.0">Bridgetown</generator><link href="https://jmd.fm/feed.xml" rel="self" type="application/atom+xml" /><link href="https://jmd.fm/" rel="alternate" type="text/html" /><updated>2025-10-09T17:47:09-07:00</updated><id>https://jmd.fm/feed.xml</id><title type="html">JMD</title><subtitle>John McDowall&apos;s blog posts and thoughts.</subtitle><entry><title type="html">Service Objects Are Totally Fine Actually</title><link href="https://jmd.fm/service-objects-are-totally-fine-actually/" rel="alternate" type="text/html" title="Service Objects Are Totally Fine Actually" /><published>2025-08-01T00:00:00-07:00</published><updated>2025-08-01T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2025-08-01-service-objects-are-totally-fine-actually.md</id><content type="html" xml:base="https://jmd.fm/service-objects-are-totally-fine-actually/">&lt;p&gt;The Ruby community used to have this fairly strong idiom back in the day: Keep Ruby Weird. Nowadays it seems more like just a conference that happens every so often.&lt;/p&gt;

&lt;p&gt;We had folks like “Why The Lucky Stiff”, who’d write these incredibly baroque programs that’d interesting things, really leaning into the intricacies and strange features the Ruby language provided, and sometimes really bending what was possible.&lt;/p&gt;

&lt;p&gt;It was extremely cool. It felt fresh. It felt vibrant. People were trying things. Anything was possible.&lt;/p&gt;

&lt;p&gt;Now, in 2025, to me it feels like what passes the ‘Ruby community’ has become this puritanical, finger wagging, 37Signals sycophantic clique.&lt;/p&gt;

&lt;p&gt;For five years or so now, there’s a regular drumbeat of people wagging their fingers and writing blog posts and tweets about how ‘Service Objects’ are bad, m’kay? I’m not even going to address the merit of these arguments, because they are silly and specious.&lt;/p&gt;

&lt;p&gt;Anyone can construct a strawman of something that people don’t actually do, and say “Well look, this is obviously bad.” It does nothing for the community. Worse I think it’s puritanical and patriarchal - and I’m choosing those terms &lt;em&gt;very&lt;/em&gt; carefully because I think they speak to what I think the root cause of this mindset is.&lt;/p&gt;

&lt;p&gt;It shouldn’t belong in the Ruby community, but I think we’re well past that now.&lt;/p&gt;

&lt;p&gt;But let me paint at least some kind of rebuttal to the ‘Service Objects Bad’ stance.&lt;/p&gt;

&lt;p&gt;I was first introduced to the idea by an article that my friend james Golick wrote in 2010 - &lt;a href=&quot;https://jamesgolick.com/2010/3/14/crazy-heretical-and-awesome-the-way-i-write-rails-apps.html&quot;&gt;Crazy, Heretical and Awesome: The Way I Write Rails Apps&lt;/a&gt; - you should read it.&lt;/p&gt;

&lt;p&gt;Notice he said: “The way &lt;em&gt;I&lt;/em&gt; write apps.” Not “You should write your Rails app this way”. We used to be a community that was happy to share knowledge, not finger wag and tut tut.&lt;/p&gt;

&lt;p&gt;In the article he strongly details his personal philosophical driver is separation of concerns and testability, particularly because back in those days, Rails testing Rails controllers was slow as shit.&lt;/p&gt;

&lt;p&gt;Also note, he is &lt;em&gt;not&lt;/em&gt; just hiding a variable in a class that could have been a method, as the ‘No service objects’ rabble would have you believe this is the only use for this pattern. Again, read the article.&lt;/p&gt;

&lt;p&gt;You can dice this argument up any way you want. It really doesn’t matter. It &lt;em&gt;shouldn’t matter&lt;/em&gt;. It’s baffling to me why these ‘No Service Objects’ guys give a single flying shit about how someone else is writing their code? Maybe someone can explain it to me?&lt;/p&gt;

&lt;p&gt;In my case I use this pattern because it gives me clean, testable, and re-usable units of logic I take with me to many new projects. Maybe that’s one of the differences, the ‘No Service Object’ guys only ever work on one codebase? And are happy with the total spaghetti shit show that comes with Callbacks.&lt;/p&gt;

&lt;p&gt;To close, if you’re reading this and thinking “I need to write an article about how this guy is wrong and shouldn’t use service objects”, I’m asking you to just not do that. No one is going to read your thing and think you’re now a thought-leader bro.&lt;/p&gt;

&lt;p&gt;Just let people write their code the way they want to and stop trying to impose some religious doctrine on how everyone else should program.&lt;/p&gt;

&lt;p&gt;Ruby might not be weird at all anymore, but maybe it’s not too late to push against this tired, pointless bullshit.&lt;/p&gt;</content><author><name></name></author><category term="craft" /></entry><entry><title type="html">Are You Really an Engineer?</title><link href="https://jmd.fm/are-you-really-an-engineer/" rel="alternate" type="text/html" title="Are You Really an Engineer?" /><published>2024-06-05T00:00:00-07:00</published><updated>2024-06-05T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2024-06-05-are-you-really-an-engineer.md</id><content type="html" xml:base="https://jmd.fm/are-you-really-an-engineer/">&lt;p&gt;An engineer—someone who has been formally trained in a school of engineering (whether civil, electrical, or otherwise) and has been called before their association of peers and found worthy—has, at the core of their practice, a belief in the scientific process.&lt;/p&gt;

&lt;p&gt;Distilled down to its very basics, this means that you construct a hypothesis, perform experiments, observe data, and change your hypothesis when the data point to flaws.&lt;/p&gt;

&lt;p&gt;In the world of software development, an ‘engineer’ should have the same mindset. You should try alternative frameworks, styles, tools, and methodologies.&lt;/p&gt;

&lt;p&gt;If you have a cherished belief in something and encounter new data or experiences that suggest your belief is wrong or even slightly incompatible with the hypothesis, you should change that belief.&lt;/p&gt;

&lt;p&gt;Otherwise, you’re just someone who rabidly believes what the tribe believes, operating with received knowledge. That’s not being an engineer. That’s being a zealot.&lt;/p&gt;

&lt;p&gt;However, that’s still better than someone who just uses or believes in something without a genuine opinion or experience but seeks to proselytize that belief as vigorously as a real engineer. That’s not engineering either. That’s being a useful idiot.&lt;/p&gt;

&lt;p&gt;Worse, such a person usually doesn’t even realize they are using their lives in service of some commercial interest that couldn’t care less about their efforts, so in the end nothing is gained.&lt;/p&gt;

&lt;p&gt;So if you believe Rails is the best framework ever made, try Elixir, try Next, try Laravel.&lt;/p&gt;

&lt;p&gt;Still feel the same way? Yes? Great. No? What should change in your mind? What can you bring from those other frameworks you just tried back to your use of Rails?&lt;/p&gt;

&lt;p&gt;If you believe GraphQL is the absolute best solution, try to build the same thing using pure REST. What’s different? Which solution really provides the best leverage?&lt;/p&gt;

&lt;p&gt;Above all else, be brave enough to face the opposite direction from the crowd and turn your back on the latest trends—if that’s what the data and experience tell you, then it’s never wrong.&lt;/p&gt;

&lt;p&gt;That’s engineering.&lt;/p&gt;</content><author><name></name></author><category term="craft" /></entry><entry><title type="html">Animating Hotwire Powered Modals with Stimulus and Tailwind</title><link href="https://jmd.fm/animating-hotwire-powered-modals-with-stimulus-and-tailwind/" rel="alternate" type="text/html" title="Animating Hotwire Powered Modals with Stimulus and Tailwind" /><published>2015-05-25T00:00:00-07:00</published><updated>2015-05-25T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2015-05-25-animating-hotwire-powered-modals-with-stimulus-and-tailwind.md</id><content type="html" xml:base="https://jmd.fm/animating-hotwire-powered-modals-with-stimulus-and-tailwind/">&lt;h2 id=&quot;the-setup&quot;&gt;The Setup&lt;/h2&gt;

&lt;p&gt;It’s now super easy to get Modal dialogues up and running in your Rails app,
thanks to Hotwire and Turbo Streams.&lt;/p&gt;

&lt;p&gt;The following general technique I just leared from Pete Hawkins over at 
&lt;a href=&quot;https://rapidruby.com/&quot;&gt;https://rapidruby.com/&lt;/a&gt;. He’s making great new Rails
content over there, and I try to support any new content makers focussing on 
modern Rails. I highly recommend you check him out.&lt;/p&gt;

&lt;p&gt;Pete’s initial solution did not handle the animation of the modal. It simply 
immediately appeared, and immediately disappeared on dismisal.&lt;/p&gt;

&lt;p&gt;If you know me, you know I need to have that little bit of polish where it feels 
like an interaction has happened. I think it’s better for my users. So I set out
to figure out how to animate this modal in, and out.&lt;/p&gt;

&lt;p&gt;As you’ll see, because we are going to be dismissing the modal by changing the 
modal’s turbo frame source, that means the contents of the frame will immediately
be replaced with new content - there will be no chance to animate anything.&lt;/p&gt;

&lt;p&gt;So my initial plan of attack revolved around the idea of using a Stimulus controller
to hook onto the Modal’s DOM element, target both the backdrop and the dialog parts, override
the dismissal link’s default action, do some CSS jiggery pokery to animate stuff, then
make the modal’s turbo frame update when I am ready, and when the modal has animated out
of view. In list form:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Stimulus controller takes control of the Modal’s DOM element.&lt;/li&gt;
  &lt;li&gt;It should target both the backdrop (so we can animate that) and the dialog.&lt;/li&gt;
  &lt;li&gt;When the controller connects, we can easily add the animation classes then.&lt;/li&gt;
  &lt;li&gt;We will need to hook into the dismissal link and prevent it from causing the 
modal’s turbo frame from updating its src (until we are ready).&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;getting-the-basic-modal-setup&quot;&gt;Getting the basic Modal setup&lt;/h2&gt;

&lt;p&gt;First, you need to add a &lt;code class=&quot;highlighter-rouge&quot;&gt;turbo_frame_tag&lt;/code&gt; into your &lt;code class=&quot;highlighter-rouge&quot;&gt;application&lt;/code&gt; layout that will 
be for any modals you want to appear.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# app/views/layouts/application.html.erb

&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;lang=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;en&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;h-screen&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;layouts&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;partials&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;body&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;antialiased&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;shared&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;flash_alerts&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;yield&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- Add this turbo frame --&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;turbo_frame_tag&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:modal&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; 
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt; 
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, you’ll want a button to open that modal. This is what appears in my ‘Projects’
dashboard:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# app/views/projects/index.html.erb

&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- the data tag targets the modal turbo frame when the link is clicked --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- the link path causes the modal frame to load the new project modal into it --&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;link_to&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;new_project_path&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;data:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;turbo_frame:&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:modal&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;inline-flex&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;items-center&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;rounded-md&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;bg-indigo-600&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;px-3.5&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;py-2.5&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;text-sm&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;font-semibold&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;text-white&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;shadow-sm&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;hover:bg-indigo-500&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;focus-visible:outline&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;focus-visible:outline-2&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;focus-visible:outline-offset-2&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;focus-visible:outline-indigo-600&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;-ml-0.5 mr-1.5 h-5 w-5&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;viewBox=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;0 0 20 20&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;currentColor&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;aria-hidden=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;path&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;d=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;M10.75 4.75a.75.75 0 00-1.5 0v4.5h-4.5a.75.75 0 000 1.5h4.5v4.5a.75.75 0 001.5 0v-4.5h4.5a.75.75 0 000-1.5h-4.5v-4.5z&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
    New Project
&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It targets the &lt;code class=&quot;highlighter-rouge&quot;&gt;:modal&lt;/code&gt; turbo frame you added to the application layout. Next,
we need to prepare the content that needs to be loaded into the modal to also
be wrapped in a &lt;code class=&quot;highlighter-rouge&quot;&gt;turbo_frame_tag&lt;/code&gt; that targets &lt;code class=&quot;highlighter-rouge&quot;&gt;:modal&lt;/code&gt;. I’m using &lt;code class=&quot;highlighter-rouge&quot;&gt;view_components&lt;/code&gt;,
but you can ignore that, it’s just a detail and isn’t specific to this method of
implementing modals in your application:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;# app/views/prooject/new.html.erb

&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;turbo_frame_tag&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:modal&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;ModalComponent.new&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;mt-4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;text-2xl font-bold mt-4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Create a new Project&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;p&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;text-sm leading-tight mt-2 mb-4 text-gray-700&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Creating a new project allows you to create surveys for a particular website.&lt;span class=&quot;nt&quot;&gt;&amp;lt;p&amp;gt;&lt;/span&gt;

      &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;render&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;partial:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&apos;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;locals:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;project:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;project&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;  
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here’s the ERB fragment the component above renders anyway (&lt;em&gt;I’m just using a 
stock TailwindUI fragment for the modal skeleton, because ain’t nobody got time
to reinvent every wheel&lt;/em&gt;):&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;relative z-10&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;aria-labelledby=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;modal-title&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;role=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dialog&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;aria-modal=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fixed pointer-events-auto inset-0 bg-gray-500 bg-opacity-75 transition-opacity&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fixed inset-0 z-10 overflow-y-auto&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;link_to&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;close_modal_path&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;data:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;turbo_frame:&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:modal&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;absolute&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;top-3&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;right-3&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;do&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2000/svg&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;viewBox=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;0 0 24 24&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;currentColor&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;w-6 h-6&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;path&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fill-rule=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;evenodd&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;d=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;clip-rule=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;evenodd&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So with that, you now have a modal dialog that pops up and goes away when it 
should. Literally no additional Javascript was required to get this to happen,
and this is the full power of Hotwire in effect.&lt;/p&gt;

&lt;p&gt;But as you’ll see from this gif, the backdrop and modal both just snap in and
snap out of existence:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/unanimated_modal.gif&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can do better…&lt;/p&gt;

&lt;h2 id=&quot;adding-a-sprinkling-of-javascript-to-make-the-magic-happen&quot;&gt;Adding a sprinkling of Javascript to make the magic happen&lt;/h2&gt;

&lt;p&gt;First, let’s touch up our modal dialog’s HTML so that it will work with the 
Stimulus controller we will create:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;relative z-10&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;aria-labelledby=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;modal-title&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;role=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dialog&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;aria-modal=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;data-controller=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;modal&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fixed pointer-events-auto inset-0 bg-gray-500 bg-opacity-75 transition-opacity opacity-0&quot;&lt;/span&gt; 
    &lt;span class=&quot;na&quot;&gt;data-modal-target=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;backdrop&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;data-entering-classes=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ease-out duration-300 opacity-100&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;data-leaving-classes=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ease-in duration-200 opacity-0&quot;&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;data-action=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;modal#close&quot;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fixed inset-0 z-10 overflow-y-auto&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; 
        &lt;span class=&quot;na&quot;&gt;data-modal-target=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dialog&quot;&lt;/span&gt; 
        &lt;span class=&quot;na&quot;&gt;data-entering-classes=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ease-out duration-300 opacity-100 !translate-y-0&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;data-leaving-classes=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;ease-in duration-200 opacity-0 !translate-y-4 !sm:translate-y-0&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all opacity-0 translate-y-4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;c&quot;&gt;&amp;lt;!-- We will hook into this link in the stimulus controller to prevent it&apos;s default action --&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;link_to&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;close_modal_path&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;data:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;turbo_frame:&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;:modal&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;modal_target:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;dismiss&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&quot;,&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;action:&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;click-&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;modal#close keydown.esc@document-&amp;gt;modal#close&quot;}, class: &quot;absolute top-3 right-3&quot; do%&amp;gt;
          &lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2000/svg&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;viewBox=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;0 0 24 24&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fill=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;currentColor&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;w-6 h-6&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;path&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;fill-rule=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;evenodd&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;d=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;clip-rule=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;evenodd&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class=&quot;nt&quot;&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;%=&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can check out the above code fragment, but I just configured it so that the 
Stimulus controller we’re about to create will attach to it, one target for the backdrop, 
one target for the dialog, and data attributes for entering and leaving css classes
for both. The close modal link got some extra data attribures also got a target and
an action when it is clicked. That’s it.&lt;/p&gt;

&lt;p&gt;Now, on to creating the Stimulus controller that will do our bidding and interrupt
the flow of clicking on the close link to dismiss the modal, and let us do our
animation shenanigans:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Controller&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;@hotwired/stimulus&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Controller&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;targets&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;backdrop&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;dialog&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;dismiss&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Modal controller connected&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropEnteringClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;enteringClasses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropLeavingClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;leavingClasses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogEnteringClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;enteringClasses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogLeavingClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dataset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;leavingClasses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;// Use an animation frame to remove the backdrop leaving classes that might be there&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// and add the backdrop entering classes.&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropLeavingClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropEnteringClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Use an animation frame to remove any dialog leaving classes that might be there&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// and add the dialog entering classes. &lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogLeavingClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogEnteringClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;nx&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// We must stop the link from doing it&apos;s think and changing the modal&apos;s turbo frame source&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;preventDefault&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;abortListener&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;AbortController&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropEnteringClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;backdropLeavingClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;transitionend&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// Remove this event listener because otherwise multiple transitions will&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// cause this function to be called N times, and will generate a console&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// error about the user aborting a request due to the modelEl.src being &lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// set multiple times. Listening for one `transitionend` is fine, because&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// they all have a single duration anyway.&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;abortListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;// Manually we take the close link&apos;s href and set the modal turbo frame&apos;s&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// src to that path (in this case the /close_modal path), which will clear&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// the modal from the screen, magically, thanks to Turbo Frames. &lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dismissTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;modalEl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;querySelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;#modal&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;modalEl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;signal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;abortListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;signal&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

    &lt;span class=&quot;nx&quot;&gt;requestAnimationFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogEnteringClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;classList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;dialogLeavingClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt; &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And here’s how that looks:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/animated_modal.gif&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Smashed it!&lt;/p&gt;

&lt;p&gt;I was pretty amazed that my pseudo code outline plan of attack basically translated
directly into Javascript, and it almost worked exactly from the outset.&lt;/p&gt;

&lt;p&gt;The cool part where I wait for the &lt;code class=&quot;highlighter-rouge&quot;&gt;transitionend&lt;/code&gt; came at the end of development
when I realized that the modal source was being updated before the transition
could complete, so it had this jarring snapping out effect as the contents were 
replaced mid-transition.&lt;/p&gt;

&lt;p&gt;But by waiting for the &lt;code class=&quot;highlighter-rouge&quot;&gt;transitionend&lt;/code&gt; event, you can be guaranteed that the 
transition you care about has ended. So no need to use &lt;code class=&quot;highlighter-rouge&quot;&gt;setInterval&lt;/code&gt; or any other
kind of hacks. And if I decided to change the duration in the future, this code
will still just work™.&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;That’s it! The only thing missing right now is clicking on the modal backdrop
does not dismiss it. This is due to some shenanigans with the way Tailwind is
used to create this modal. I’ll get to it…&lt;/p&gt;

&lt;p&gt;Thanks again to Pete at &lt;a href=&quot;https://rapidruby.com/&quot;&gt;https://rapidruby.com/&lt;/a&gt;
for showing the way. 🙇&lt;/p&gt;</content><author><name></name></author><category term="rails" /></entry><entry><title type="html">Restarting the Rails server from the Rails console</title><link href="https://jmd.fm/restarting-the-rails-server-from-the-rails-console/" rel="alternate" type="text/html" title="Restarting the Rails server from the Rails console" /><published>2023-05-19T00:00:00-07:00</published><updated>2023-05-19T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2023-05-19-restarting-the-rails-server-from-the-rails-console.md</id><content type="html" xml:base="https://jmd.fm/restarting-the-rails-server-from-the-rails-console/">&lt;h2 id=&quot;why-tho&quot;&gt;Why tho?&lt;/h2&gt;

&lt;p&gt;If you’re like me, you have your Rails environment fully dockerized. You have one 
terminal window open that is shelled into the container, and probably running the 
Rails Console. It can be inconvienient to open another terminal window, or drop
out of the Console in order to run a command line invocation to restart the Rails
server process.&lt;/p&gt;

&lt;p&gt;But even if that’s not you, sometimes it’s just useful to be able 
to restart the Rails server with a boot from the Rails console that you’re in.&lt;/p&gt;

&lt;p&gt;Luckily, you can add your own custom commands to the Rails console, and
specifically in this case, Pry. I use Pry (and &lt;code class=&quot;highlighter-rouge&quot;&gt;pry-rails&lt;/code&gt;), and you probably
would like using it too.&lt;/p&gt;

&lt;h2 id=&quot;adding-custom-console-commands-to-the-rails-console&quot;&gt;Adding custom Console commands to the Rails Console&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://island94.org/2023/05/whatever-you-do-don-t-autoload-rails-lib&quot;&gt;Since we don’t autoload &lt;code class=&quot;highlighter-rouge&quot;&gt;/lib&lt;/code&gt; anymore&lt;/a&gt;, create a &lt;code class=&quot;highlighter-rouge&quot;&gt;lib&lt;/code&gt; folder under &lt;code class=&quot;highlighter-rouge&quot;&gt;app&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Create a file in that new &lt;code class=&quot;highlighter-rouge&quot;&gt;app/lib&lt;/code&gt; folder called
&lt;code class=&quot;highlighter-rouge&quot;&gt;rails_console_commands.rb&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Inside that file, place the following code:
    &lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; &lt;span class=&quot;k&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;RailsConsoleCommands&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;restart_server!&lt;/span&gt;
     &lt;span class=&quot;sx&quot;&gt;%x(touch tmp/restart.txt)&lt;/span&gt;
     &lt;span class=&quot;s2&quot;&gt;&quot;Restarting Rails Server...&quot;&lt;/span&gt;
   &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Now, in your &lt;code class=&quot;highlighter-rouge&quot;&gt;development.rb&lt;/code&gt; file, you’re going to tell the Rails console
and Pry to add this new method as a command:&lt;/p&gt;

    &lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;# Add this to the bottom of your development.rb file&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;console&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;nb&quot;&gt;require_relative&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&apos;../../app/lib/rails_console_commands&apos;&lt;/span&gt;
  &lt;span class=&quot;no&quot;&gt;TOPLEVEL_BINDING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;eval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&apos;self&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;extend&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;RailsConsoleCommands&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Now, when you run &lt;code class=&quot;highlighter-rouge&quot;&gt;bin/rails c&lt;/code&gt; and type &lt;code class=&quot;highlighter-rouge&quot;&gt;restart_server!&lt;/code&gt;, you will indeed
see that the Rails server is restarted. Magic!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is a minor improvement to my DX, definitely sharpening the saw here, but 
it honestly saves more than a few seconds every day as I do deep work on my 
Rails app that the in-built code reloading can’t handle. YMMV.&lt;/p&gt;

&lt;p&gt;Obviously there’s no limit to the custom commands you could add. Have fun.&lt;/p&gt;

&lt;p&gt;PS. I was able to piece this together from an ancient blog post Brandon Keepers
wrote on &lt;a href=&quot;https://opensoul.org/2012/11/08/add-helper-methods-to-your-rails-console/&quot;&gt;Adding helper methods to your Rails console&lt;/a&gt; and another post about &lt;a href=&quot;https://web.archive.org/web/20160714011132/https://blog.nhocki.com/2015/06/03/add-helper-methods-to-your-rails-console-with-pry/&quot;&gt;making that work from Pry&lt;/a&gt;.&lt;/p&gt;</content><author><name></name></author><category term="rails" /></entry><entry><title type="html">An experiment in refactoring Ember Properties</title><link href="https://jmd.fm/an-experiment-in-refactoring-ember-properties/" rel="alternate" type="text/html" title="An experiment in refactoring Ember Properties" /><published>2015-07-20T00:00:00-07:00</published><updated>2015-07-20T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2015-07-20-an-experiment-in-refactoring-ember-properties.md</id><content type="html" xml:base="https://jmd.fm/an-experiment-in-refactoring-ember-properties/">&lt;p&gt;You might have run across the situation where you have lots of properties in a Controller or Component, and they have associated Computed Properties that calculate some presence value. They end up feeling like repetitive boilerplate.&lt;/p&gt;

&lt;p&gt;How might you go about cleaning them up? Perhaps auto-generating them?&lt;/p&gt;

&lt;h2 id=&quot;typical-ember-example&quot;&gt;Typical Ember Example&lt;/h2&gt;

&lt;p&gt;Specifically, what kind of code am I talking about? Something like this:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ember&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;na&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 

  &lt;span class=&quot;na&quot;&gt;hasUsername&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;notEmpty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;hasPassword&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;notEmpty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;

  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;etc&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Typically these properties are the results of requirements from the UI to display different elements on particular states. The template will have some conditionals that lean on these properties to achieve this. Depending on how complex the UI is, you could end up having a few of these state properties.&lt;/p&gt;

&lt;p&gt;Let’s look at how we could save ourselves from manually having to define lots of boilerplate properties.&lt;/p&gt;

&lt;h2 id=&quot;take-1-using-embers-defineproperty-method&quot;&gt;Take 1: Using Ember’s &lt;code class=&quot;highlighter-rouge&quot;&gt;defineProperty&lt;/code&gt; Method&lt;/h2&gt;

&lt;p&gt;Ember provides a method which allows you to perform a basic level of meta-programming by defining properties at runtime. The parameters for &lt;code class=&quot;highlighter-rouge&quot;&gt;defineProperty&lt;/code&gt; are (basically):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The object you want to define the new property on&lt;/li&gt;
  &lt;li&gt;The name of the new property&lt;/li&gt;
  &lt;li&gt;A ‘Descriptor’ which for our purposes will be a Computed Property to be attached to the new property&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Which looks like this:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.defineProperty(this, myCpPropName, Ember.computed(&apos;propName&apos;, function(){...});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We’re now going to use a function to pass back to &lt;code class=&quot;highlighter-rouge&quot;&gt;defineProperty&lt;/code&gt; so that the Computed Property has a dynamic value.&lt;/p&gt;

&lt;p&gt;And with that in mind lets look at the solution:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ember&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;notEmpty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;UI_FIELDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Builds a field property name from a field name.&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;_fieldPropName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Utilize ES6 string interpolation. &lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;`has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;capitalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Run once on component init, sets the default empty values for the field&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// and generated the hasPropertyName properties for each field.&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;defineFieldProperties&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;UI_FIELDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;propName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_fieldPropName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;defineProperty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;propName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Unfortunately there’s a bit of a hidden trap here. As it turns out &lt;code class=&quot;highlighter-rouge&quot;&gt;defineProperty&lt;/code&gt; is a relatively slow function, and we’ve just set it up so that the Component is going to execute it every time its initialized. While the technique above would be fine in something long lived like a `Service, it’s no good in a component displayed 100 times. So what do we do?&lt;/p&gt;

&lt;h2 id=&quot;take-2-pre-creating-the-attributes-at-object-creation&quot;&gt;Take 2: Pre-creating the attributes at Object creation&lt;/h2&gt;

&lt;p&gt;The best way to go about this is to pre-generate an Object with the properties and Computed Properties we need, and then re-extend our component with the pre-generated items before we &lt;code class=&quot;highlighter-rouge&quot;&gt;export&lt;/code&gt; it. By taking this approach, Ember will only have to do its &lt;code class=&quot;highlighter-rouge&quot;&gt;defineProperty&lt;/code&gt; magic once and only once.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;ember&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;computed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;notEmpty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// The Component UI fields as before. &lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;UI_FIELDS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;userName&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;password&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Pre-generate an object with the properties and computed&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// properties that we need. &lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;processedAttrs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;UI_FIELDS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;forEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;processedAttrs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;processedAttrs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;capitalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;has&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Create a Component just as you normally would. &lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Component&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Your usual Ember component stuff in here as needed&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;debugOutput&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hasPassword=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hasPassword&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hasUserName=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;hasUserName&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Export the component with an extra extension of our pre&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// generated attributes and computed properties.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;LoginComponent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;processedAttrs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;So obviously this got a little messy looking, as changes to optimize for performance usually make things. That said, the technique above could be abstracted out quite easily to wrap the Ember Component class and handle the necessary heavy lifting without all of the ceremony.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;At the end of our exploration, we can see how it might be possbile to clean up and auto generate boilerplate Computed Properties. In the end things looked a litlle messy, and obviously you wouldn’t use this technique to clean up two properties.&lt;/p&gt;

&lt;p&gt;That said, I feel like there’s the bones of a simple validation system here. You could build a simple form validation system on this technique with some pre-canned validator functions along the lines of the &lt;code class=&quot;highlighter-rouge&quot;&gt;has&lt;/code&gt; function, for example &lt;code class=&quot;highlighter-rouge&quot;&gt;minLength&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;maxLength&lt;/code&gt; and so on. Then the &lt;code class=&quot;highlighter-rouge&quot;&gt;UI_FIELDS&lt;/code&gt; value would be expanded to an object, and each field name would have associated keys describing the validation to use, defaults, etc.&lt;/p&gt;

&lt;p&gt;It was an interesting diversion for me, and hopefuly you learned something new.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eternal thanks to the ever patient and helpful Alex Matchneer, Todd Smith-Salter and Kelly Sutton for their input on this article!&lt;/em&gt;&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /><category term="ember-core" /></entry><entry><title type="html">Announcing Centerline</title><link href="https://jmd.fm/announcing-centerline/" rel="alternate" type="text/html" title="Announcing Centerline" /><published>2015-03-19T00:00:00-07:00</published><updated>2015-03-19T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2015-03-19-announcing-centerline.md</id><content type="html" xml:base="https://jmd.fm/announcing-centerline/">&lt;p&gt;I like to design in the Browser. Sometimes I’m not quite sure if something is fully centered in the Browser window or not, so I made Centerline. Centerline
is just a dumb bookmarklet that adds a global ‘center line’ in your Browser viewport. Here it is:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;javascript:(function()%7Bvar%20v%3D%272.1.3%27%3B%20if%20(window.jQuery%3D%3D%3Dundefined%20%7C%7C%20window.jQuery.fn.jquery%20%3C%20v)%7Bvar%20done%3Dfalse%3B%20var%20script%3Ddocument.createElement(%27script%27)%3B%20script.src%3D%27%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F%27%20%2B%20v%20%2B%20%27%2Fjquery.min.js%27%3B%20script.onload%3Dscript.onreadystatechange%3Dfunction()%7Bif%20(!done%20%26%26%20(!this.readyState%20%7C%7C%20this.readyState%3D%3D%27loaded%27%20%7C%7C%20this.readyState%3D%3D%27complete%27))%7Bdone%3Dtrue%3B%20initCenterLine()%3B%7D%7D%3B%20document.getElementsByTagName(%27head%27)%5B0%5D.appendChild(script)%3B%7Delse%7BinitCenterLine()%3B%7Dfunction%20initCenterLine()%7B(window.centerLine%3Dfunction()%7B%24(%27body%27).append(%27%3Cdiv%20class%3D%22centerLineDiv%22%3E%3C%2Fdiv%3E%27)%3B%20%24(%27body%27).append(%27%3Cstyle%20type%3D%22text%2Fcss%22%3E.centerLineDiv%7Bcontent%3A%22%22%3B%20position%3A%20fixed%3B%20top%3A%200%3B%20bottom%3A%200%3B%20left%3A%2050%25%3B%20border-left%3A%202px%20dotted%20%23444%3B%20z-index%3A%2099999999%3B%7D%3C%2Fstyle%3E%27)%3B%20%24(%27body%27).append(%27%3Cstyle%20type%3D%22text%2Fcss%22%3E.container%7Bborder-left%3A%201px%20solid%20red%3B%20border-right%3A%201px%20solid%20red%3B%7D%3C%2Fstyle%3E%27)%3B%7D)()%3B%7D%7D)()%3B&quot;&gt;CenterLine&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just drag it onto your bookmark bar, and when you need that center line, click the hell out of it. Check it out:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/posts/centerline.png&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To remove, just refresh the page.&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /></entry><entry><title type="html">A 50,000 foot overview of the Ember.js Run Loop</title><link href="https://jmd.fm/a-50,000-foot-overview-of-the-ember.js-run-loop/" rel="alternate" type="text/html" title="A 50,000 foot overview of the Ember.js Run Loop" /><published>2014-10-16T00:00:00-07:00</published><updated>2014-10-16T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2014-10-16-a-50000-foot-overview-of-the-ember-js-run-loop.md</id><content type="html" xml:base="https://jmd.fm/a-50,000-foot-overview-of-the-ember.js-run-loop/">&lt;p&gt;The Ember Zone HQ is currently being assailed by the remnants of the Super Typhoon Vongfong. Look at that thing (image courtesy of &lt;a href=&quot;https://twitter.com/astro_reid&quot;&gt;Reid Weisman&lt;/a&gt;, Astronaut on the ISS), with its whirling loop of chaos in the middle, the eye, which is apparently 80KM wide. The eye is calm, surrounded by the most intense and fastest winds, with the speeds decreasing the further you are from the eye. Ember has its own whirling pseudo-loop of controlled chaos. Let’s look at the strangely named Ember Run Loop.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;At the core of Ember beats the heart of an Accountant. An Accountant who sits at a large desk with six inboxes on it, and the inboxes are always processed in the same order. Items in a given inbox are processed in full before moving onto the next inbox. Sometimes processing a particular inbox will cause items to be added to a previous inbox, and the whole process immediately starts again from the first (highest priority) inbox with unprocessed items in it. This whole routine is performed in order that Ember can take advantage of batches of like things, coalesce them together, and minimize the amount of subsequent work that might otherwise need to be done. This is one of the core features of Ember that makes it fast, even without HTMLBars.&lt;/p&gt;

&lt;h2 id=&quot;embers-six-inboxes&quot;&gt;Ember’s six inboxes&lt;/h2&gt;

&lt;p&gt;We can have Ember show us its secret inboxes, or more correctly &lt;strong&gt;queues&lt;/strong&gt;, at the developer console:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; Ember.run.queues
[&quot;sync&quot;, &quot;actions&quot;, &quot;routerTransitions&quot;, &quot;render&quot;, &quot;afterRender&quot;, &quot;destroy&quot;]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;the-sync-queue&quot;&gt;The Sync Queue&lt;/h3&gt;

&lt;p&gt;This is the queue that settles all binding updates, and has the highest priority. You’re almost never likely to schedule something in here yourself. This is the place of the fast winds that surround the calm eye of Ember’s hurricane.&lt;/p&gt;

&lt;h3 id=&quot;the-actions-queue&quot;&gt;The Actions Queue&lt;/h3&gt;

&lt;p&gt;This queue contains things that should be processed after all of the binding updates have been synchronized and before any Views are rendered. This is the general workhorse queue in Ember, and is the place where any Promises will get sent to. Any call to &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run&lt;/code&gt; will place the item in this queue.&lt;/p&gt;

&lt;h3 id=&quot;the-router-transitions-queue&quot;&gt;The Router Transitions Queue&lt;/h3&gt;

&lt;p&gt;Anything in your Ember Application that signals a Transition should happen will end up in here. You’re almost never likely to schedule something in here yourself.&lt;/p&gt;

&lt;h3 id=&quot;the-render-queue&quot;&gt;The Render Queue&lt;/h3&gt;

&lt;p&gt;This queue contains items that cause changes in the DOM, and is mostly fed from items that were processed in the Actions queue. You’re almost never likely to schedule something in here yourself.&lt;/p&gt;

&lt;h3 id=&quot;the-afterrender-queue&quot;&gt;The AfterRender Queue&lt;/h3&gt;

&lt;p&gt;Sometimes you might need to update a DOM element that is created as part of processing an item that would have rendered in the Render queue. You would use the &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run.schedule(&apos;afterRender&apos;, function() { ... })&lt;/code&gt; call to schedule your function to be run in this queue, after Ember has rendered all of its DOM changes. This is probably the queue you’ll deal with the most, as you use it to help schedule jQuery plugins attaching to DOM elements, for example.&lt;/p&gt;

&lt;h3 id=&quot;the-destroy-queue&quot;&gt;The Destroy Queue&lt;/h3&gt;

&lt;p&gt;The Destroy queue is pretty much as it sounds – the queue where things that should be destroyed (Views that are no longer shown, etc) are placed, and processed last, and has the lowest priority. You’re almost never likely to schedule something in here yourself, either. At this level, we’re at the slow moving winds that dump fat rain drops onto small islands.&lt;/p&gt;

&lt;h2 id=&quot;scheduling-things-on-the-queues&quot;&gt;Scheduling things on the Queues&lt;/h2&gt;

&lt;p&gt;The two main methods you’ll probably need to use are &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run.next&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run.schedule&lt;/code&gt;. The &lt;code class=&quot;highlighter-rouge&quot;&gt;next&lt;/code&gt; function is used to schedule something to happen in a completely new run loop, that will happen some time after (you don’t know when) the current run loop has cleared. The &lt;code class=&quot;highlighter-rouge&quot;&gt;schedule&lt;/code&gt; function is for when you want to schedule something to be processed in the current run loop, on a particular queue. If you’re certain that the thing you want to schedule should only be scheduled once, then use &lt;code class=&quot;highlighter-rouge&quot;&gt;scheduleOnce&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A lot of common advice is to use &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run.schedule&lt;/code&gt; and the &lt;code class=&quot;highlighter-rouge&quot;&gt;afterRender&lt;/code&gt; queue inside places like &lt;code class=&quot;highlighter-rouge&quot;&gt;didInsertElement&lt;/code&gt; when handling jQuery plugins and so on, and it is almost always the correct default. That said, I’ve had instances where scheduling a jQuery plugin hook inside the current run loop’s &lt;code class=&quot;highlighter-rouge&quot;&gt;afterRender&lt;/code&gt; queue just wouldn’t work, and indeed needed to be scheduled in the next run loop using &lt;code class=&quot;highlighter-rouge&quot;&gt;next&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When you use &lt;code class=&quot;highlighter-rouge&quot;&gt;next&lt;/code&gt;, because it schedules the item for the next run loop, which will run an indeterminate amount of time after the current run loop, you may encounter CSS issues with sudden flashes, or document re-flowing. This is usually an indicator you should be using &lt;code class=&quot;highlighter-rouge&quot;&gt;scheduleOnce&lt;/code&gt; on the &lt;code class=&quot;highlighter-rouge&quot;&gt;afterRender&lt;/code&gt; queue.&lt;/p&gt;

&lt;h2 id=&quot;day-to-day-use-of-the-ember-runloop&quot;&gt;Day to day use of the Ember Runloop&lt;/h2&gt;

&lt;p&gt;Chances are you’ll never need to directly invoke placement of a function on any of the Run Loop’s queues, but the most common scenario where you might need to is the &lt;code class=&quot;highlighter-rouge&quot;&gt;afterRender&lt;/code&gt; queue because you want to manipulate a DOM element that Ember has rendered as part of a &lt;code class=&quot;highlighter-rouge&quot;&gt;View&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;Component&lt;/code&gt;. Usually, you’ll be doing this because you wish to use some jQuery provided effect or third party component.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;The Ember Run Loop is a powerful mechanism that allows Ember to minimize the work it needs to do to keep bindings up to date, propagate changes, and reduce the amount of DOM manipulations that need to happen. Hopefully this article has given you the 20% of the information you’ll need for 80% of the time.&lt;/p&gt;

&lt;p&gt;For the other 20% of the time, you can also look at the following excellent resources for more information:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/eoinkelly/ember-runloop-handbook&quot;&gt;The Ember Run Loop handbook&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://talks.erikbryn.com/backburner.js-and-the-ember-run-loop/&quot;&gt;Backburner.js and the Ember Run Loop by Erik Bryn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://alexmatchneer.com/blog/2013/01/12/everything-you-never-wanted-to-know-about-the-ember-run-loop/&quot;&gt;Everything You Never Wanted to Know About the Ember Run Loop&lt;/a&gt;&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /><category term="ember-core" /></entry><entry><title type="html">A Simple Auto Expanding Textarea Component</title><link href="https://jmd.fm/a-simple-auto-expanding-textarea-component/" rel="alternate" type="text/html" title="A Simple Auto Expanding Textarea Component" /><published>2014-10-09T00:00:00-07:00</published><updated>2014-10-09T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2014-10-09-a-simple-auto-expanding-textarea-component.md</id><content type="html" xml:base="https://jmd.fm/a-simple-auto-expanding-textarea-component/">&lt;p&gt;Greetings! The nights are drawing in pretty quickly here, and it’s also additionally pretty dark in the morning due to the mountain I live next to and the added darkness is making it pretty difficult to maintain my early morning routines. A short and sweet post this week about how to extend the built-in Ember.js Textarea View so that it auto expands to contain the text inside it, but first a short interlude into a recent poll I ran on Ember.js usage:&lt;/p&gt;

&lt;!--more--&gt;

&lt;blockquote&gt;
  &lt;p&gt;The results can be seen here: &lt;a href=&quot;http://strawpoll.me/2695391/r&quot;&gt;http://strawpoll.me/2695391/r&lt;/a&gt;. Admittedly, it’s an extremely small sample size, but I was shocked to see Rails in the minority. It’s good to see Ember-CLI leading the pack, as it’s a great project – and the results overall make me feel more comfortable about writing more Ember-CLI related posts in the near future. On to today’s post…&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When we need a &lt;code class=&quot;highlighter-rouge&quot;&gt;Textarea&lt;/code&gt; in one of our Templates, we can simply use the &lt;code class=&quot;highlighter-rouge&quot;&gt;textarea&lt;/code&gt; helper like so:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;p&quot;&gt;{{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textarea&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;notes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that will render a basic text area bound to the &lt;code class=&quot;highlighter-rouge&quot;&gt;notes&lt;/code&gt; property. But it will be a static &lt;code class=&quot;highlighter-rouge&quot;&gt;textarea&lt;/code&gt; that does not accommodate content that is larger than its style will permit without scroll bars. What if we wanted the &lt;code class=&quot;highlighter-rouge&quot;&gt;textarea&lt;/code&gt; to automatically grow vertically as more text is entered, without resorting to any external jQuery plugins?&lt;/p&gt;

&lt;p&gt;First of all, we create a new &lt;code class=&quot;highlighter-rouge&quot;&gt;Component&lt;/code&gt; that &lt;code class=&quot;highlighter-rouge&quot;&gt;extends&lt;/code&gt; the Ember &lt;code class=&quot;highlighter-rouge&quot;&gt;TextArea&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;AutoExpandingTextAreaComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TextArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;snip&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If we just left the new &lt;code class=&quot;highlighter-rouge&quot;&gt;AutoExpandingTextAreaComponent&lt;/code&gt; as is above, we could use it in any template with &lt;code class=&quot;highlighter-rouge&quot;&gt;&apos;}} and its behaviour would be exactly the same as the default&lt;/code&gt;textarea`. So far, so obvious.&lt;/p&gt;

&lt;p&gt;The trick here for us, is that we want the &lt;code class=&quot;highlighter-rouge&quot;&gt;textarea&lt;/code&gt; to be aware of any keypresses, and change its size accordingly. We’ll use the &lt;code class=&quot;highlighter-rouge&quot;&gt;didInsertElement&lt;/code&gt; hook to attach an event listener for &lt;code class=&quot;highlighter-rouge&quot;&gt;keypress&lt;/code&gt;es on the text area:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;AutoExpandingTextAreaComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TextArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;didInsertElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Focus the text area&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;focus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// Listen for keypress events and recalculate the height of the text area.&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;keypress&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;newHeight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scrollHeight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;parseFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;borderTopWidth&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;parseFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;borderBottomWidth&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

          &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;outerHeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;newHeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// didInsertElement&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We’re careful to make sure that the jQuery event listener runs inside an &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.run.next&lt;/code&gt; in order to make sure it happens after Ember has propagated all property updates and settled it’s internal book-keeping on the Runloop.&lt;/p&gt;

&lt;p&gt;Lastly, we want to make sure we tear down the event listener when the element is destroyed, by using the &lt;code class=&quot;highlighter-rouge&quot;&gt;willDestroyElement&lt;/code&gt; hook:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;AutoExpandingTextAreaComponent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TextArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;didInsertElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;next&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;focus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;keypress&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;newHeight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;scrollHeight&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;parseFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;borderTopWidth&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;parseFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;css&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;borderBottomWidth&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

          &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textArea&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;outerHeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;newHeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

  &lt;span class=&quot;na&quot;&gt;willDestroyElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;off&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;keypress&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here’s a working example:&lt;/p&gt;

&lt;p&gt;&lt;a class=&quot;jsbin-embed&quot; href=&quot;http://emberjs.jsbin.com/saxoqokaniha/1/embed?js,output&quot;&gt;Ember Starter Kit&lt;/a&gt;&lt;script src=&quot;http://static.jsbin.com/js/embed.js&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;Ember makes it pretty easy to extend the primitives it ships with, using the built in lifecycle hooks. In this example we took the stock &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.TextArea&lt;/code&gt; view and extended it as a new component that has new behaviour on its appearance.&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /><category term="Uncategorized" /></entry><entry><title type="html">How Ember.js Finds Stuff</title><link href="https://jmd.fm/how-ember.js-finds-stuff/" rel="alternate" type="text/html" title="How Ember.js Finds Stuff" /><published>2014-10-02T00:00:00-07:00</published><updated>2014-10-02T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2014-10-02-how-ember-js-finds-stuff.md</id><content type="html" xml:base="https://jmd.fm/how-ember.js-finds-stuff/">&lt;p&gt;There are several small satellite Islands that surround the main Island that I live on, and believe it or not seem to be fairly reasonably populated. The one depicted in the photo above reputedly has a retired Doctor living on it, who owns a small cannon which he fires off while dressed in full sea-captain regalia. I’ve definitely heard the cannon, but never seen the Doctor with my own eyes…yet. I am curious as to how these folks receive their mail, though. What would their address be? Well, this led me to think about how Ember finds the things it needs.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;Following on from my previous article about &lt;a href=&quot;http://ember.zone/beginning-to-understand-the-ember-js-container/&quot;&gt;Beginning to understand the Ember.js Container&lt;/a&gt;, I used a metaphor of a ‘concierge’ that was able to look things up when needed. Today I’m going to look at that Concierge and see how it is that they do their job.&lt;/p&gt;

&lt;h2 id=&quot;the-return-of-the-concierge-metaphor&quot;&gt;The Return of the Concierge (metaphor)&lt;/h2&gt;

&lt;p&gt;In Ember, the Concierge is the person responsible for taking the requested name that we want to look up, in this case let’s say ‘controller:index’, and translating that an actual object that we can use. In Ember land, this person is called the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; and its only purpose is to provide that necessary lookup and translation service of string based names to real things.&lt;/p&gt;

&lt;p&gt;It’s worth noting that there are actually two completely different Resolvers kicking around at the moment: one that ships with stock Ember, the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt;, and the other is Stefan Penner’s &lt;a href=&quot;https://github.com/stefanpenner/ember-resolver&quot;&gt;ember-resolver&lt;/a&gt; project which is the foundation of how Ember-CLI performs its module based magic. We’re only going to look at Ember’s stock Resolver today.&lt;/p&gt;

&lt;p&gt;Previously we saw that we could register an object to be found at a particular ‘address’ using the following syntax inside an &lt;a href=&quot;http://ember.zone/ember-application-initializers/&quot;&gt;Initializer&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;App.register(&apos;services:session&apos;, App.Session);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This creates a link between the string ‘services:session’ and our &lt;code class=&quot;highlighter-rouge&quot;&gt;App.Session&lt;/code&gt; object. When we or Ember needs to perform a lookup on the &lt;code class=&quot;highlighter-rouge&quot;&gt;Container&lt;/code&gt; for an object, the &lt;code class=&quot;highlighter-rouge&quot;&gt;Container&lt;/code&gt; is internally going to use the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; to do the reverse lookup of the &lt;code class=&quot;highlighter-rouge&quot;&gt;string&lt;/code&gt; name we supply to get the actual object.&lt;/p&gt;

&lt;h2 id=&quot;finding-things-not-in-the-container&quot;&gt;Finding things not in the Container&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;Container&lt;/code&gt; isn’t used to store everything in Ember. Templates, for example, live in the &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.TEMPLATES&lt;/code&gt; variable, which isn’t stored inside the &lt;code class=&quot;highlighter-rouge&quot;&gt;Container&lt;/code&gt;. This is where the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; steps in again to help locate what Ember needs.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; has several methods for looking up &lt;code class=&quot;highlighter-rouge&quot;&gt;Routes&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Models&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Helpers&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Templates&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;Controllers&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;Views&lt;/code&gt;, and all of them can be overridden. It is through the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; that the &lt;code class=&quot;highlighter-rouge&quot;&gt;Container&lt;/code&gt; is able to provide a unified lookup service to the rest of the system.&lt;/p&gt;

&lt;p&gt;Let’s say you wanted to have all of your Modal dialog templates located under a &lt;code class=&quot;highlighter-rouge&quot;&gt;/modals&lt;/code&gt; subdirectory of &lt;code class=&quot;highlighter-rouge&quot;&gt;/templates&lt;/code&gt;. If you try to do that without overriding the &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt;‘s basic implementation of how Templates are looked up in &lt;code class=&quot;highlighter-rouge&quot;&gt;Ember.TEMPLATES&lt;/code&gt;, Ember won’t be able to find the modal templates. Here’s how you could provide your own implementation that looks to see if a requested template ends in the word ‘modal’, and if it does, add the &lt;code class=&quot;highlighter-rouge&quot;&gt;/modals&lt;/code&gt; prefix to the lookup path:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;Resolver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;DefaultResolver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;extend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;na&quot;&gt;resolveTemplate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parsedName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;modalSuffix&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;modal&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;templateName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;parsedName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;// If the template ends in &apos;modal&apos; then we alter the lookup path.&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;templateName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;modalSuffix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;templateName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;modalSuffix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Ember&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;TEMPLATES&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;modals/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;templateName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;// Call the default implementation for all the other templates.&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_super&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parsedName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the above example, we’ve replaced the stock Resolver that ships with Ember without our own, which extends the basic &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; and overrides the &lt;code class=&quot;highlighter-rouge&quot;&gt;resolveTemplate&lt;/code&gt; hook to implement the Modal template lookup functionality we need. Maybe you’d also like to override how a Modal’s &lt;code class=&quot;highlighter-rouge&quot;&gt;Controller&lt;/code&gt;s are also looked up to match the same folder convention. It’s possible using this technique.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;highlighter-rouge&quot;&gt;DefaultResolver&lt;/code&gt; does a good job and is a main workhorse in Ember. Knowing what it does and how to tweak it as necessary can be very useful for establishing some of your own conventions, but use it with care.&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /><category term="Ember Infrastructure" /></entry><entry><title type="html">Ember Works Best When You Tell Instead Of Ask</title><link href="https://jmd.fm/ember-works-best-when-you-tell-instead-of-ask/" rel="alternate" type="text/html" title="Ember Works Best When You Tell Instead Of Ask" /><published>2014-09-25T00:00:00-07:00</published><updated>2014-09-25T00:00:00-07:00</updated><id>repo://posts.collection/_posts/2014-09-25-ember-works-best-when-you-tell-instead-of-ask.md</id><content type="html" xml:base="https://jmd.fm/ember-works-best-when-you-tell-instead-of-ask/">&lt;p&gt;Welcome to another note from the Ember Zone. This week on the Island we’ve had a couple of days of really torrential rain, and sunsets like the one above. On one hand this is good because it replenishes the reservoir that we all get our drinking water from. On the other hand it shakes and knocks down all of the leaves from the trees that were ready to fall, which admittedly does create a pretty colourful carpet everywhere. The wind, to the rain, to the leaves, to my driveway. Nature’s binding system at work.&lt;/p&gt;

&lt;p&gt;This started me thinking about how Ember really excels when you take advantage of the fact that the optimal state of things when using Ember is to Tell, don’t Ask.&lt;/p&gt;

&lt;!--more--&gt;

&lt;p&gt;‘Tell don’t Ask’ is a common software heuristic. The distinction is that procedural code ask lots of questions about what it should do next, whereas Object Oriented code relies on telling other objects what to do at the right time. It’s a subtle, but powerful inversion of obvious thinking.&lt;/p&gt;

&lt;p&gt;One of the most powerful aspects of Ember is that it has this concept baked in from the ground up in the form of the Bindings system.&lt;/p&gt;

&lt;p&gt;From &lt;a href=&quot;http://emberjs.com/guides/object-model/bindings/&quot;&gt;the guides&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A binding creates a link between two properties such that when one changes, the other one is updated to the new value automatically.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By virtue of creating a Binding, we are allowing the bound object to automatically tell interested parties when something has changed, they don’t have to ask by repeatedly polling, or relying on a custom event system.&lt;/p&gt;

&lt;p&gt;Any time you are reaching into another object to query the state of some property, you should re-write it as a Binding and take advantage of ‘Tell, don’t ask’. For example, instead of:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;// Assuming the controller has `someController` in its `needs`.
this.get(&apos;controllers.someController.someProperty&apos;);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Create a Computed Property using the &lt;code class=&quot;highlighter-rouge&quot;&gt;alias&lt;/code&gt; macro on the object that needs to know the information like so:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;someProperty: Ember.computed.alias(&apos;controllers.someController.someProperty&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first example involves ‘asking’, and you might think that the second example also involves asking, because you’re setting the binding in the object that needs to know what’s going on. Turn that thinking around! When &lt;code class=&quot;highlighter-rouge&quot;&gt;someController.someProperty&lt;/code&gt; changes, our own &lt;code class=&quot;highlighter-rouge&quot;&gt;someProperty&lt;/code&gt; will change in kind. It’s implicitly told what to do via the Bindings system.&lt;/p&gt;

&lt;p&gt;We can now create a new property based on our own bound property to further enhance the local state:&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;criticalCondition: function() {
  return this.get(&apos;someProperty&apos;) &amp;gt; 80;
}.property(&apos;someProperty&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Update: This was an Observer before, but @locks pointed out it should be a Property because it doesn’t contain any behaviour, and rightly so. Thanks!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once again, &lt;code class=&quot;highlighter-rouge&quot;&gt;criticalCondition&lt;/code&gt; will automatically update when the bound property all the way over in &lt;code class=&quot;highlighter-rouge&quot;&gt;controllers.someController.someProperty&lt;/code&gt; changes, and we won’t have to do a damn thing.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;p&gt;Ember’s Bindings and Computed Properties system is probably the most powerful thing in the entire framework. It allows for the same experience you might get when editing a spreadsheet – change the value in cell A2, and a bunch of other cells update – in your daily programming.&lt;/p&gt;

&lt;p&gt;In short, whenever you feel yourself writing a long property path chain in a &lt;code class=&quot;highlighter-rouge&quot;&gt;get&lt;/code&gt;, flip it around to use the Bindings system with something like a Computed proeprty.&lt;/p&gt;</content><author><name></name></author><category term="The Workshop" /><category term="Uncategorized" /></entry></feed>