From 6d740ceb677a1adf06adc7c53c11beb5c6aeaad1 Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 4 Dec 2013 11:28:29 +0000 Subject: [PATCH 1/2] knockout.projections: Created typings and tests --- .../knockout.projections-tests.ts | 30 +++++++++++++++++++ .../knockout.projections.d.ts | 11 +++++++ 2 files changed, 41 insertions(+) create mode 100644 knockout.projections/knockout.projections-tests.ts create mode 100644 knockout.projections/knockout.projections.d.ts diff --git a/knockout.projections/knockout.projections-tests.ts b/knockout.projections/knockout.projections-tests.ts new file mode 100644 index 000000000..6940a4989 --- /dev/null +++ b/knockout.projections/knockout.projections-tests.ts @@ -0,0 +1,30 @@ +// Type definitions for knockout-projections 1.0.0 +// Project: https://github.com/stevesanderson/knockout-projections +// Definitions by: John Reilly + +/// +/// + +// Test map +var sourceItems = ko.observableArray([1, 2, 3, 4, 5]); +var squares = sourceItems.map(function (x) { return x * x; }); +var squaresAsStrings = sourceItems.map(function (x) { return (x * x).toString(); }); + +sourceItems.push(6); +// 'squares' has automatically updated and now contains [1, 4, 9, 16, 25, 36] +// 'squaresAsStrings' has automatically updated and now contains ['1', '4', '9', '16', '25', '36'] + +sourceItems.reverse(); +// 'squares' now contains [36, 25, 16, 9, 4, 1] +// 'squaresAsStrings' now contains ['36', '25', '16', '9', '4', '1'] + +// Test Filtering + +var evenSquares = squares.filter(function (x) { return x % 2 === 0; }); +// evenSquares is now an observable containing [36, 16, 4] + +sourceItems.push(9); +// This has no effect on evenSquares, because 9*9=81 is odd + +sourceItems.push(10); +// evenSquares now contains [36, 16, 4, 100] diff --git a/knockout.projections/knockout.projections.d.ts b/knockout.projections/knockout.projections.d.ts new file mode 100644 index 000000000..5e85308a9 --- /dev/null +++ b/knockout.projections/knockout.projections.d.ts @@ -0,0 +1,11 @@ +// Type definitions for knockout-projections 1.0.0 +// Project: https://github.com/stevesanderson/knockout-projections +// Definitions by: John Reilly + +/// + +interface KnockoutObservableArrayFunctions { + + map(mapping: (value: T) => TResult): KnockoutObservableArray; + filter(predicate: (value: T) => boolean): KnockoutObservableArray; +} From a20e5adf6a09bf7551b56e2202d6bae112373d1a Mon Sep 17 00:00:00 2001 From: John Reilly Date: Wed, 4 Dec 2013 11:35:18 +0000 Subject: [PATCH 2/2] knockout.projections: corrected header --- knockout.projections/knockout.projections-tests.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/knockout.projections/knockout.projections-tests.ts b/knockout.projections/knockout.projections-tests.ts index 6940a4989..3d479e7ac 100644 --- a/knockout.projections/knockout.projections-tests.ts +++ b/knockout.projections/knockout.projections-tests.ts @@ -1,6 +1,4 @@ -// Type definitions for knockout-projections 1.0.0 -// Project: https://github.com/stevesanderson/knockout-projections -// Definitions by: John Reilly +// Tests for knockout.projections.d.ts /// ///