Working around Edge not having array.flatMap()

This commit is contained in:
Przemek Wiech
2019-03-07 23:35:09 +01:00
parent b54073fbee
commit 2c030ec970
2 changed files with 8 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
"version": "1.0.0", "version": "1.0.0",
"main": "src/index.tsx", "main": "src/index.tsx",
"dependencies": { "dependencies": {
"array.prototype.flatmap": "^1.2.1",
"canvas-toBlob": "^1.0.0", "canvas-toBlob": "^1.0.0",
"d3": "^5.7.0", "d3": "^5.7.0",
"detect-browser": "^4.1.0", "detect-browser": "^4.1.0",
@@ -21,6 +22,7 @@
"topola": "^2.2.2" "topola": "^2.2.2"
}, },
"devDependencies": { "devDependencies": {
"@types/array.prototype.flatmap": "^1.2.0",
"@types/d3": "^5.5.0", "@types/d3": "^5.5.0",
"@types/file-saver": "^2.0.0", "@types/file-saver": "^2.0.0",
"@types/history": "^4.7.2", "@types/history": "^4.7.2",

View File

@@ -2,6 +2,7 @@ import * as React from 'react';
import {GedcomData} from './gedcom_util'; import {GedcomData} from './gedcom_util';
import {GedcomEntry} from 'parse-gedcom'; import {GedcomEntry} from 'parse-gedcom';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import flatMap from 'array.prototype.flatmap';
interface Props { interface Props {
gedcom: GedcomData; gedcom: GedcomData;
@@ -114,12 +115,11 @@ function getDetails(
tags: string[], tags: string[],
detailsFunction: (entry: GedcomEntry, tag: string) => JSX.Element | null, detailsFunction: (entry: GedcomEntry, tag: string) => JSX.Element | null,
): JSX.Element[] { ): JSX.Element[] {
return tags return flatMap(tags, (tag) =>
.flatMap((tag) => entries
entries .filter((entry) => entry.tag === tag)
.filter((entry) => entry.tag === tag) .map((entry) => detailsFunction(entry, tag)),
.map((entry) => detailsFunction(entry, tag)), )
)
.filter((element) => element !== null) .filter((element) => element !== null)
.map((element) => <div className="ui segment">{element}</div>); .map((element) => <div className="ui segment">{element}</div>);
} }