<?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 Wes on Medium]]></title>
        <description><![CDATA[Stories by Wes on Medium]]></description>
        <link>https://medium.com/@weswhite?source=rss-97cf7cdb9cec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cWiIqgZgH4emtLZ83736Ng.jpeg</url>
            <title>Stories by Wes on Medium</title>
            <link>https://medium.com/@weswhite?source=rss-97cf7cdb9cec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:55:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@weswhite/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[Angular Modules and Lazy Loading]]></title>
            <link>https://medium.com/@weswhite/angular-modules-1242eeb7153c?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/1242eeb7153c</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[modules]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Mon, 22 Jan 2018 16:20:35 GMT</pubDate>
            <atom:updated>2018-01-22T16:28:20.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r4hZDWTkf9D3fsactX7S4A.png" /><figcaption>Photo by <a href="https://unsplash.com/photos/1KTyI0POWhc?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Jakub Kriz</a> on <a href="https://unsplash.com/search/photos/landscape?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>This is the most basic Angular Module:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6ec9420ef8771eab7637b5306707cb9/href">https://medium.com/media/a6ec9420ef8771eab7637b5306707cb9/href</a></iframe><p>@NgModule decorator defines the module. The metadata defined does all the work. Any components imported and defined in the meta down now live in the module. Here you can see how components are imported and then defined in declarations . Other modules are defined in imports . Services used to be injected into components are defined in providers .</p><p>The last two properties on the ngModule object are for entry-components (entryComponents and boostrap). Entry-components are components that are loaded by the Angular’s render engine even though they are not referenced by templates in components. The boostrap component is simple the main component in the application for that module. Entry components are components that are not referenced in other component templates but in are referenced functionally. The most common example is a component like a model that has a show or open function to display the component.</p><p>All of the core Angular code is broken up in to modules just like this. Modules are the center of Angular. Modules drive Angular’s dependency injection engine. Depending on where services is imported into which module, services will be a singleton or not (quick tip on singleton service: if the whole app needs a service, import the service in the main App module).</p><p>Every app will have an App level module. This is the main module. But the Angular docs recommend breaking out components in cohesive sections of the app into their own module. This is called a feature module by the <a href="https://angular.io/guide/feature-modules">Angular docs</a>. Feature modules get imported into the App module and referenced in the imports array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbd44821afdb5f86dfa3212a2fcc3ea4/href">https://medium.com/media/dbd44821afdb5f86dfa3212a2fcc3ea4/href</a></iframe><p>Here is <a href="https://medium.com/@weswhite/angular-singleton-service-and-a-loading-indicator-ca3cc7892722">my post on singleton services</a>. Service life cycle is controlled by the module. When a module is active through the router, the module’s injector is created with all the associated services. Since modules form a tree structure with the App module at the top, services in the top are available all the way down. The App module injector is never destroyed and all the services will be the same instance. This is affected as you move down the tree into feature modules. <a href="https://angular.io/guide/singleton-services">Go read the docs for more detail</a>.</p><p>Outside of a feature module or App module, it is common to see a shared module. This is a module style where you could wrap all your common components that are reused throughout your app. Its like your own component library. This is really just a tool to organize your code.</p><p>One of the most import features of modules is the ability to lazy load feature modules. This means that you do not have to bring down all your app code at once. You can bring down the bare bones and based on the active route bring down what you will need next. This a basic strategy to improve app performance and decrease and distribute network load. To do this, an app-routing.module.ts file and a routing file for each feature module is needed. For more info, <a href="https://angular.io/guide/lazy-loading-ngmodules">instructions for using Angular CLI to setup lazy loading</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf492780fc2ab51890d44bfba158d0b/href">https://medium.com/media/cbf492780fc2ab51890d44bfba158d0b/href</a></iframe><p>Add the route module to the feature module imports (line 9 below).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ee2f4ba5b626f93fc4f10104d5cf94cb/href">https://medium.com/media/ee2f4ba5b626f93fc4f10104d5cf94cb/href</a></iframe><p>Add the feature route module file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0e0c0800b55e55cb24387159c43d8d0/href">https://medium.com/media/f0e0c0800b55e55cb24387159c43d8d0/href</a></iframe><p>Now, lazy loading is setup. When your route to the new module a new chunk will show up in the Network tab.</p><p>That wraps up a lot of what you can do with NgModule.</p><p><em>If you found this helpful at all please hit the clap button about 50 times. It helps this post reach more people.</em></p><p><em>I post on twitter about new articles </em><a href="https://twitter.com/WesTealWhite"><em>here</em></a><em>. I would also really enjoy hearing any response. Just leave them below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1242eeb7153c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular PowerBI and SSRS Components]]></title>
            <link>https://medium.com/@weswhite/angular-powerbi-and-ssrs-components-7a1528cd4247?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a1528cd4247</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[ssrs]]></category>
            <category><![CDATA[power-bi]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Tue, 02 Jan 2018 16:07:01 GMT</pubDate>
            <atom:updated>2018-01-02T16:07:01.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YySR-6iiq1l4pEQbYO7Kow.png" /></figure><p>Here are two components you can drop into any project that abstract out a nice little chuck of logic for displaying PowerBI and SSRS reports inside any application. Drop in these components and use right away.</p><p>Here is the PowerBI component. I takes in credentials and report type as inputs. It also relies on the powerbi-client library from Microsoft.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccd72a1cd831b874961ecaa0e4be9b53/href">https://medium.com/media/ccd72a1cd831b874961ecaa0e4be9b53/href</a></iframe><p>You will need to inject the PowerBI client library into your module. It will look this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a33b103f3fed010654ff6ad70b4b445e/href">https://medium.com/media/a33b103f3fed010654ff6ad70b4b445e/href</a></iframe><p>Here is the SSRS component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fdca8244e6921b2be196d685d048a9bd/href">https://medium.com/media/fdca8244e6921b2be196d685d048a9bd/href</a></iframe><p>Using the SSRS component needs a little bit of an old school endpoint set up next to your data API on your server. But you are looking for an SSRS component you likely already know that. I this example we take in a report type and ids of data to report on. The render report function will need to be modified to fit the desired URL that SSRS will need.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a1528cd4247" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular BehaviorSubject Service]]></title>
            <link>https://medium.com/@weswhite/angular-behaviorsubject-service-60485ef064fc?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/60485ef064fc</guid>
            <category><![CDATA[behaviorsubject]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rxjs]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Fri, 27 Oct 2017 04:27:29 GMT</pubDate>
            <atom:updated>2018-08-09T22:23:12.926Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jajFzgD2WKzgGYCPiwDkVQ.png" /></figure><p>State management in Angular does not have one single prescribed pattern. A data store (similar to ngrx’s store) is a centralized single source (singleton) of state. This fits well with maintaining selected items on the frontend that an app needs to know about. If multiple components care about what a user has selected or input, that can be nicely held in a store.</p><p>RxJS has observers (consuming interface) and observables (push interface). A Subject is both an observer and observable. A BehaviorSubject a Subject that can emit the current value (Subjects have no concept of current value). That is the confusing part. The easy part is using it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c612ad2f40c1631ac04b143ed8d5be0d/href">https://medium.com/media/c612ad2f40c1631ac04b143ed8d5be0d/href</a></iframe><p>The BehaviorSubject holds the value that needs to be shared with other components. These components subscribe to data which is simple returning the BehaviorSubject value without the functionality to change the value. <a href="https://www.bennadel.com/blog/3048-converting-a-subject-to-an-observable-using-rxjs-in-angular-2.htm">Here</a> is a more detailed breakdown of asObservable. In updateDataSelection we call next and pass in a new value to the BehaviorSubject.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e39dfbb11cf23628d960129fb1d9a1b/href">https://medium.com/media/6e39dfbb11cf23628d960129fb1d9a1b/href</a></iframe><p>This is a very simple but powerful pattern. What about remote data? That can work too. More to come on that.</p><p>Next step in learning stores is to dive all in with ngrx.</p><p><em>If you found this helpful at all please hit the recommend button . It helps this post reach more people.</em></p><p><em>I post on twitter about new articles </em><a href="https://twitter.com/WesTealWhite"><em>here</em></a><em>. I would also really enjoy hearing any response. Just leave them below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60485ef064fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack Basics]]></title>
            <link>https://medium.com/@weswhite/webpack-basics-1767c26db102?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/1767c26db102</guid>
            <category><![CDATA[webpack-2]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Thu, 24 Aug 2017 17:33:29 GMT</pubDate>
            <atom:updated>2017-08-31T17:24:19.101Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YIgzMBoz3rMCJpTfrXy73w.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/photos/kQzFr1JqSKM?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Austin Neill</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Webpack is the king of JavaScript tooling. What does it do for me?</p><p><strong>Webpack takes one file and brings in all other code that is imported as it works its way through a dependency tree.</strong></p><p>So I made this assumption that everyone writing frontend code understands the landscape and history of JavaScript. That is not the case. And you don’t have know everything to be efficient in writing a JavaScript app. So here is some information around the basics of Webpack and the problems that is solves.</p><p>Webpack at its purest is a module bundler. If you are writing JavaScript in more than one file but want to have access to functions and classes in other files, you will need to connect your JavaScript. You do this with a bundler. It takes all your files and neatly puts them into one file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/14d56524134e032af871e23d58ef1060/href">https://medium.com/media/14d56524134e032af871e23d58ef1060/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa11a5ef6dcec898fd3f41c49148d30a/href">https://medium.com/media/fa11a5ef6dcec898fd3f41c49148d30a/href</a></iframe><p>In input.js we imported a class, Component . In the ES2015 import syntax we specified the location of the class. Our class is not in the module. So how does this work in a large modern JavaScript application? Well Webpack needs to make a module tree.</p><p>Webpack needs a root position in your app to start making a tree of imports for your module. Webpack calls this a dependency graph and the root of the graph is call the entry point. To define this entry point we need a Webpack config file in our project. In the command line we give Webpack our config file and the bundle is created. Here is a basic Webpack config.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3282e8bead858196a11c2a593c68f700/href">https://medium.com/media/3282e8bead858196a11c2a593c68f700/href</a></iframe><p>The output file it the bundle the is created out of all the imports that tree off the entry file. <strong>Webpack takes one file and brings in other code that is imported as it works its way through all the files. </strong>That is Webpack at its most basic.</p><p>We need to take the bundle and add it to the page we need our JavaScript on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65367aebf461731a9ba3da2659fff68b/href">https://medium.com/media/65367aebf461731a9ba3da2659fff68b/href</a></iframe><p>Webpack also two other core features, Loaders and Plugins. Loaders give you the ability to make modules out of file types other that JavaScript. Plugin allow you to hook into the inner lifecycle of Webpack and perform actions when specific events are emitted.</p><p>You should be using es2015 so we are going to need the babel-loader to give us our transpile functionality. We do this by adding a module property to our config. For all JavaScript files we will use Babel to transpile ES2015 to ES5 and skip node_modules.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/189d0293f06075c002f2acb619c16a4b/href">https://medium.com/media/189d0293f06075c002f2acb619c16a4b/href</a></iframe><p>This is the tip of the iceberg for Webpack. Next you can learn about using Webpack for development servers, transpiling TypeScript or React’s JSX. This is only the beginning.</p><p><em>If you found this helpful at all please hit the </em>❤<em> button . It helps this post reach more people.</em></p><p><em>I post on twitter about new article </em><a href="https://twitter.com/WesTealWhite"><em>here</em></a><em>. I would also really enjoy hearing any response. Just leave them below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1767c26db102" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bring Arguments Back to Angular]]></title>
            <link>https://medium.com/@weswhite/bring-arguments-back-to-angular-59f9417b024?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/59f9417b024</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Tue, 18 Jul 2017 14:37:03 GMT</pubDate>
            <atom:updated>2017-07-18T14:37:03.265Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*meJBEfm5ac8Ugg_OV_goQw.png" /></figure><p>I keep seeing this mistake. Angular components define variables and functions. But I think it is an issue when arguments are not defined for the functions and the component variables are being mutated directly in the functions. Looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/587b8789d6098ca0cc800129916d158d/href">https://medium.com/media/587b8789d6098ca0cc800129916d158d/href</a></iframe><p>So in that component we have an editData function that takes no arguments. It relies on this to glue the variables to the context. It gets the job done, but it is a little too lazy. This is considered an impure function. We cannot know reliably what is going to happen to our data.</p><p>AngularJS gave us created a bad habit. Written in the days of MVC, we had controllers where we happy attached our view data to an object. AngularJS passed that object to the view, and we were happy to let two-way data binding take care of the rest.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1ed8d2924f500abe828cd34068abde69/href">https://medium.com/media/1ed8d2924f500abe828cd34068abde69/href</a></iframe><p>The gist here shows attaching functions and our data to our vm object (view model). But this got us in a bad habit because when we wanted access to our data all we did was type vm.data and there it was. For whatever reason this lead to a wide scale pattern of not using arguments for functions and access the data on the view model.</p><p>Well this needs to go. Next time you write a component function, use arguments. This really seems so simplistic, but there is a lot of code out there relying on this. While this feels obvious to write about, the ease in which Angular allows this with component “global” values makes this mistake so easy.</p><p>The scenario that cause me to write this post went like this; we had a service that retrieved data for a table. The service also handle paging and sorting on the server. The component had a function that called the service and set the return value equal to the data value that was bound to the grid. The issue is that the component function had no arguments. I relied on passing the this variables straight to the service. Two big issues come out of that. The function is not pure and the function is not testable. Impure functions take more effort to understand, and because internal state drives the function, the call cannot be mocked.</p><p>In summary, component functions in Angular need arguments all the time even if they only rely on component this values. AngularJS may have made us too relaxed in how we think about attacking our data to the view. Angular’s class structure also makes it far to easy to write this kind of code. Use arguments. If executed properly you will have nice, testable, pure functions. That is a good thing.</p><p><em>If you found this helpful at all please hit the </em>❤<em> button . It helps this post reach more people.</em></p><p><em>I post on twitter about new article </em><a href="https://twitter.com/WesTealWhite"><em>here</em></a><em>. I would also really enjoy hearing any response. Just leave them below!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59f9417b024" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Data Part 1: Fetch]]></title>
            <link>https://medium.com/@weswhite/javascript-data-part-1-fetch-e8230e5942dd?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8230e5942dd</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[fetch]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Tue, 16 May 2017 21:27:16 GMT</pubDate>
            <atom:updated>2017-05-17T13:57:37.201Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_0qcWhJBOX_56WGLvhRpw.png" /></figure><p>There are many ways to fetch a resource. The Fetch Standard is an effort to unify the architecture around how JavaScript gets remote data. Fetch had its first <a href="https://github.com/whatwg/fetch/graphs/commit-activity">GitHub</a> commit May 22nd 2016. So now in May 2017, fetch is still a new, but mostly known, feature of JavaScript <a href="http://caniuse.com/#feat=fetch">widely supported</a> in modern browsers (meaning you can use it, but must polyfill if your targeted browsers are not supported).</p><p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch </a>is a method to call a server endpoint. It takes a mandatory argument, the path to the resource being fetched .Fetch gets passed (or creates) a <a href="https://developer.mozilla.org/en-US/docs/Web/API/Request">Request </a>object, and it returns <a href="https://developer.mozilla.org/en-US/docs/Web/API/Response">Response </a>object. The response is in the form of the well loved promise.</p><p>Why Fetch? Fetch can be used to fully replace the XMLHttpRequest object. Fetch boasts a cleaner request API and more robust response functionality. To be clear here, fetch adds Requests and Response primitives. This is a big win and not supported by XHR. These primitives enable us to leverage Service Works where w could not in XHR. Fetch also giver the option to make CORS calls (something XHR cannot do). Fetch brings in cache control. Fetch is much more readable and concise.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b87359e3cb5d5ee1224ccca0712cefe/href">https://medium.com/media/3b87359e3cb5d5ee1224ccca0712cefe/href</a></iframe><p>For the request, pass in a URL, a method type (GET, POST, etc.), some headers, maybe some credentials to the Request object. Is it a CORS call or not? Then give it to fetch().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9931d6223f64ed6c6a454605ab63d4a8/href">https://medium.com/media/9931d6223f64ed6c6a454605ab63d4a8/href</a></iframe><p>Read the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Request">fetch request API</a> if you want to know all the features available.</p><p>After fetch gets your data and its promise resolves, then() is called and passed your Request object to be handled (<strong>Remember</strong>: then() is called when a promise is resolved). The fetch Response object has built in methods to handle how your Response object is going to return data. Most common is the json() method that converts your data to a JSON object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6cac49427542fdb27c0afd6299468274/href">https://medium.com/media/6cac49427542fdb27c0afd6299468274/href</a></iframe><p>Response are streams. This opens up the opportunities to read response streams and start rendering views off the uncompleted stream.</p><p>Since promises can be chained with .then, you can use this to generalize your code if you are handling many fetch response over and over. You can write functions that return promises that check the status and parse the json, leaving only the data left to be handled. Its nothing too crazy, but it could slim down some code if a lot of fetch calls are going out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e1958b52021213548769e05343a2a11/href">https://medium.com/media/0e1958b52021213548769e05343a2a11/href</a></iframe><p>One thing as of May 2017, engineers are still waiting on fetch to be able to cancel requests. It is supposed to be added in the future. We will see… I got word from Reddit that the promise cancellation proposal that would enable fetch to cancel requests was dropped. We may have to wait awhile before we get around to canceling promises.</p><p><em>If you found this helpful at all please hit the </em>❤<em> button . It helps this post reach more people.</em></p><p><em>I post on twitter about new article </em><a href="https://twitter.com/WesTealWhite"><em>here</em></a><em>. I would also really enjoy hearing any response. Just leave them below!</em></p><p>For further reading I would suggest <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">MDN</a>, <a href="https://davidwalsh.name/fetch">David Walsh</a>, <a href="https://jakearchibald.com/2015/thats-so-fetch/">Jake Archibald</a>, and <a href="https://developers.google.com/web/updates/2015/03/introduction-to-fetch">Matt Gaunt</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8230e5942dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Dependency Injection, Singleton Services, and A Loading Indicator]]></title>
            <link>https://medium.com/@weswhite/angular-singleton-service-and-a-loading-indicator-ca3cc7892722?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca3cc7892722</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[loading-indicator]]></category>
            <category><![CDATA[singleton]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Thu, 04 May 2017 21:51:28 GMT</pubDate>
            <atom:updated>2017-05-17T14:20:03.372Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E9k13VIF_bFvX3WJimIVNA.png" /><figcaption>Weeb</figcaption></figure><p>Every project needs a loading indicator. Routes need to be able to call it. Service calls need to have access to it while fetching data. People are happier when they know something is happening, but that something is not finished yet. So what is the best way to make one? I think a good singleton service will get the job done.</p><p>So what do I mean by singleton service in Angular world? Here I am talking about a service instance that is shared across components. Think one service with a given state shared across any component that imports and references the service in its constructor.</p><p>Taking a step back to develop a mental model. Components get access to service through Angular’s dependency injection system. Angular goes with a hierarchical DI system (<a href="https://angular.io/docs/ts/latest/guide/hierarchical-dependency-injection.html">read more here</a>). Angular asks you to think about it as if all component have their own injector. What gets injected into a component depends on the components provider settings as well as the providers of the parent components higher in the overall component tree. So there is the catch; components inherit the service instance of their parent (or parent’s parent and on up). But, if a component adds a service reference to its list of providers that the parent also injects, a new service instance will be instantiated that does not share state with the parent’s service.</p><p>So that is kinda weird, but it also allows for us to segment our services to component trees and ngModules (because ngModules have injectors too). Two different ngModules may need a service but need two separate instance of it. All that is needed is a reference in the ngModules provider for each module and then you have two separate singleton. So I guess its not really a singleton, but its not a cluster, so I guess is just two singletons. The singleton name is not perfect, but once you understand Angular’s hierarchical DI system all is well.</p><p>So how does this apply to a loading indicator? Well we want a service that is at the very top of app so that any component that calls it can display an indicator when loading anything. We will have a show method and a hide method. If two components call for the show method we will wait for two hide calls to hide the indicator. That’s about it.</p><p>In the component file we need a RxJS subscription to hold the state from the service. Notice how we do not have any provider for the component. Our template conditionally renders the loading indicator based on the subscription state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/350762e677f8d2fc624d1cb84b4a6897/href">https://medium.com/media/350762e677f8d2fc624d1cb84b4a6897/href</a></iframe><p>Some styles for rendering in the middle of the page</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/74ef17b169c7278788d8f90510d0ef27/href">https://medium.com/media/74ef17b169c7278788d8f90510d0ef27/href</a></iframe><p>Next we have our service. Here we create a RxJS subject observable that will push any state changes to the subscribers. We also have our methods to control the loading indicators state. The counter tracks the number of calls so that the loading indicator is only hidden when all of the calls are resolved.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/78ff0f47571b420e14a41f33d884d6dd/href">https://medium.com/media/78ff0f47571b420e14a41f33d884d6dd/href</a></iframe><p>Now we have a component that can be added to our ngModules. We want to provide the service at the top level ngModule. This will give the entire tree underneath the same service instance. Now we just need to call the show method in a component before we go get data and when we have it back, call hide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*FJTeSo9n0tfryjpen-anvw.gif" /><figcaption>Weeb</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca3cc7892722" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Fiber, a thread optimizer]]></title>
            <link>https://medium.com/@weswhite/react-fiber-a-thread-optimizer-a312f6d4599e?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/a312f6d4599e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-fiber]]></category>
            <category><![CDATA[fiber]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Fri, 28 Apr 2017 16:42:27 GMT</pubDate>
            <atom:updated>2017-04-28T16:42:27.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gtptRqPaamv4-cAxAhsHuQ.png" /></figure><p>React was introduced to the JavaScript world packaged with the Virtual DOM, changing the way we think about rendering changes in the browser. These changes are made in two parts. First, the <em>reconciliation </em>algorithm calculates the change needed. Then, the <em>render </em>makes those changes. The reconciler and the renderer are core to React. React v16, or React Fiber, is a rewrite of the reconciler.</p><p>React Fiber is not a new JavaScript frame work created to exacerbate fatigue and frustration of those trying to learn everything ever. React Fiber is a rework of framework internals that happens to make some breaking changes to v15 codebases.</p><p>Here is a great overview of Fiber from Mozilla’s Lin Clark. You could watch this and be done with this article. Everything below will be more simplistic than the content taught here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FZCuYPiUIONs%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DZCuYPiUIONs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FZCuYPiUIONs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/717e79384ef6aa96c4b9567250418116/href">https://medium.com/media/717e79384ef6aa96c4b9567250418116/href</a></iframe><p>So at a really basic level, what does Fiber aim to accomplish? It wants to increase perceived JavaScript runtime performance by tell the browser what changes are most important and when they should be done. This is accomplished by providing a hierarchy of importance based on the priority of the action in the queue of needed actions. Fiber is strategy engine to make the JavaScript thread work better with the written components. It is a scheduler of the main (and only) thread.</p><p>At a really base level, React creates component trees that have state and actions (parent and child style) that needs to be built up, called, and handled as React moves down the tree and all the components’ lifecycle methods. A fiber is the data structure used by the thread to keep track of the current position on the component tree. This fiber is used to allow the main thread to come up for air and complete high priority tasks while it is working its way down the tree. Instead of the threads process execution order looking like the Grand Canyon with far reaching canyon walls, and a rock bottom, executed in an inefficient <strong>U </strong>fation, Fiber can schedule the thread to work more like fast rolling hills, reaching down when needed but able to come back up when needed.</p><p>Fiber builds the tree of changes and executes them in phases. Phase one is the reconcilation and render phase. Phase two is the commit phase. In the reconcile and reader phase, Fiber executes <strong>componentWillMount</strong>, <strong>componentWillRecieveProps</strong>, <strong>shouldComponentMount</strong>, and <strong>componentWillUpdate</strong>. In commit phase, <strong>componentDidMount</strong>, <strong>componentDidUpdate</strong>, and <strong>componentWillUnmount</strong>. By looking at when the lifecycle methods get called, Fiber’s hierarchy begins to take shape.</p><p>So in Fiber, what takes priority? What is most important? Fiber has six levels of priority. Here is a basic list. Watch the linked video for a better explanation of this.</p><ol><li>Synchronous Actions</li><li>Task</li><li>Animations</li><li>High priority actions</li><li>Low priority actions</li><li>Offscreen actions</li></ol><p>React Fiber is not here as a new framework to be learned. Instead, Fiber is here to help the main thread execute the needed actions in a more efficient sequence of events, increasing performance without necessarily increasing execution speed. Pretty smart…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a312f6d4599e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Inter-component Communication Part 1: The @Input]]></title>
            <link>https://medium.com/@weswhite/angular-quick-concepts-inter-component-communication-part-3-the-input-4ab6fd53344e?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ab6fd53344e</guid>
            <category><![CDATA[change-detection]]></category>
            <category><![CDATA[putin]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Mon, 10 Apr 2017 00:39:20 GMT</pubDate>
            <atom:updated>2017-04-10T01:47:14.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KM5X-7yE5bnia1J4J8pfew.png" /></figure><p>For real this a real quick one. But this does bring up a pretty crucial topic along the way, change detection. This will touch on CD a little but a another post will be dedicated to outlining CD more fully.</p><p>I have a hierarchy. How do I pass the state (data) I have in my parent component to the child components making up the whole? Use @Input().</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d2d77d328e2624881d8d750986d2a14/href">https://medium.com/media/3d2d77d328e2624881d8d750986d2a14/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00bd4f5d74141b930ae6f6ecf4126cae/href">https://medium.com/media/00bd4f5d74141b930ae6f6ecf4126cae/href</a></iframe><p>So the concept is pretty straight forward. The top level parent owns all the data. The child components are passed the data. When implemented correctly, the child components <strong>do not change the data given to them</strong>. This is a term called immutability. Immutability in component state keeps our local app state in sync. If only the parent component can change state and do so in a manner that keeps our data immutable (unchangeable), the Angular can quickly and efficiently push state changes to all the components that consume the same state.</p><p>Immutability can be a deep subject, but what is important to take away is our parent component holds state. It gives state to the child through the @Input. If the child needs to change state, it emits an event that the parent can listen to. The parent handles the event with the parameters given to it from the child EventEmitter and can make changes to the immutable state. Then Angular change detection handles pushing the new state to all the child component @Inputs. How to makes changes to immutable state is another topic. <a href="https://vsavkin.com/immutability-vs-encapsulation-90549ab74487">Read more on that from Victor Savkin</a>.</p><p>Asynchronous data throws a wrench in our system. When the parent component is being built by Angular at render time it does not have the data back from the server to bind to the inputs of the child components. The parent component will send an undefined input value to the child. But when the data does come back from the server we need to make sure that data is given to the child components. This is change detection. What the components do when a change in state is detected?</p><p>In AngularJS this was handled by dirty checking. It was like a file watcher looking for changes. This was simple for implementation, but not performant. Instead Angular changed the CD architecture to a push approach like React. This means components need to be more explicit in stating how they are going to handle state changes.</p><p>So how do we update child component input values if not using immutable objects? We get a life-cycle function, <a href="https://angular.io/docs/ts/latest/api/core/index/OnChanges-class.html">ngOnChanges</a>. This gives us an object we can use to set the value of the child state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce633d82a612ddddc9b7a695e259c6fb/href">https://medium.com/media/ce633d82a612ddddc9b7a695e259c6fb/href</a></iframe><p>Or we can use Inputs with get and set methods that call when a component input changes.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d438b4da946554d4e98f2cb652c1ccf2/href">https://medium.com/media/d438b4da946554d4e98f2cb652c1ccf2/href</a></iframe><p>But if you are use immutable data structures or observables (observables are immutable by nature of returning new object on .next ), you can optimize your change detection performance with <a href="http://stackoverflow.com/questions/39795634/angular-2-change-detection-and-changedetectionstrategy-onpush">ChangeDetectionStrategy.OnPush</a>.</p><p>But at their simplest, @Inputs get state down to the child components. This opens the door for Angular’s new Change Detection engine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ab6fd53344e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular Inter-component Communication Part 2: The Event Emitter]]></title>
            <link>https://medium.com/@weswhite/quick-angular-concepts-inter-component-communication-part-2-the-event-emitter-6ba93e15333e?source=rss-97cf7cdb9cec------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ba93e15333e</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[output]]></category>
            <category><![CDATA[emit]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[eventemitter]]></category>
            <dc:creator><![CDATA[Wes]]></dc:creator>
            <pubDate>Tue, 04 Apr 2017 18:27:22 GMT</pubDate>
            <atom:updated>2017-04-10T01:47:31.452Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CPFhyZ86pujpX1Tkf94xzw.png" /></figure><p>Angular components fit really nicely in a modular, parent/child hierarchy. In part 1 of Angular component communication talks about how parent components call methods living on child components. But how do child components tell the parent component that a specific event has happened? That is the job of the Event Emitter.</p><p>Angular components can take in @Input() and @Output(). @Input is how components get data passed in (look out for a post on these, because while very basic you can do some cool thinks with them). @Output is our Event Emitter.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fea8b156ea45d56ccb421ab5060f2b51/href">https://medium.com/media/fea8b156ea45d56ccb421ab5060f2b51/href</a></iframe><p>Now that we have the basic child component laid out we can register a handler of the EventEmitter what will be called when .emit() is called. This is called the output handler, and it is defined in the parent component.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/562c749dec59f7dce4486298655d2506/href">https://medium.com/media/562c749dec59f7dce4486298655d2506/href</a></iframe><p>This pattern opens up a lot of option for handling events. It is really flexible. The EventEmitter is built on the Observable. The emit() called be view a lot like next(). After looking over this post and the context of ViewChild, the concept of inter-component communication should start to solidify. You can look over the <a href="https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html">Angular docs for EventEmitter here</a>. The last (but actually probably first) step to inter-component communication is @Input(). While it is pretty intuitive, I will outline it in another post to show off some cool features.</p><p>Another note about the EventEmitter is that is takes a boolean in the constructor called isAsync. By defualt this boolean is set to true, meaning EventEmitters are asynchronous. All this means is when the EventEmitter fires, by default, the component zone will run through the rest of it stablization (you dont really need to know what that means. I am just getting into Zones anyway). If set to false (making the EventEmitter synchronous), as soon as the EventEmitter fires, so too will the event handler in the parent component. <a href="https://www.bennadel.com/blog/3071-synchronous-vs-asynchronous-eventemitters-in-angular-2-beta-14.htm">A post by Ben Nadel</a> talk more about that. But he summarizes that synchronous event handling is rarely needed.</p><p>One last bonus, Event Emitters can also be named Outputs. You may run into that in other’s code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7072c15c2ce58728bce88a3ae51e3b1/href">https://medium.com/media/c7072c15c2ce58728bce88a3ae51e3b1/href</a></iframe><p><a href="https://toddmotto.com/component-events-event-emitter-output-angular-2">Todd Motto has more words about this stuff</a> if you want even more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ba93e15333e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>