Skip to content
This repository has been archived by the owner on Aug 9, 2024. It is now read-only.

RFC: joinLists #23

Open
Kelin2025 opened this issue Jul 7, 2023 · 4 comments
Open

RFC: joinLists #23

Kelin2025 opened this issue Jul 7, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Kelin2025
Copy link
Member

Case

Sometimes you need one-to-many connection between two KVs

For example, there's "Swaps" widgets and you need to gather swaps lists for each widget

Solution

Add joinLists method

const widgetSwaps = joinLists({
  kv: Widget.model.$kv,
  join: Swap.model.$kv,
  fn: (widget, swap) => widget.swapIds.includes(swap.id),
  orderBy: (a, b) => a.timestamp - b.timestamp
})
@Kelin2025 Kelin2025 added the enhancement New feature or request label Jul 7, 2023
@Kelin2025 Kelin2025 self-assigned this Jul 7, 2023
@Kelin2025
Copy link
Member Author

Kelin2025 commented Jul 7, 2023

Actually I think the naming of this one is incorrect but wonder what would be a better name

@Minhir
Copy link
Member

Minhir commented Jul 8, 2023

This could be solved by createMap/createSelection with source field and filter option (#17 (comment)). You can pass swapIds as source and use filter to check includes.
I think it looks more straightforward.

@Kelin2025
Copy link
Member Author

The idea of joinLists and grabItems methods is to provide a formalized way to join KVs without manually iterating through them
The problem with solving these cases through createMap/createSelection is that you'll pass other KVs as a source and handle joining inside fn, so your app

  • Will have knowledge about KV structure
  • And it's a lot of boilerplate code too

@Minhir
Copy link
Member

Minhir commented Jul 10, 2023

I agree that we need some utils which are working "key per key" like SQL joins does. I'm still not sure how to make it easier. We can start with current joinLists approach.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants