Skip to content

Commit

Permalink
fixup! feat(common): introduce KeyValuePipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Wiles committed Jun 7, 2018
1 parent 6e25cdb commit 65f8ff6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/pipes/index.ts
Expand Up @@ -14,10 +14,10 @@
import {AsyncPipe} from './async_pipe';
import {LowerCasePipe, TitleCasePipe, UpperCasePipe} from './case_conversion_pipes';
import {DatePipe} from './date_pipe';
import {KeyValue, KeyValuePipe} from './keyvalue_pipe';
import {I18nPluralPipe} from './i18n_plural_pipe';
import {I18nSelectPipe} from './i18n_select_pipe';
import {JsonPipe} from './json_pipe';
import {KeyValue, KeyValuePipe} from './keyvalue_pipe';
import {CurrencyPipe, DecimalPipe, PercentPipe} from './number_pipe';
import {SlicePipe} from './slice_pipe';

Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/pipes/keyvalue_pipe.ts
Expand Up @@ -8,7 +8,7 @@

import {KeyValueDiffer, KeyValueDiffers, Pipe, PipeTransform} from '@angular/core';

function makeKeyValuePair<V>(key: number|string, value: any): KeyValue<V> {
function makeKeyValuePair<V>(key: number | string, value: any): KeyValue<V> {
return {key: key as any, value};
}

Expand All @@ -23,7 +23,8 @@ export interface KeyValue<V> {
*
* Transforms Object or Map into an array of key value pairs.
*
* The output array will be ordered by the keys from the input and all keys will be converted to strings
* The output array will be ordered by the keys from the input and all keys will be converted to
* strings
*
*/
@Pipe({name: 'keyvalue', pure: false})
Expand Down
6 changes: 4 additions & 2 deletions packages/common/test/pipes/keyvalue_pipe_spec.ts
Expand Up @@ -48,7 +48,8 @@ import {SpyChangeDetectorRef} from '../spies';
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
const input = {2: 1, 1: 1, 'b': 1, 0: 1, 3: 1, 'a': 1};
expect(pipe.transform(input)).toEqual([
{key: '0', value: 1}, {key: '1', value: 1}, {key: '2', value: 1}, {key: '3', value: 1}, {key: 'a', value: 1}, {key: 'b', value: 1}
{key: '0', value: 1}, {key: '1', value: 1}, {key: '2', value: 1}, {key: '3', value: 1},
{key: 'a', value: 1}, {key: 'b', value: 1}
]);
});
it('should return the same ref if nothing changes', () => {
Expand Down Expand Up @@ -86,7 +87,8 @@ import {SpyChangeDetectorRef} from '../spies';
const pipe = new KeyValuePipe(defaultKeyValueDiffers);
const input = [[2, 1], [1, 1], ['b', 1], [0, 1], [3, 1], ['a', 1]];
expect(pipe.transform(new Map(input as any))).toEqual([
{key: '0', value: 1}, {key: '1', value: 1}, {key: '2', value: 1}, {key: '3', value: 1}, {key: 'a', value: 1}, {key: 'b', value: 1}
{key: '0', value: 1}, {key: '1', value: 1}, {key: '2', value: 1}, {key: '3', value: 1},
{key: 'a', value: 1}, {key: 'b', value: 1}
]);
});
it('should return the same ref if nothing changes', () => {
Expand Down
6 changes: 3 additions & 3 deletions tools/public_api_guard/common/common.d.ts
Expand Up @@ -175,8 +175,8 @@ export declare class JsonPipe implements PipeTransform {
transform(value: any): string;
}

export interface KeyValue<K, V> {
key: K;
export interface KeyValue<V> {
key: string;
value: V;
}

Expand All @@ -185,7 +185,7 @@ export declare class KeyValuePipe<K, V> implements PipeTransform {
transform(input: null | {
[key: string]: V;
[key: number]: V;
} | Map<K, V>): Array<KeyValue<string, V>> | null;
} | Map<K, V>): Array<KeyValue<V>> | null;
}

export declare class Location {
Expand Down

0 comments on commit 65f8ff6

Please sign in to comment.