Skip to content
Snippets Groups Projects
Commit e59fe444 authored by David Bühler's avatar David Bühler
Browse files

[dome] Moves mergeArrays utilitary functions into arrays.ts.

parent 66ed528d
No related branches found
No related tags found
No related merge requests found
...@@ -109,22 +109,4 @@ export function styles( ...@@ -109,22 +109,4 @@ export function styles(
return (empty ? undefined : buffer); return (empty ? undefined : buffer);
} }
export type Indexed = { key: unknown; }
export function mergeArrays<A, B>(
a1: A[],
a2: B[],
match: (x1: A, x2: B) => boolean): (A | (A & B))[] {
return a1.map(x1 => ({...x1, ...(a2.find(x2 => match(x1, x2)))}));
}
export function mergeArraysByKey<A, B>(
a1: (A & Indexed)[],
a2: (B & Indexed)[]
): (A | A & B)[] {
return mergeArrays(a1, a2, (x1, x2) => x1.key === x2.key);
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
...@@ -43,3 +43,24 @@ export function removeAt<A>(ls: A[], k: number): A[] { ...@@ -43,3 +43,24 @@ export function removeAt<A>(ls: A[], k: number): A[] {
export function insertAt<A>(ls: A[], id: A, k: number): A[] { export function insertAt<A>(ls: A[], id: A, k: number): A[] {
return 0 <= k && k <= ls.length ? ls.slice(0, k).concat(id, ls.slice(k)) : ls; return 0 <= k && k <= ls.length ? ls.slice(0, k).concat(id, ls.slice(k)) : ls;
} }
export type Indexed = { key: unknown; }
/** Merges elements of the second array into matching elements of the first.
The length and order of the first array is preserved. Elements of the second
array matching no element of the first are ignored. */
export function mergeArrays<A, B>(
a1: A[],
a2: B[],
match: (x1: A, x2: B) => boolean): (A | (A & B))[] {
return a1.map(x1 => ({...x1, ...(a2.find(x2 => match(x1, x2)))}));
}
/** Same as mergeArrays, using the `key` field to match between array items. */
export function mergeArraysByKey<A, B>(
a1: (A & Indexed)[],
a2: (B & Indexed)[]
): (A | A & B)[] {
return mergeArrays(a1, a2, (x1, x2) => x1.key === x2.key);
}
...@@ -28,7 +28,6 @@ import _ from 'lodash'; ...@@ -28,7 +28,6 @@ import _ from 'lodash';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import * as Dome from 'dome'; import * as Dome from 'dome';
import * as Json from 'dome/data/json'; import * as Json from 'dome/data/json';
import * as Utils from 'dome/misc/utils';
import * as States from 'frama-c/states'; import * as States from 'frama-c/states';
import * as Compare from 'dome/data/compare'; import * as Compare from 'dome/data/compare';
import * as Settings from 'dome/data/settings'; import * as Settings from 'dome/data/settings';
...@@ -37,6 +36,7 @@ import { Icon } from 'dome/controls/icons'; ...@@ -37,6 +36,7 @@ import { Icon } from 'dome/controls/icons';
import { IconButton, Checkbox } from 'dome/controls/buttons'; import { IconButton, Checkbox } from 'dome/controls/buttons';
import * as Models from 'dome/table/models'; import * as Models from 'dome/table/models';
import * as Arrays from 'dome/table/arrays'; import * as Arrays from 'dome/table/arrays';
import * as ArrayUtils from 'dome/data/arrays';
import { Table, Column, ColumnProps, Renderer } from 'dome/table/views'; import { Table, Column, ColumnProps, Renderer } from 'dome/table/views';
import { TitleBar } from 'ivette'; import { TitleBar } from 'ivette';
import { Scroll, Folder } from 'dome/layout/boxes'; import { Scroll, Folder } from 'dome/layout/boxes';
...@@ -616,7 +616,7 @@ export default function RenderProperties(): JSX.Element { ...@@ -616,7 +616,7 @@ export default function RenderProperties(): JSX.Element {
useEffect(() => { useEffect(() => {
model.removeAllData(); model.removeAllData();
const data = Utils.mergeArraysByKey(kernelData, evaData); const data = ArrayUtils.mergeArraysByKey(kernelData, evaData);
model.updateData(data); model.updateData(data);
model.reload(); model.reload();
}, [model, kernelData, evaData]); }, [model, kernelData, evaData]);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment