First of the Week Reading List

How to use npx: the npm package runner

There’s so much to say about `npx`, but essentially, it allows you to run package (think of the cli tool that comes with a package) without installing it globally, or without installing the package at all!


Microsoft: We want you to learn Python programming language for free

Learn Python for free! But obviously, you probably already expect this, that it will also promote the usage of Azure.


Google reveals new Python programming language course: Scholarships for 2,500

Well, if Microsoft has free Python course, Google gotta launch its own. Soon, I’m sure Amazon will follow. Google course is not free however, but will give scholarship to 2500 students.


Third-Party Components at Their Best

This post is less of educational, but more of “things you should have”, aka checklist, if you want to use third-party UI components. But, it also applies to non-UI, it applies to any open source really. And you can even use this checklist if you want to start your own open source project.


6 Ways to Unsubscribe from Observables in Angular

Yes, the glorious Observables in Angular. It’s double-edged sword, but it will only hurt you if you forget to unsubscribe. Luckily, there are 6 ways to do it. This post will show you how.


More Reading List

100 new requests in Node.js while still serving the first one

This is an interesting look into how Node.js works under the hood when serving multiple requests. It’s different than how Apache, Tomcat or IIS serve the request from users. Pretty interesting.


Promises and async/await relationship

I always wonder how they actually relate to each other. This short post explains it concisely. They are also interchangeable.


Best Practices for REST API Error Handling

I’d categorize this more of “basic” practices. However, just because it’s basic, doesn’t mean you can ignore them. In fact, they are very important in building APIs.


How to handle exceptions in asynchronous code in C#

The main (and probably the only) takeaway from this post is that exception thrown in an `async` method that returns a `Task` object is wrapped in an instance of `AggregateExpcetion` which you would have to access with `tasks.Exception` instance. Check out the code example in the post.


Reduce Change Detection Cycles with Event Coalescing in Angular

Event bubbling in Angular app can be problematic when it triggers change detection. This post shows you how to coalesce them.


A Reading List

Creating PWA Using Angular 7 – Step-by-Step Guide

A rather long and detailed post about Angular and PWA (Progressive Web App), but worth the read, especially if you haven’t heard about PWA. It covers the 101 stuff and goes on to creating PWA using Angular.


How to use Azure Bastion to connect securely to your Azure VMs

Great new offering from Azure. If you always RDP to your VM in Azure, or use a _’jump box’_, you will have a new, better, more secure way to RDP now. I really like the name too!


Lessons from Design School for Software Engineers

They are great lessons software engineers can adopt to become better. Not a technical post, but related to technical. It’s more of philosophical-type post, which is always good to know.


The Battle of C# to JSON Serializers in .NET Core 3

There’s a new kid in town, it’s called `System.Text.Json`. Michael goes over how the comparison between this new .NET Core 3 feature and other JSON libraries, including the infamous Json.NET. And yes, it cover performance test as well.


How to resolve .NET reference and NuGet package version conflicts

Have you ever got one of those annoying, `Could not load file or assembly or one of its dependencies` error when running .NET locally? Not only Michael explains why, but he also tell you how to resolve it. Mystery solved.


List to Read

The emerging big data architectural pattern

An Azure post about big data architecture. If you are about to start one, this is a good introduction. It mainly focuses on Lambda architect (batch and speed layers) using Azure resources.


Roadmap for learning the JavaScript language

Do you just start learning JavaScript? Are you planning to master JavaScript? This post is for you. Learn JavaScript from the early version and how it evolve to current version.


Choosing the right frontend database for a single page application

And if you are now serious about PWA, check this article out on what’s the ‘right’ frontend database for your app. Very useful especially when you are starting a new project.


Turn your Angular App into a PWA in 4 Easy Steps

Now you know what’s PWA, you can turn your existing Angular app into a PWA. Looks pretty straigh-forward honestly. But the devil is always in the details, right?


Progressive Web Apps & Electron

You can’t talk about PWA without Electron app. But, what’s the difference? Well, check this post out to find the answer. In short, they are like siblings, similar but different.


Integrate Ionic in Existing Angular Project

Angular Project

I just finished my project, written in Angular and although it runs on mobile browsers, it needs to be deployed as a native application. The choice is obvious, Ionic.

I’m integrating Ionic for Android development, but it’s optional. You don’t have to prepare your Ionic project for Android development, if you don’t want to. The same concept can also be used to prepare your project for iOS development.

This applies to:

  • Angular 7.
  • Ionic 5.
  • Java SDK 8 update 202.
  • Android SDK 9.0 (API level 28)
  • Android Studio 3.3.2

Here’s my approach integrating Ionic in my Angular project.

Bring-in Ionic

The step includes creating a new project using Ionic CLI, I’m going to refer it as Ionic project while my original Angular project as, well, Angular project.

  • In your Angular project, update all npm packages, to the latest major if you can. This is to avoid version conflict with Ionic project’s npm packages.
  • Start a new Ionic blank project.
    ionic start project-name blank
    
  • Update all npm packages in the newly created Ionic project.
    npm i -g npm-check-updates && ncu -u
    
  • Copy ionic.config.json from Ionic project to Angular project.
  • Copy angular.json from Ionic project to Angular project.
    • If you have specifically changed anything in your angular.json, make that necessary changes in the Angular project after the copy.
    • Ionic uses SCSS for style sheet by default, so if you are not using SCSS, make sure to copy settings under projects/app/architect/**/options/styles from Angular project’s angular.json prior to copy.
    • integrate-ionic-in-angular-project-1
  • Copy package.json from Ionic project to Angular project.
      • If you have specifically changed anything in your package.json (npm scripts, etc), make that necessary changes in the Angular project after the copy.
      • Combine the npm packages from both projects setting under dependencies and devDependencies.
      • integrate-ionic-in-angular-project-2

     

  • Combine .gitignore files from both projects, if you are using Git source control.
  • In Angular project, delete package-lock.json file and node_modules folder. These should be located in root of the project.
  • In Angular project, run npm install command.
    npm install
    
  • Test and make sure everything runs.
    // Test run with Ionic
    ionic serve
    // Test run with Angular
    ng serve --open
    
  • If you want to prepare your project for Cordova, runs the following command. Note that environment setup is required. Please refer to reference section for more details.
    // For Android
    ionic cordova prepare android
    // For iOS
    //ionic cordova prepare ios
    

References

Barebone Angular with D3 v5

Just uploaded Github project showcasing sample Angular project with D3 v5.

The project contain implementation of D3 v5 in Angular project and consist of most popular D3 features such as Basic shape, Animation, Chart, Dragging and Zooming. Each sample is self-contained. D3 dependencies can be seen on `package.json`.
Time permitting, I will add more samples in the future.

For D3 new-comers, check out this resources explaining most important concepts in D3, Selection, Joins and if you work with chart, Scale.

NgRx Entity

NgRx Entity

NgRx Entity is a library to handle entity within NgRx framework. The entity in the context is defined as the application’s domain objects, like User, Employee, etc.

The purposes of NgRx Entity are basically:

  • Reduce boilerplate code.
  • Search and sort entities quickly.

The first thing we need to use NgRx Entity is to create an entity adapter, like so:

const adapter = createEntityAdapter();

NgRx Entity also defines `EntityState<>` interface. The interface is also extensible should the additional properties in the application state are needed,

The shape of EntityState is something like this:

interface EntityState {
  ids: string[];
  entities: { [id: string]: V };
}

What this allows us to do is:

  • Find entity quickly using `entities` dictionary.
  • Maintain order of the list, good for use in sorting.

Some boilerplate codes that are reduced when using NgRx Entity:

  • No need to specify properties of the state interface.
  • Add, remove, update of entities in the state are handled by entity adapter.
  • Entity adapter has most commonly used selectors.

Reference

https://medium.com/ngrx/introducing-ngrx-entity-598176456e15