<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Macsour - Medium]]></title>
        <description><![CDATA[The Macsour blog - Medium]]></description>
        <link>https://medium.com/macsour?source=rss----7d6b9562e8e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Macsour - Medium</title>
            <link>https://medium.com/macsour?source=rss----7d6b9562e8e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 03:09:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/macsour" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to handle async properties in Ember.js]]></title>
            <link>https://medium.com/macsour/how-to-handle-async-abilities-with-ember-can-22d90df056ed?source=rss----7d6b9562e8e---4</link>
            <guid isPermaLink="false">https://medium.com/p/22d90df056ed</guid>
            <category><![CDATA[promises]]></category>
            <category><![CDATA[emberjs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Maciej Kwaśniak]]></dc:creator>
            <pubDate>Wed, 12 Dec 2018 11:01:00 GMT</pubDate>
            <atom:updated>2018-12-12T11:03:34.074Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TUxdZrOZ62cxu__c" /><figcaption>Photo by <a href="https://unsplash.com/@mattlee?utm_source=medium&amp;utm_medium=referral">Matt Lee</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Many times I encounter a question about how to handle async properties in Ember. I saw a lot of solutions like overwriting property after promise will resolve or handling promise in a template using special helpers. But there is also another, much simpler way!</p><p>You can use <a href="https://www.emberjs.com/api/ember/release/classes/PromiseProxyMixin"><strong>PromiseProxyMixin</strong></a> + <a href="https://www.emberjs.com/api/ember/release/classes/ObjectProxy"><strong>ObjectProxy</strong></a> (or <a href="https://www.emberjs.com/api/ember/release/classes/ArrayProxy"><strong>ArrayProxy</strong></a> if needed).</p><p><strong>Example usage:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd75d004ca6c7f6c13ca3f96539b4f51/href">https://medium.com/media/cd75d004ca6c7f6c13ca3f96539b4f51/href</a></iframe><h4><strong>Explanation:</strong></h4><p>Instead of resolving a promise inside of our property:</p><pre>viewCount: computed(&#39;articleId&#39;, function() {<br>  return this.fetchArticleStats(this.articleId).then((stats) =&gt; {<br>    return stats.viewCount;<br>  });<br>}).readOnly(),</pre><p>We are creating ObjectPromiseProxy using <a href="https://www.emberjs.com/api/ember/release/classes/PromiseProxyMixin">PromiseProxyMixin</a> inside of our async property.</p><pre>articleStats: computed(&#39;articleId&#39;, function() {<br>  let promise = this.fetchArticleStats(this.articleId);<br>  return ObjectPromiseProxy.create({ promise });<br>}),</pre><p>And then just referring our property to that object:</p><pre>viewCount: reads(&#39;articleStats.viewCount&#39;).readOnly()</pre><blockquote>Hint:<br>The property will stay empty until the promise will not resolve</blockquote><p>Thanks to this trick, you can “observe” whatever async property you wish in your component, handle loading state or display them whenever it will be possible.</p><h3>Hire me as your next frontend engineer!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3gAQWSQPuEWzkjXSwd3EA.png" /><figcaption><strong><em>Check out my projects, experience, and ask me a question on </em></strong><a href="https://macsour.com/"><strong><em>macsour.com</em></strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22d90df056ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macsour/how-to-handle-async-abilities-with-ember-can-22d90df056ed">How to handle async properties in Ember.js</a> was originally published in <a href="https://medium.com/macsour">Macsour</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Components structure in Ember.js]]></title>
            <link>https://medium.com/macsour/components-structure-in-ember-js-91e925e2f0d3?source=rss----7d6b9562e8e---4</link>
            <guid isPermaLink="false">https://medium.com/p/91e925e2f0d3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[emberjs]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[ember]]></category>
            <dc:creator><![CDATA[Maciej Kwaśniak]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 10:56:44 GMT</pubDate>
            <atom:updated>2018-12-11T10:56:43.976Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ygM1LJYAGsnQFV74" /><figcaption>Photo by <a href="https://unsplash.com/@alexkixa?utm_source=medium&amp;utm_medium=referral">Alexandre Debiève</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote><strong>Before you start:</strong><br>Make sure you are already familiar with <a href="https://medium.com/macsour/components-patterns-in-ember-js-5e6fc6eea28f">components patterns</a></blockquote><p>Ember.js is a framework that uses a lot of patterns and is conventions oriented. Fortunately, it’s also flexible. A lot of things depend clearly on developers, what sometimes can bring unexpected consequences. Very often fixing those issues is not an easy thing, and can change our mind about Ember because of its limitations. The truth is, hacks are not going in pair with conventions.</p><p>One of the first places where developers make this kind of mistake are components. They start to build their projects by adding new blocks, very often even without thinking about architecture, how this will be reused in the future and how flexible it will be. Today, components are super crucial parts, and their structure should be thought well. Thanks to it, you will be able to easily use them, navigate, they will be more flexible, and isolated. Good patterns in this field will allow you to develop maintainable applications and keep up with rapidly changing business requirements.</p><p>Have you ever reached a moment where your app was so big that you had to split it? Thanks to using conventions in components structure this operation will be much easier to achieve.</p><blockquote><strong>Disclaimer:</strong><br>Those patterns may not work for the <a href="https://github.com/emberjs/rfcs/blob/master/text/0311-angle-bracket-invocation.md">angle brackets components</a> and after <a href="https://github.com/emberjs/rfcs/blob/master/text/0143-module-unification.md">Module Unification</a> implementation</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IK0Yd1qgJEDDES03" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">chuttersnap</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Naming</h3><p>This is a pretty important thing in components structure. It allows you to determine a purpose of a component so you will know if it’s used in a way it is meant to be.</p><p>We can determine 3 types of components:</p><h4><strong>1. Public</strong></h4><p>Public components are named as a normal component and can be accessed anywhere.</p><p><strong>Example:</strong></p><pre>app<br>└── components<br>    └── user-profile</pre><p><strong>Usage:</strong> {{<strong>user-profile</strong>}}</p><h4><strong>2. Internal</strong> (Private)</h4><p>Internal (private) components have a prefix char - (dash), so you can see that this component was not meant to be used outside of its scope or you should be careful with using it. It’s very useful if you have a big complicated component and don’t want to expose underneath layer.</p><p><strong>Example:</strong></p><pre>app<br>└── components<br>    └── user-profile<br>        └── -avatar</pre><p><em>Ideally, you should only use internal components in the scope of its parent, so in case of a big components tree, you can easily tell which of them you </em>can or can’t call directly<em>.</em></p><p><strong>Usage:</strong> {{<strong>user-profile/-avatar</strong>}}</p><h4><strong>3. Abstract</strong></h4><p>These components can be used mostly for extending other components (used as a base). So, you can create a component file but this component cannot be called in a template. Perfect as an abstract layer.</p><p><strong>Example:</strong></p><pre>app<br>└── components<br>    └── user-profile<br>        └── fields<br>            └── _base</pre><p>The usage will look like: {{<strong>user-profile/fields/_base</strong>}} however, this <strong>will be omitted and not be rendered</strong> anyway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6Xk-KcVycxqeFulv" /><figcaption>Photo by <a href="https://unsplash.com/@iliched?utm_source=medium&amp;utm_medium=referral">Ilya Orehov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>The Structure</h3><p>Okay, so you already know what kind of name you should use. Now, you need to get to know how to structure it. I propose to use those 3 levels:</p><pre>NAMESPACE<br>└── PURPOSE<br>    └── MY-COMPONENT</pre><h4>1. Namespace</h4><p>It can be a business logic part (eg. dashboard) custom namespace (eg. shared) or resource name (eg tasks). First, you will probably build components for resources and maybe use shared namespace for non-related things. After that, you will shape bussines logic namespaces like the dashboard and settings.</p><h4>2. Purpose</h4><ul><li><strong>parts </strong><br>All components that will serve you as parts to build UI elements. They shouldn&#39;t contain any layout markup, should work with custom data and be flexible enough to modify them easily. Mostly those are <a href="https://medium.com/macsour/components-patterns-in-ember-js-5e6fc6eea28f">composable or container components</a>.</li><li><strong>ui <br></strong>Components that are a wrapper for parts and build a layout of the application. Ready to use in routes templates, almost out-of-the-box. They contain proper styling and maintain data. You can call it a public interface of your components.</li></ul><h4>3. Component</h4><p>And finally, here you can create your components and choose a correct name and <a href="https://medium.com/macsour/components-patterns-in-ember-js-5e6fc6eea28f">pattern</a> for them.</p><h3>Example</h3><pre>app<br>└── components<br>    ├── tasks<br>    │   ├── parts<br>    │   │   └── tasks-list<br>    │   │       └── -item<br>    │   └── ui<br>    │       └── todo-list<br>    └── shared<br>        └── parts<br>            └── form-builder<br>                └── -fields<br>                    ├── _base<br>                    ├── input<br>                    └── textarea</pre><p>Looks cool, right? But wait! There is a disadvantage. Your components name will get longer, right?</p><p>From tasks-list/item now we got tasks/parts/tasks-list/-item . Well, yes. But look how much information you have.</p><ol><li>You know that this is an internal component (not meant to be used outside of tasks-list.</li><li>Its parent is composable, not containing layout (as it’s in parts )</li><li>The whole thing is related strictly to tasks namespace.</li></ol><p>What’s more, if you use components patterns correctly you will use full names rarely as you will call most of them through the block of the contextual component.</p><p>Thanks to the correct naming and structure it will be much easier for you to build, maintain and refactor this important segment of each app.</p><h3>Hire me as your next frontend engineer!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3gAQWSQPuEWzkjXSwd3EA.png" /><figcaption><strong><em>Check out my projects, experience, and ask me a question on </em></strong><a href="https://macsour.com/"><strong><em>macsour.com</em></strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91e925e2f0d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macsour/components-structure-in-ember-js-91e925e2f0d3">Components structure in Ember.js</a> was originally published in <a href="https://medium.com/macsour">Macsour</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Components patterns in Ember.js]]></title>
            <link>https://medium.com/macsour/components-patterns-in-ember-js-5e6fc6eea28f?source=rss----7d6b9562e8e---4</link>
            <guid isPermaLink="false">https://medium.com/p/5e6fc6eea28f</guid>
            <category><![CDATA[emberjs]]></category>
            <category><![CDATA[ember]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[components]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Maciej Kwaśniak]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 11:13:47 GMT</pubDate>
            <atom:updated>2018-12-10T11:13:47.732Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<p>As an Ember developer, you are probably familiar with components. Thanks to them you can split your code into meaningful parts. Unfortunately, it’s not always obvious how they should look like, and which pattern should you use. This snippet should let you better understand what kind of components patterns you can use to be the best match for your case.</p><p>Here are all the components patterns I found in the Ember community, that I think is good to know.</p><h3>Components patterns</h3><h4>Presentational component</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HjNofHnC59Unqkbw" /><figcaption>Photo by <a href="https://unsplash.com/@mrthetrain?utm_source=medium&amp;utm_medium=referral">Joshua Hoehne</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This is the basic type of component. It used for presenting, formatting data. It takes some properties and displays them in a more meaningful way. It shouldn’t be responsible for data fetching or business logic. One good example can be a component for displaying a user’s avatar.</p><p><strong>Example definition:</strong></p><pre>// user-avatar/template.hbs<br>&lt;img src={{user.avatarUrl}}&gt;</pre><p><strong>Call API example:</strong></p><pre>{{user-avatar user=user}}</pre><p><strong>References:</strong><br><a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0</a><br><a href="https://medium.com/@learnreact/container-components-c0e67432e005">https://medium.com/@learnreact/container-components-c0e67432e005</a></p><h4>Contextual component</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W58Cdf0JrznBmric" /><figcaption>Photo by <a href="https://unsplash.com/@jammypodger7470?utm_source=medium&amp;utm_medium=referral">michael podger</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>These components can be used as a wrapper eg. for markup. They can act like any other component type. The only difference is that they can pass content inside of the block to a specific place in the component using the <strong>{{yield}}</strong> statement.</p><p><strong>Example definition:</strong></p><pre>// page-header/template.hbs<br>&lt;div class=&quot;jumbotron&quot;&gt;<br>  &lt;h1&gt;Hello, world!&lt;/h1&gt;<br>  &lt;p&gt;<strong>{{yield}}</strong>&lt;/p&gt;<br>&lt;/div&gt;</pre><p><strong>Call API example:</strong></p><pre>{{#page-header}}<br>  <strong>How are you?</strong><br>{{/page-header}}</pre><p><strong>References:</strong><br><a href="https://guides.emberjs.com/release/components/wrapping-content-in-a-component/">https://guides.emberjs.com/release/components/wrapping-content-in-a-component/</a></p><h4>Container component</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cFNuNLNq1dVUIC6S" /><figcaption>Photo by <a href="https://unsplash.com/@guibolduc?utm_source=medium&amp;utm_medium=referral">Guillaume Bolduc</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This pattern is used for data manipulation, actions handling and all the business logic around. For example, it can fetch the user and format the content using <strong>presentational components</strong>. Container component can also act as the <strong>contextual component</strong>, allowing you to overwrite the content and markup by passing a block.</p><p><strong>Example definition:</strong></p><pre>// user-profile/component.js<br>import Component from &#39;<a href="http://twitter.com/ember/component">@ember/component</a>&#39;;<br>import { inject as service } from &#39;<a href="http://twitter.com/ember/service">@ember/service</a>&#39;;<br>import { computed } from &#39;<a href="http://twitter.com/ember/object">@ember/object</a>&#39;;</pre><pre>export default Component.extend({<br>  store: service(),</pre><pre>  id: null,<br>  <br>  user: computed(&#39;id&#39;, function() {<br>    return id ? this.store.findRecord(&#39;user&#39;, this.id) : null;<br>  }),<br>});</pre><pre>// user-profile/template.hbs<br>{{#if hasBlock}}<br>  {{yield user}}<br>{{else}}<br>  {{user.name}}<br>  {{user-avatar user=user}}<br>{{/if}}</pre><p><strong>Call API example:</strong></p><pre>{{#user-profile id=7 as |user|}}<br><strong>  &lt;h1&gt;{{user.name}}&lt;/h1&gt;</strong><br>{{/user-profile}}</pre><p><strong>References:</strong><br><a href="https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0">https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0</a><br><a href="https://medium.com/@learnreact/container-components-c0e67432e005">https://medium.com/@learnreact/container-components-c0e67432e005</a></p><h4>Composable component (aka Higher-Order Component)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XDRDV_Z1YtMqdR0l" /><figcaption>Photo by <a href="https://unsplash.com/@egnaro?utm_source=medium&amp;utm_medium=referral">Rick Mason</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Its role is to deliver to you meaningful components/parts from which you can build your business logic and features but also serves as a great extension for container components. They should still stay flexible so you can add your own markup or modify behaviors. This kind of components can be used in a top-level template where you define your application layout but can be also used to form another component.</p><p><strong>Example definition:</strong></p><pre>// articles-list/template.hbs<br>{{yield (hash<br>  variables=(hash<br>    articles=articles<br>  )</pre><pre>  components=(hash<br>    list=(component &quot;articles-list/list&quot; articles=articles)<br>    pagination=(component &quot;articles-list/pagination&quot;)<br>  )<br>)}}</pre><p><strong>Call API example:</strong></p><pre>{{#<strong>articles-list</strong> articles=user.articles as |<strong>articlesList</strong>|}}<br>  {{#<strong>articlesList.components.list</strong> as |<strong>list</strong>|}}<br>    {{#<strong>list.components.item</strong> as |article|}}<br>      &lt;h1&gt;{{article.title}}&lt;/h1&gt;<br>      &lt;p class=&quot;lead&quot;&gt;{{article.body}}&lt;/p&gt;<br>    {{/<strong>list.components.item</strong>}}<br>  {{/<strong>articlesList.components.list</strong>}}</pre><pre>{{<strong>articlesList.components.pagination</strong>}}<br>{{/<strong>articles-list</strong>}</pre><p><strong>References:<br></strong><a href="https://www.chriskrycho.com/2018/higher-order-components-in-emberjs.html">https://www.chriskrycho.com/2018/higher-order-components-in-emberjs.html</a><br><a href="https://riptutorial.com/ember-js/example/10416/composable-components">https://riptutorial.com/ember-js/example/10416/composable-components</a><br><a href="https://www.youtube.com/watch?v=6N4qsO22fmw">https://www.youtube.com/watch?v=6N4qsO22fmw</a></p><p>More about composable components soon in next articles :)</p><p>Of course, this is just an outline of these patterns but the point is to give an overview of which components pattern we can use during the development process of our application.</p><p><strong>Any questions?</strong><br>Twitter: <a href="http://twitter.com/themacsour">theMacsour</a></p><h3>Hire me as your next frontend engineer!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t3gAQWSQPuEWzkjXSwd3EA.png" /><figcaption><strong><em>Check out my projects, experience, and ask me a question on </em></strong><a href="https://macsour.com/"><strong><em>macsour.com</em></strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e6fc6eea28f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/macsour/components-patterns-in-ember-js-5e6fc6eea28f">Components patterns in Ember.js</a> was originally published in <a href="https://medium.com/macsour">Macsour</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>