JavaScript Promises – how to (not) use it

How do you handle asynchronous operations in JavaScript? Working with callback function was the common way for years and it still feels like spending some time with a good old friend. But using callback functions do have some drawbacks (we will talk about later). Since ES2015 we have Promises. ES2017 will even simplify the work with asynchronous operations. So, if you didn’t take a deeper look into Promises yet, you should. Promises can be a real game changer for your code – if you use them right.

Continue reading “JavaScript Promises – how to (not) use it”

The best way to unit test React components using ES6 with Babel

Some days ago a colleague asked me how to write tests for React components. It wasn’t just a challenge to write the tests but also to set up the whole environment to run the tests and measuring the code coverage. I did some googling to solve the problem and I realised that there are several ways to solve them. Some solutions work and some not. I will show you my solution that works!

Continue reading “The best way to unit test React components using ES6 with Babel”

React – What and why?

Countless posts have been done about react so here goes another one. 🙂 React is a framework for developing web applications by Facebook. BUT unlike Angular or Ember.js or others it features ONLY the view layer. This cannot be stressed enough when talking about which framework to use for a new project. React does not offer an MVC pattern or similar things. There is no data layer, no connection libraries to the backend, no wrapper functions to ajax calls, no promises and so on. React does however feature some interesting view layer features and architecture ideas.
Continue reading “React – What and why?”

Lightning Talk: PostCSS

The talk gives only a brief overview about PostCSS in general and the most interesting plugins. The cssnext plugin seems to be an interesting alternative for LESS or SASS. After the talk we considered to apply this tool in an internal project to check out the usability. We do not bring it into our main projects because we are not sure about the stability and the community support. Will the PostCSS project be still alive in some years?

Workshop: Webpack – Part 1: Theory

Due to the fact that webpack is a very complex subject I will split my posts in 3 parts which will be posted every 2 weeks.

Today we’re starting with a little theory.

What is webpack?

In short, webpack is a JavaScript module bundler and its main purpose is reducing the initial load of your website.  It combines the idea of building your assets and bundling them into one by analyzing the dependencies of the configured entry point. By having the opportunity to use synchronous and asynchronous dependencies, webpack is able to split the code into chunks to create contextual bundles.

Continue reading “Workshop: Webpack – Part 1: Theory”

Functions with optional parameters

Today we are having fun refactoring legacy code. In our application there are  functions with various optional parameters.

callRequest(method, params, data, headers, url)

Only method is mandatory, all other parameters are optional. The status quo consists of each parameter being checked for existance, not very pretty…

callRequest(method, params, data, headers, url) {
    if (headers && headers.length > 0) { 
        ... 
    }
    ...
}

Continue reading “Functions with optional parameters”