RxJS 6 Patterns with Angular Material: Refresh Button

RxJS + Angular + Material

In this article, we’ll be looking at a very simple RxJS 6 pattern that allows us to easily refresh data coming from REST APIs (or any other async data source).

In Angular, we’ll be using a service to handle most of the work, including the data fetching and the refresh logic.

Let’s look at a mock service that we’ll be using to fetch some data from a REST API.

TypeScript
export class MockService {

  refresh$ = new ReplaySubject(1);
  data$: Observable<SomeDataType>;

  constructor(private http: HttpClient) {

    this.refresh();

    this.data$ = this.refresh$.pipe(
      switchMap(() => this.getData()),
      share()
    );
  }

  refresh() {
    this.refresh$.next();
  }

  // This one could also be private
  getData(): Observable<SomeDataType> {
    return this.http.get<SomeDataType>(`url`);
  }
}

Read more

RxJS 6 Patterns with Angular Material: Confirmation Dialog

RxJS + Angular + Material

Intro

This basic pattern applies to RxJS 6 in combination with Angular Material. However, it can be applied to any other environment that supports RxJS 6, as long as you have an observable-based dialog implementation.

Desired behaviour

  1. A user clicks on a button
  2. A confirmation dialog is shown
  3. If the user confirms, an action is performed

Read more

SASS-only Material Angular Palette generator

SASS Material Angular Palette Generator

With my job, I often need to replicate projects from a template based on Angular Material. When I do that, one of the first things that I usually need to change is the color scheme.

Angular Material’s color scheme is defined by two palettes: primary and accent. These two palettes define a range of colors used by all components.

There are many tools available online to generate such palettes. My personal favourite is Material Design Color Generator (also available on GitHub). This tool includes a code generator that automatically creates a SASS list in Angular Material’s accepted format.

I based my SASS color palette generator on Mikel Bitson‘s code. This is a simple SASS translation that makes it easier to adjust colors directly from your code. 

Read more

Unique random coupon code generation in PHP

Generating pseudo random codes is usually a trivial task. However, coupon codes should have two features that make them computationally complex:

  • They have to be unique
  • They should be hard to guess

A third optional feature would be readability. This means that the final user should not be thinking “is this 0 or O?“.

I found the problem intriguing and decided to make my personal implementation of a coupon code generator in PHP.

Read more

Google’s Codebase Insight: great for small businesses?

The 2015 edition of @Scale featured an extremely interesting insight on how Google handles its codebase.

I won’t repeat what is so clearly explained in the video. Instead, I would like to focus on its potential viability for very small companies.

Indeed, sky high numbers like Google’s require a huge effort in tooling, standardization and definition of constraints and procedures. As a result, similar companies willing to unify their codebase would generally consider it unpractical.

However, I believe that a monolithic codebase could be a huge improvement in efficiency and reliability for small software houses, for several reasons.

 

#1: Organization

Small companies tend to have little to no policies in terms of repositories, code quality, conventions, etc. Thus, code improvements, modifications, copies, versions, docs and changelogs have a tendency to scatter around company systems, personal computers and the internet. If there is one repository, then everything can be kept together and under control.

#2: Code reuse

That’s pretty much the same for Google. You write code once and then use it across multiple softwares. However, in small companies code reuse can become a nightmare (see versions fragmentation, unmerged customizations,…). With little to no policies, versions can even be lost on some hard disk placed somewhere. A unified codebase may help keeping things tidy.

#3: Everyone knows everything

In small companies, that’s quite common as well. The team is small and everyone knows what the others are doing, even if they’re working on different projects. In a collaborative environment, one repository facilitates code browsing and shortens times to access snippets and functions. Changes and improvements to shared codes and services can be discussed together and implemented, without requiring huge investments on tools.

#4: You can always detach projects

If things are going well and the company quickly scales up, you always have the option to detach projects from the main repository. This is obviously a choice that can be either great or terribly wrong depending on the context. However, it is always good to know that you have an “emergency button”.

 

CONCLUSION

Small companies that cannot invest in the definition of software developement processes may benefit from a monolithic codebase like Google’s. It helps keeping things organized and accessible while leaving the option to adopt a different strategy when things get more complex. As always, it’s a decision that needs to be evaluated in its context of application, but I believe it’s worth considering.

An easy and maintainable implementation of IsolatedStorageSettings

Recently I’ve been working on a Windows Phone app that comes with a good number of settings to implement. The official examples that anyone can find online report a simple procedure. Let’s say I want to implement the UserToken setting, then I would have to do something like this: [code language=”csharp”] // Access the settings … Read more