Tag: Javascript

  • Creating database migrations and seeds in Node.js

    This can be all done with knex library, a SQL query builder for JavaScript. In this post I’ll use MySQL (MariaDB) database, but knex also supports Postgres, MSSQL, SQLite3, and Oracle. I will also use faker for generating fake data for seeding the database. Install knex, faker and mysql (or any other driver for database…

  • Testing React components

    There are two aspect of testing React components: testing their structure (desired markup is displayed) and behaviour (e.g. when clicking on a button this function will be called or something different will appear in component’s markup). Testing component structure is best done with shallow rendering since it renders only provided component and not its potential…

  • Spread operator for faster JavaScript debugging

    Spread operator in JavaScript version ES2015 lets you explode array elements into arguments. That can be very useful when creating a new array consisting of all elements from another array ((so that you don’t mutate the latter)) or when calling a function with arguments that are in array ((equivalent to calling a function with .apply…

  • Learning Redux: A step beyond “todos” and “async” examples

    For the past two days I’ve been into Redux. It’s a framework-agnostic JavaScript library for easier handling of all application’s state. Specialty of Redux is that application state is stored in one object (and not different object for different data domain) and that functions reducers which manipulates part of the state never mutate it but…

  • Array-like objects in JavaScript

    Do you know what the difference between following two snippets are? Why are we in first case calling map function on array but than at second we call map it as prototype.map.call method which exists on function object (almost everything in JavaScript is an object). var numbers = [1,2,3,4] var multipliedBy3 = numbers.map(function(number) { return…