Posts

Showing posts with the label Front End Programming

JavaScript Promise

Nothing weights lighter than a promise This maybe true regarding to human promises, however in the programming domain, promises are always kept. Following this optimistic note, today we'll be talking about JavaScript promises. Event Handling Problem Let's see what promises are good for and their basic capabilities starting with a problem they come to solve. Events are great for things of a repetitive nature like keydown , mousemove etc. With those events you don't really care about what have happened before you attached the listener. On contrary calling services and processing their response is a completely different kind of beast. Have a look at the following function, which reads a json file and returns it's content or an error in case of something goes wrong. function readJSON(filename, callback) { fs.readFile(filename, 'utf8', function (err, res) { if (err) { return callback(err); } try { res = JSON.parse(res); ...

EcmaScript6 with TypeScript and Grunt.js

Image
ECMAScript 6 is nearly here . In fact I can already taste it and so will you with TypeScript . TypeScript is an open source language and compiler written by Microsoft running on NodeJS. The language is based on the evolving ES6 spec but adds support for types, interfaces that generates JavaScript (ES3 or ES5 dialects based on flag). In fact it's very interesting shift for Microsoft to make something useful for open source community, so before you boo me, have a look at it as it's not so bad. Introduction Microsoft has compiled a great video introducing the TypeScript and since one video replaces million words, let's start with it. Using TypeScript As TypeScript is built on top of Node.js, installing it will be as easy as breathing. npm install -g typescript And compiling the files is done through the tsc command, however this is no way respectable developers work. We'll be using Grunt.js to compile our TypeScript files during the build phase. Let...

Automate JavaScript Testing with Grunt.js

So far we've learned how to test your JavaScript code with Jasmine and running them against Node.js and browsers with Karma . We've also got familiar with modular design patterns in JavaScript . And yet, somehow it seems that we're still missing one last puzzle piece connecting all the others, it's called Grunt.js . What is it? According to it's site: In one word: automation. The less work you have to do when performing repetitive tasks like minification , compilation, unit testing, linting , etc, the easier your job becomes. After you've configured it, a task runner can do most of that mundane work for you—and your team—with basically zero effort. Zero or not, there is a bit of effort in making everything play together, but no worry - we'll figure it out. So what's our plan? Write classes, which are both usable in Node.js, Require.js and global environment. Write Jasmine specs to test our code in both Chrome and Firefox Write Karma ...

AngularJS Debugging with Batarang

Image
It's been a while from the moment I started to blog about JavaScript topics and despite me being MEAN developer; Heh-heh, actually I'm quite friendly. Anyway, despite the MEAN orientation of the blog, I haven't talked much about the "A", that is AngularJS. Well, today we are going to fix this and since it's the first blog of the month, we'll be talking about Batarang - debugging tool for AngularJS. Why even bother? I use Chrome Over the years a lot of developers have shifted to rely entirely on Chrome developer tools in terms of debugging front end applications. While Chrome indeed provides a superb build-in debugging functionality, it doesn't support specific aspects of modern frameworks like AngularJS and Ember. For instance it's not aware AngularJS scopes and models. Being a JavaScript application, one can of course debug AngularJS code as any other web application, however if you're not a stranger to Zen Coding , than producti...

Sass and Compass

It's first week of August, and it means it's time for continuation of JavaScript Developer Toolkit series. Last month we talked about Sass and I promised I would elaborate on the topic with Compass . So let's talk about Compass. What is Compass? Compass helps Sass authors write smarter stylesheets and empowers a community of designers and developers to create and share powerful frameworks. Put simply, Compass is a Sass framework designed to make the work of styling the web smooth and efficient. Since it's based on Sass, it's compiled into regular CSS rules and is not required to be installed on production environment. Let's start with installing it on our machine: gem install compass Yes, it's Ruby again and you'll have to live with that. If the command is not recognized, then you probably haven't installed the Ruby on your computer. To do so, please read the  JavaScript Developer Toolkit  article. Compass is made up of three main com...

Jasmine and Karma

Let's talk about testing again, and will surely again in the future :) Last time I introduced the JavaScript Testing with Jasmine and we ran a few specs, however it seemed some how half baked - you were required to create a special page and open it in the browser to see the results. I you wanted to check in various browsers, you should have iterated the same procedure on each browser again and again. This is not how we do things in 2014! We want to streamline the process! This is where Karma comes. It is built on Node.js and allows you to run the tests of your front end code automatically on various browsers. Installation In order to install Karma on your computer, run the following npm command. If you're not familiar with the tool, please read the JavaScript Developer Toolkit article first: npm install -g karma After you try to call karma though, you'll get unknown command error, which can be easily solved by installing karma command-line interface ( CLI )...

AngularJS E2E Testing with Protractor

In continuation to  AngularJS series , today we'll discuss e2e or end-to-end testing of AngularJS applications. If you've been following the blog for a while, you must have noticed my numerous stressing the importance of unit testing using Jasmine and Karma and automating JavaScript testing with Grunt.js . The only thing left behind was e2e testing, of which we would talk today using Protractor for AngularJS applications. What is E2E Testing? End-to-end testing is a methodology used to test, whether the flow of an application is performing as designed from start to finish. The purpose of carrying out end-to-end tests is to identify system dependencies and to ensure that the right information is passed between various system components and systems. In contrast to unit testing, which verifies the correct behaviour of various components separately, end-to-end testing verifies the entire flow of the application. From front end development perspective, it will be check...

D3 Data Visualization Library

Data visualization is the study of the visual representation of data, meaning "information that has been abstracted in some schematic form, including attributes or variables for the units of information". In the end everything we do, needs to be somehow presented to the users. Fortunately, we humans are intensely visual creatures. Few of us can detect patterns among rows of numbers, but even young children can interpret bar charts, extracting meaning from those numbers’ visual representations. For that reason, data visualization is a powerful exercise and is the fastest way to communicate it to others. What is D3? D3 is a JavaScript library, which helps in manipulating documents based on data. It uses HTML, SVG and CSS to create visualizations. With D3.js, the complete capabilities of new-age browsers can be used without being constrained to a framework. Fundamentally, D3 is an elegant piece of software that facilitates generation and manipulation of web documents ...

Bower and Require.js Integration

In the past we've talked about Bower package manager and God knows, I have been obsessively repeating myself about using Require.js  and it's integration with object oriented programming . So how do they integrate with each other? In this article we'll cover the integration of both and see how they get along together. Bower Initiation Let's start by defining, which packages we want to use in our project by filling the bower.json . You can create one yourself or run bower init command for interactive creation. { "name": "RequireJS Starter", "version": "1.0.0", "dependencies": { "jquery": "1.9", "underscore": null, "requirejs": null } } So we'll be needing jQuery, Underscore and of course Require.js. Putting null as a version number will download the latest version. Now run bower install to download all the packages into bo...

CSS and JavaScript Live Editing

Image
As planned we're continuing our tradition to present JavaScript Developer Toolkit. Last time we've talked about Emmet and today's article I'd like to devote to HTML/CSS/JavaScript editing. How often do you change your CSS rules and JavaScript within your browser? How often do copy/paste the changes made into appropriate resource files? It's time to do this Zen style. IDE integration This is my preferable way to develop and live-editing the changes. Let me show you why. Wouldn't it be cool if you could develop using your beloved IDE with all the neat plugins it offers and see the changes reflected live in the browser? Well - you can, with both Sublime Text and Webstorm we've talked about during our previous JavaScript toolkit article . You do this by installing JetBrains IDE Chrome  extension for Webstorm: or Emmet LiveStyle for Sumblime Text: Look into their sites and see how properly things should to be configured. Both tools only of...

What Is Bower And Why You Need It

So you've heard everyone talking about this mythical creature called Bower. But what exactly is it? Better to see once than to hear 100 times, so before we proceed any further take a peek at their  site . The problem Recall how you used to manage, and maybe still do, your 3rd party libraries. Firstly you went to their official site or maybe github repository. After finding the latest minified version, you would  get something like this - xxx-1.0.1.min.js, then  downloaded and saved it into your project. At last referencing it in the HTML would do the trick by copy pasting the script tag - <script src="//code.jquery.com/jquery-1.11.0.min.js">. But what would have happened if a new version came up? Well, if you were aware of the update, you would repeat the process again and put xxx-1.0.2.min.js in your library folder. Then you would change the reference in your HTMLs or JavaScript files. You could of course rename the file to xxx.js and omitting the version...