Tuesday, February 19, 2013

Declaration source files and google analytics

What is Declaration source files?

Declaration source files are restricted to contain declarations only. Declaration source files can be used to declare the static type information associated with existing JavaScript and expose their behavior.

I have started to implement TypeScript in my projects at work :-)

In that case I had to implement google analytics but ran into the problem, that I did not have intellisence for the that.

I googled a bit and could not find any declaration file for that, so I made my own.
I can now acces ga, _gaq, _gat and the Tracker object with intellicense in my TypeScript file, nice...

Example

describe("tester Google Analytics Code  _gaq object", () => {
    it("can create _push", () => {
        _gaq.push(['_setAccount', 'UA-XXXXXXX-YY']);
        _gaq.push(['_gat._anonymizeIp']);
        _gaq.push(['_trackPageview']);

        _gaq.push(() => {
                var tracker = _gat._getTrackerByName('UA-65432-1');
                tracker._trackPageview();
            }
        );
    });  
});

I have pushed it to https://github.com/borisyankov/DefinitelyTyped but until it is merged you can get the files here https://github.com/RonnieHegelund/DefinitelyTyped/tree/master/google.analytics



Sunday, February 17, 2013

TeaCrunch - CodeCoverage for Typescript

When working in .NET and writing unit test, I really like the green dots NCrunch gives me. I think its a great way to show what code you have test coverage on.

I would love to have this in TypeScript to, but haven't found any, so I have started making a prove of concept my self.



The prove of concept works, but is very unstable and have to rewrite the code, and need to find out how I can read the results from the test explorer. The biggest problem is to find the time to rewrite my code :-)

Saturday, February 16, 2013

TypeScript - The rest parameter

Rest parameter in TypeScript has nothing todo with REST (REpresentational State Transfer)

If you are familiar with C# params keyword, The rest parameter is the same. The rest parameter lets you specify a function parameter that takes an argument where the number of arguments is variable.

An example could be a function that make a Sum of a variable length of numbers:


Sum(1,2,3,4);

C# example

public int Sum(params int[] list)
{
  int sum = 0;
  foreach (int i in list)
    sum += i;
  return sum;
}
TypeScript example

public Sum(...list Number[]) : number
{
    return list.reduce( 
        (a,b) => { a + b }
    );
}
And the result when compiled to JavaScript

function sum() {
    var numbers = [];
    for (var _i = 0; _i < (arguments.length - 0); _i++) {
        numbers[_i] = arguments[_i + 0];
    }
    return numbers.reduce(function (a, b) {
        return a + b;
    });
}


Wednesday, February 13, 2013

Update to the book content has changed a bit


Update to the book content has changed a bit.

Introduction to enterprise design
    What is enterprise design?
        Design priciples
            Reliability
            Sepreation Of Concern
            Flexibility
            Maintainablitiy
            Reuseablity
            S.O.L.I.D
                Single responsibility principle
                Open/closed principle
                Liskov substitution principle
                Interface segregation principle
                Dependency inversion principle
        Design patterns
            Working with design patterns
            The benefits of patterns
            Antipatterns

The road to enterprise 
    Testing strategies.
        Unit tests
        Components Tests
        Integrations tests
        System tests
        Manual tests
    Acceptance test
    Test driven development     
        What is TDD
        TDD Kata as an example
    Testing frameworks
        jasmineJS
        QUnit
        Selenium - automated browser tests
    Continous Integration
        Teamcity
            Setting up automated tests
            Setting up automated deployment
        Continous Delivery

Design patterns in action
    View patterns
        MVVM
            Knockout as an example
        MVC
            Backbone as an example

TypeScript Fundamentals
    What is TypeScript
    TypeScript keywords
    Types
        Primitive Types
            The String type
            The Number type
            The Boolean type
            The Null type
            The Undefefined type
    Interfaces
    Classes
    Functions
        Functions arguments
        Arrow Functions
        Extension methods
            What is code smell?
    Inheritance
    Modules
    Generics (not supported yet) .
    Declaration Source Files

TypeScript Tools
    Visual Studio
    Web Essentials
    Sublime text