Filter items in a normalized array
janhesters opened this issue · comments
Jan Hesters commented
match-sorter
version: 2.3.0node
version: v9.4.0npm
(oryarn
) version: 6.4.1
Relevant code or config
const adults = [
{ name: "Jim", house: "house-uuid-one", children: ["children-uuid-one", children-uuid-two"], uuid: "adult-uuid" },
{ name: "Yin", house: "house-uuid-two", children: [], uuid: "adult-uuid-two" }
];
const normalizedHouses = {
"house-uuid-one": { address: "Some Street", uuid: "house-uuid-one" },
"hourse-uuid-two": { address: "Simba Ave", uuid: "house-uuid-two"
};
const normalizedChildren = { "children-uuid-one": { age: 2, name: "John", uuid: "children-uuid-one" }, "children-uuid-two": { age: 8, name: "Jenna", uuid: "children-uuid-two" } };
What you did:
I would like to use match sorter with normalized arrays.
What happened:
I couldn't figure out how to use matchSorter with normalized arrays.
Problem description:
I tried it like this:
matchSorter(adults, "o", {
keys: [
"name",
item => normalizedHouses[item.house].name,
item => item.children.map(child => normalizedChildren[child]).name
]
})
Suggested solution:
Let the array be transformed:
matchSorter(items, "o", { keys: ["name", "house", "children"], trafo: .map(<someTransformation>) })
So that the initial array stays the same, but the trafo gets applied during the filtering.
Kent C. Dodds commented
Sorry, I'm not 100% certain I understand the need, and I'm guessing this is no longer needed as it's been a long time 😬 Sorry!