Skip to content

Commit

Permalink
🔬 #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Wilhite committed Jan 8, 2020
1 parent 1decab6 commit a099c01
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@
"script": "version:patch",
"problemMatcher": []
},
{
"label": "npx: jest [current open file]",
"type": "shell",
"command": "npx",
"args": [
"jest",
"${relativeFile}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": []
},
{
"label": "typedoc: generate docs",
"type": "shell",
Expand Down
3 changes: 2 additions & 1 deletion src/utilities/array.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class ArrayUtility {
i: number,
dataRef: any,
k: any = keyGetter(current)
) => ((accumulator[k] || (accumulator[k] = [])).push(current), accumulator), initialValue
) => ((accumulator[k] || (accumulator[k] = [])).push(current), accumulator),
initialValue
);
const groupByModels: ReducedGroup[] = [];

Expand Down
4 changes: 2 additions & 2 deletions src/utilities/display-item.utility.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import items from '../mocks/app-songhay-blog-q2-2018-items.json';
import { MenuDisplayItemModel } from '../models/menu-display-item.model';

import { DisplayItemUtility, DISPLAY_ITEM_GROUP_NONE } from './display-item.utility';
import { DISPLAY_ITEM_GROUP_NONE, DisplayItemUtility } from './display-item.utility';
import { MapObjectUtility } from './map-object.utility';

it('should group flat set for display [empty or null Selectable map pairs]', () => {
Expand Down Expand Up @@ -139,7 +139,7 @@ it('should get a mapped pair or return a default pair', () => {
);
});

fit('should sort fallback group to the end', () => {
it('should sort fallback group to the end', () => {

const mapForG1 = new Map<string, any>([['topic-one', 'First Topic'], ['group-one', 'Group One']]);
const mapForG2 = new Map<string, any>([['group-two', 'Group Two']]);
Expand Down
7 changes: 3 additions & 4 deletions src/utilities/display-item.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,8 @@ export class DisplayItemUtility {
throw new Error('The expected items are not here.');
}

DisplayItemUtility.setGrouping(items, groupId);

const grouped = ArrayUtility.groupBy(items, (i: MenuDisplayItemModel) => i.groupId);
const reduced = ReducedGroupUtility.reduceToObject<MenuDisplayItemModel>(grouped);
const groups = ArrayUtility.groupBy(items, (i: MenuDisplayItemModel) => i.groupId);
const reduced = ReducedGroupUtility.reduceToObject<MenuDisplayItemModel>(groups);

return reduced;
}
Expand Down Expand Up @@ -185,6 +183,7 @@ export class DisplayItemUtility {
.filter(i => i ? true : false)
.forEach(i => {
const pair = DisplayItemUtility.getItemMapPair(i, groupId);

if (!pair) {
if (!i.groupId || !i.displayText) { doGroupPairWarning(i); }
} else {
Expand Down
17 changes: 12 additions & 5 deletions src/utilities/reduced-group-utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,25 @@ export class ReducedGroupUtility {
*
*/
public static reduceToObject<T>(groups: ReducedGroup[]): { [key: string]: T[] } {
const keyGetter = (datum: ReducedGroup) => datum.key;
const keyGetter = (datum: {[key: string]: any}) => Object.getOwnPropertyNames(datum)[0];
const initialValue: { [key: string]: T[] } = {};
const reduction = groups.reduce(
const reduction = groups
.map(i => {
const o = {} as { [key: string]: T[] };
const k = i.key as string;
o[k] = i.values;
return o;
})
.reduce(
(
accumulator: { [key: string]: T[] },
current: ReducedGroup,
current: { [key: string]: T[] },
i: number,
dataRef: any,
k: any = keyGetter(current)
k: string = keyGetter(current)
) => ({...current, ...accumulator}),
initialValue
);
); console.log({reduction});

return reduction;
}
Expand Down

0 comments on commit a099c01

Please sign in to comment.