ciplogic.com
Live with grace. Write superb software.

typescript

  • core-lang: Better Collection Classes for JavaScript

    It brings me great joy to announce the release of version 1.0.0 of core-lang, the collection classes I wrote for JavaScript.

    Overview

    With an API that is fully compatible with the JavaScript API, keeping the same signatures and behaviors for functions such as forEach, etc, but also inspired from groovy, having methods such as groupBy, chaining support, and full Promise support, allowing to deal with collections that contain promises, or are transformed to promises, using simple chainable calls.

  • core-promise and core-lang Promise ES6 TypeScript API updates

    core-promise

    After a bit of fiddling around I managed to convince the core-promise implementation to actually implement the Promise interface from the ES6 typescript definitions itself:

    /**
     * Represents the completion of an asynchronous operation
     */
    interface Promise<T> {
        /**
        * Attaches callbacks for the resolution and/or rejection of the Promise.
        * @param onfulfilled The callback to execute when the Promise is resolved.
        * @param onrejected The callback to execute when the Promise is rejected.
        * @returns A Promise for the completion of which ever callback is executed.
        */
        then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => TResult | PromiseLike<TResult>)" Promise<TResult>;
        then<TResult>(onfulfilled?: (value: T) => TResult | PromiseLike<TResult>, onrejected?: (reason: any) => void): Promise<TResult>; 
        /**
         * Attaches a callback for only the rejection of the Promise.
         * @param onrejected The callback to execute when the Promise is rejected.
         * @returns A Promise for the completion of the callback.
         */
        catch(onrejected?: (reason: any) => T | PromiseLike<T>): Promise<T>;
        catch(onrejected?: (reason: any) => void): Promise<T>;
        [Symbol.toStringTag]: string;
    }

    Thus not only you have now all the test guarantees, you also get the API guarantees. Neat!

  • TypeScript unit testing with Mocha

    I am writing some unit tests for my TypeScript collection classes (actually migrating some older tests), and I decided in going with Mocha.

    How easy it is? Well, as simple as 1, 2, 3... 4 :) :

    1. Install the typing files

    tsd install mocha
    tsd install node
    tsd install assert

    2. Write your test(s)

    For this example, I'm presenting you a super simple test, but obviously nothing stops you from adding new ones (check my github core-lang project for details):

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    /// <reference path="../../../typings/mocha/mocha.d.ts"/>
    /// <reference path="../../../typings/node/node.d.ts"/>
    /// <reference path="../../../typings/assert/assert.d.ts"/>
     
    import { list, XIterable, XIterator } from "../../main/core/Iterable";
    import assert = require("assert");
     
    describe('ArrayList', function() {
        it('should allow filtering', function() {
            var items : XIterable<number> = list([1, 2, 3, 4]),
                filteredItems: XIterable<number>,
                iterator : XIterator<number>;
     
            filteredItems = items.filter(it => it % 2 == 0);
            iterator = filteredItems.iterator();
            
            assert.equal(iterator.next(), 2);
            assert.equal(iterator.next(), 4);
            assert.notEqual(iterator.hasNext(), true);
        });
    });

    3. Build your test(s)

    I use Grunt, so I have (I deleted all the non test stuff), but is basically easy to see the target that is named "test" across all the plugins in the original full Grunt file:

Germanium

The one to rule them all. The browsers that is.

SharpKnight

SharpKnight is an Android chess game.

MagicGroup

MagicGroup is an eclipse plugin.