Add support for mappingOptions in knockout.projections

Added support for new features introduced in knockout-projections,
mappingOptions parameters with either a mapping/disposeItem pair or a
single mappingWithDisposeCallback function which produces a
mappedItem/dispose pair.
This commit is contained in:
Thomas Michon
2015-03-30 19:14:40 -07:00
parent 02a93db66a
commit c124eaac95
2 changed files with 40 additions and 2 deletions

View File

@@ -26,3 +26,31 @@ sourceItems.push(9);
sourceItems.push(10);
// evenSquares now contains [36, 16, 4, 100]
// Testing mapping options
interface IComplexItem {
value: string;
dispose(): void;
}
var complexItems = sourceItems.map({
mapping: x => {
var item: IComplexItem = {
value: (x * x).toString(),
dispose: () => { }
};
return item;
},
disposeItem: (item: IComplexItem) => item.dispose()
});
var complexItems2 = sourceItems.map({
mappingWithDisposeCallback: x => {
return {
mappedValue: (x * x).toString(),
dispose: () => { }
};
}
});

View File

@@ -6,7 +6,17 @@
/// <reference path="../knockout/knockout.d.ts" />
interface KnockoutObservableArrayFunctions<T> {
map<TResult>(mapping: (value: T) => TResult): KnockoutObservableArray<TResult>;
map<TResult>(mappingOptions: {
mappingWithDisposeCallback: (value: T) => {
mappedValue: TResult;
dispose: () => void;
};
}): KnockoutObservableArray<TResult>;
map<TResult>(mappingOptions: {
mapping: (value: T) => TResult;
disposeItem?: (mappedItem: TResult) => void;
}): KnockoutObservableArray<TResult>;
map<TResult>(mappingOptions: (value: T) => TResult): KnockoutObservableArray<TResult>;
filter(predicate: (value: T) => boolean): KnockoutObservableArray<T>;
}