<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Manuel Heidrich on Medium]]></title>
        <description><![CDATA[Stories by Manuel Heidrich on Medium]]></description>
        <link>https://medium.com/@mahnuh?source=rss-ab3bd85da684------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1x3InnSijnz1JXEpgjvGQg.png</url>
            <title>Stories by Manuel Heidrich on Medium</title>
            <link>https://medium.com/@mahnuh?source=rss-ab3bd85da684------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 15:41:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahnuh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[A hassle-free, zero dependency way to handle console.log()]]></title>
            <link>https://medium.com/@mahnuh/a-hassle-free-zero-dependency-way-to-handle-console-log-d63a37b7a129?source=rss-ab3bd85da684------2</link>
            <guid isPermaLink="false">https://medium.com/p/d63a37b7a129</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Tue, 17 Mar 2020 11:28:26 GMT</pubDate>
            <atom:updated>2020-03-17T11:28:26.470Z</atom:updated>
            <content:encoded><![CDATA[<h3>A hassle-free, zero dependency way to handle console.log() &amp; co. in a production Angular application</h3><p>console.log() and its siblings likely are the most used methods any JavaScript developer has ever used. And that&#39;s totally fine, because console.log() most definitely is a huge help if not even a life saver when debugging an application.</p><p>And there is the challenge right there: as helpful as output in the browser’s console is when debugging, it is absolutely not a good idea to leave this output when deploying your application to production. At least any output below the error level.</p><p>So one solution could be to not leave any console methods in the code (except maybe console.error()). Fortunately linters like <a href="https://palantir.github.io/tslint/rules/no-console/">tslint</a> or <a href="https://eslint.org/docs/rules/no-console">eslint</a> have built-in rules to help you with that. But let&#39;s be honest, we developers usually are lazy af. Also often there are situations where we want to have console output permanently when developing. So it would be a huge hassle to add, remove, re-add (and so on) the console methods.</p><p>I wrote about a <a href="https://manuel-heidrich.dev/blog/building-a-simple-logger-service-for-ionic-3">custom logger service</a> a couple of years ago, which is environment agnostic, but I’m no longer using it. The main reason is that you are not able to see the file and line the output was generated. Plus I do not always want to import and inject a service first. Using console.log() is just so much more convenient.</p><h3>My solution</h3><p>For my current side project <a href="https://monitornator.io/">Monitornator</a> I added a method called handleConsole() to my AppComponent that looks like this:</p><pre><em>private</em> handleConsole(): <em>void</em> {<br>  <em>let</em> methods: string[] = [];<br><br>  <em>switch</em> (environment.name) {<br>    <em>case</em> ‘production’:<br>    <em>case</em> ‘staging’:<br>      methods = [‘log’, ‘debug’, ‘info’, ‘warn’];<br>      <em>break</em>;<br><br>    <em>default</em>:<br>      <em>break</em>;<br>  }<br><br>  <em>if</em> (methods.length) {<br>    console.warn(`🚨 Console output is disabled on ${environment.name}!`);<br>  }<br><br>  methods.forEach((method) =&gt; {<br>    console[method] = <em>function</em>(): <em>void</em> { };<br>  });<br>}</pre><p>What it does is basically overriding any console method with an empty function, depending on the current environment. So leaving console.log() in the code in this case will just print nothing while on staging or production. Using switch case allows me to quickly add different log levels for different environments. And before overriding the methods I print a warning to the console, because... let&#39;s say SOMEONE more then once spent a huge amount of time wondering why console.log() suddenly stopped working while on staging 🤦🏼‍♂️.</p><h3>Conclusion</h3><p>Of course there is a fair amount of logging libraries out there, some better than others, but I personally don’t want to add another dependency for something I can solve with just a couple lines of code. The above solution works pretty fine for me.</p><p><em>Originally published at </em><a href="https://manuel-heidrich.dev/blog/a-hassle-free-way-to-handle-console-log-in-a-production-angular-application"><em>https://manuel-heidrich.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d63a37b7a129" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ionic 3: Better Dialogs with async/await]]></title>
            <link>https://medium.com/prototype-berlin/ionic-3-better-dialogs-with-async-await-c67fb5423c5f?source=rss-ab3bd85da684------2</link>
            <guid isPermaLink="false">https://medium.com/p/c67fb5423c5f</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Tue, 04 Sep 2018 08:01:01 GMT</pubDate>
            <atom:updated>2018-09-04T08:01:01.673Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AiCGVT8YAT5LDCd1h13MGQ.jpeg" /></figure><p>When building a mobile app with Ionic there is a good chance you will want to display confirm dialogs to your users to ask them if they really want to do something, for example before logging them out of your application.</p><p>Fortunately Ionic comes with an <a href="https://ionicframework.com/docs/api/components/alert/AlertController/">AlertController</a> that can handle dialogs like alerts, confirms and prompts. Unfortunately, though, the example usage explained in the Ionic docs is kind of clumsy and hard to read. That’s why I decided to develop a better approach. In this post I am going to explain why and how I did that. (tl;dr, just take me to <a href="#38e8">the solution</a>!)</p><p>So let’s look at an example based on the Ionic docs where you ask for confirmation before logging out the user:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56bc8fecf52943c6ab30e5c3682055f2/href">https://medium.com/media/56bc8fecf52943c6ab30e5c3682055f2/href</a></iframe><p>So this works fine of course, but I think it is not the most beautiful solution.</p><p>Why, you ask?</p><p>You would have to read through lots of lines of code to see what is actually happening when the user confirms the logout. I usually like to split up huge methods into smaller ones, also keeping the <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> principle in mind.</p><p>So what I usually did was splitting up the code into two methods, one responsible for displaying the dialog and one responsible for the actual logout process:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72ccb486ff1ea4c1bbe38824a12497df/href">https://medium.com/media/72ccb486ff1ea4c1bbe38824a12497df/href</a></iframe><p>That seems better, but the there are still a lot of lines to read until you reach the actual logout method. I also did not like this solution very much because of semantics. The method called logout() does not do the actual logging out and I think a button labeled “Logout” should call a method with a similar name and not something like showLogoutConfirmation().</p><p>So now what?</p><h4>async/await</h4><p>As the post title might reveal my preferred solution is async/await. I had this idea while browsing through the documentation of the upcoming Ionic 4 release where the AlertController will be promisified by default. So why not use this strategy in Ionic 3?</p><p>That’s what I came up with and what I really like using right now for dialogs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9141569c16b696910fdf9500984ea10e/href">https://medium.com/media/9141569c16b696910fdf9500984ea10e/href</a></iframe><p>We have a method called logout() and one called confirmLogout(). The code is easy to read and each method does exactly what you would expect from their names.</p><p>I hope you like this solution and if you have any ideas or questions, please feel free to comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c67fb5423c5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/ionic-3-better-dialogs-with-async-await-c67fb5423c5f">Ionic 3: Better Dialogs with async/await</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pagination in LoopBack 3]]></title>
            <link>https://medium.com/prototype-berlin/pagination-in-loopback-3-1cb5e7e7bc20?source=rss-ab3bd85da684------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb5e7e7bc20</guid>
            <category><![CDATA[pagination]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[loopback]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Mon, 20 Aug 2018 07:05:28 GMT</pubDate>
            <atom:updated>2018-08-20T07:05:28.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zkISXWVieJdfk9DssHJb8w.jpeg" /></figure><p>When developing an application with a LoopBack backend it usually won’t take long until you will need some kind of pagination in your frontend to make long lists of countless items more user-friendly to navigate.</p><p>Thankfully LoopBack has a <a href="https://loopback.io/doc/en/lb3/Skip-filter.html">skip filter</a> and a <a href="https://loopback.io/doc/en/lb3/Limit-filter.html">limit filter</a> which allows us to implement pagination with just using some url parameters. Your first request to fetch the list would contain</p><pre>?filter={“skip”:0,”limit”:10}</pre><p>the next request</p><pre>?filter={“skip”:10,”limit”:10}</pre><p>and so on. This is quite useful!</p><p>However whether you are building a classic pagination with pages, a load more button or even some kind of infinite scrolling you might want to know exactly how many pages there are or how many items there are left to fetch. In this post I will discuss two options to solve this issue: the X-Total-Count header and the <a href="https://www.npmjs.com/package/loopback-paginator">loopback-paginator</a> mixin.</p><p><strong>The X-Total-Count header</strong></p><p>As the headline might suggest one solution would be to add a header to your response that tells you, how much items there are in total. This can easily be done with the following boot script you just have to place into the server/boot directory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2cda4fbec472f1f9f9d3d330da45bde/href">https://medium.com/media/c2cda4fbec472f1f9f9d3d330da45bde/href</a></iframe><p>This will automatically intercept all calls for item lists (find) and add the X-Total-Count header to the response. This also takes filters into account. So if you applied a where filter to your request only items that fit your filter will be counted.</p><p>In your frontend you can use that total count to calculate the number of available pages for example or hide the load more button if no more items are available.</p><p><strong>The loopback-paginator</strong></p><p>The second option is to use the <a href="https://www.npmjs.com/package/loopback-paginator">loopback-paginator</a> mixin. (Full disclosure: I’m the author of this mixin which I wrote to have an in my opinion more elegant solution to the pagination problem.) After installing and applying the mixin to your models (check the <a href="https://github.com/prototype-berlin/loopback-paginator#readme">readme</a> to see all available options), the response body of your GET /api/items requests will look slightly different:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e766e2dbb085acfb77db0234ad1e660c/href">https://medium.com/media/e766e2dbb085acfb77db0234ad1e660c/href</a></iframe><p>Instead of an array with all your items the body will contain <strong>data</strong> and <strong>meta</strong>. Data contains the array of items as you are used to and meta contains some helpful information to implement pagination. You will see the total number of items, the total number of available pages, the number of items per page as well as the current, previous and next page (if available). This solution also takes all your applied filters into account.</p><p>I just started working on the paginator last week, but I have some more features in mind and updates will come soon.</p><p>So which solution you want to use is totally up to you. They will both optimise the user experience of your application.</p><p>Have any questions? Want to let me know what you think? Just post a comment below!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb5e7e7bc20" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/pagination-in-loopback-3-1cb5e7e7bc20">Pagination in LoopBack 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Analytics in Ionic 3: Easily Track Page Views with a Custom Decorator]]></title>
            <link>https://medium.com/prototype-berlin/analytics-in-ionic-3-easily-track-page-views-with-a-custom-decorator-33aa96e5a499?source=rss-ab3bd85da684------2</link>
            <guid isPermaLink="false">https://medium.com/p/33aa96e5a499</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 13:49:02 GMT</pubDate>
            <atom:updated>2018-06-08T14:30:49.812Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7HE-Ybeq0-KIcJeIr2wAmQ.jpeg" /></figure><p>If you develop a production Ionic app chances are you also want to integrate some kind of analytics to analyse how your app is being used. There are a lot of different options available like Google Analytics, Firebase or Flurry Analytics, but all they have in common: you have to implement to implement the tracking of your individual views.</p><p>I am usually using <a href="https://ionicframework.com/docs/native/google-analytics/">@ionic-native/google-analytics</a> in my apps and since I did not really want to add this.googleAnalytics.trackView(‘SomePage’) manually to every page I tried different approaches to implement automatic view tracking. What I ended up using is a custom decorator I just need to add to any page I want to track.</p><h3>How does this decorator look like?</h3><p>Glad you asked. Like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/443c5bea4ed273c23482e3012a32467e/href">https://medium.com/media/443c5bea4ed273c23482e3012a32467e/href</a></iframe><p>To use it you have to modify your core module as well. If you don’t have a core module you can just do the same in your app.module.ts. (Don’t forget to change line 3 in page-track.decorator.ts in that case!)</p><p>Core module example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80a1a045c8e1e6a01c521e3588eb58dd/href">https://medium.com/media/80a1a045c8e1e6a01c521e3588eb58dd/href</a></iframe><p>And now you just have to import and add the PageTrack() decorator to your page component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b909d41a6f33246c01ef9decb655c45/href">https://medium.com/media/6b909d41a6f33246c01ef9decb655c45/href</a></iframe><p>That’s it!</p><h3><strong>So how does this work?</strong></h3><p>What the page track decorator basically does is publish a ‘view:enter’ event every time a view is being entered which also passes the page name (the name of the page component to be exact).<br>I am using the ionViewDidEnter life cycle event of Ionic to achieve that, but you could also use other events depending on when you want the event to be published.</p><p>So all I have to do is listen to the ‘view:enter’ event in an analytics service for example and do the actual view tracking there:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1e59cdaf46923aceafa22e4f39be86c/href">https://medium.com/media/a1e59cdaf46923aceafa22e4f39be86c/href</a></iframe><p>I think this is a pretty neat way to add page tracking to an Ionic app. What do you think?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33aa96e5a499" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/analytics-in-ionic-3-easily-track-page-views-with-a-custom-decorator-33aa96e5a499">Analytics in Ionic 3: Easily Track Page Views with a Custom Decorator</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Simple Logger Service for Ionic 3]]></title>
            <link>https://medium.com/prototype-berlin/building-a-simple-logger-service-for-ionic-3-540d924fe615?source=rss-ab3bd85da684------2</link>
            <guid isPermaLink="false">https://medium.com/p/540d924fe615</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[hybrid-app-development]]></category>
            <category><![CDATA[ionic-framework]]></category>
            <category><![CDATA[cordova]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Manuel Heidrich]]></dc:creator>
            <pubDate>Fri, 01 Jun 2018 00:00:00 GMT</pubDate>
            <atom:updated>2018-06-08T14:53:33.832Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ma3-ciO7SybtCGRMVHwA8A.jpeg" /></figure><p>An Ionic developer’s best friend often are console statements to do some quick debugging or maybe to log the order of Ionic’s lifecycle events. Console output is awesome but you would not want to make this available in a production application as it often displays information not meant so be seen by others than you or your development team. In fact it can pose a security risk.</p><p>It is usually a good idea to remove all console.log, console.warn, console.whatever statements before releasing a production version of your app. So I do not miss any I usually add a <a href="https://palantir.github.io/tslint/rules/no-console/">tslint rule</a> to my tsconfig.json to throw lint errors on all console statements. But who wants to manually remove all console statements before releasing and then adding them again when needed? Nobody I guess.<br>You could add some custom steps to your build process to automatically remove all console statements of course, but a more elegant way I think is a custom logger service.<br>This is why I built a custom logger service that outputs the different log levels depending on the current environment.</p><p>(Also check out this article about the environment switch we use at <a href="https://prototype.berlin/">prototype.berlin</a> to easily switch between different environments when serving or building our Ionic apps.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4bf3137f2859bf65820e4d750fe4e8c5/href">https://medium.com/media/4bf3137f2859bf65820e4d750fe4e8c5/href</a></iframe><p>The logger service at the moment supports four log levels: debug, info, warning and error. Of course it can be extended with some other common levels like trace or fatal, but those four are what I am usually using.<br>In lines 51 to 54 you can see the environment filter where only errors are allowed when on a production environment, otherwise all outputs are shown. This of course can be extended as well. For example you might have a staging environment where only warnings and errors should be visible.</p><p>After adding the service to the app.module.ts it can be used straight forward like the usual console statements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e63a5380c621387aecae281b988170f8/href">https://medium.com/media/e63a5380c621387aecae281b988170f8/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XVJ-84rY7kcy800QebE-wQ.png" /><figcaption>Console output of the example service above.</figcaption></figure><p>So if you use console statements a lot — and I do so — this simple logger service can make your life much easier. Just give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=540d924fe615" width="1" height="1" alt=""><hr><p><a href="https://medium.com/prototype-berlin/building-a-simple-logger-service-for-ionic-3-540d924fe615">Building a Simple Logger Service for Ionic 3</a> was originally published in <a href="https://medium.com/prototype-berlin">prototype.berlin</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>