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

RFC: grabItems (naming wanted) #24

@Kelin2025

Description

@Kelin2025

Case

Sometimes you need to gather data from multiple KVs based on one

Basically like JOIN from SQL

Solution

export const $txWidget = grabItems(Widget.model.$kv, {
  source: {
    deposit: Deposit.model.$kv,
    withdraw: Withdraw.model.$kv,
    earn: Earn.model.$kv,
  },
  filter: {
    deposit: (deposit, widget) => widget.txHashes.includes(deposit.tx_hash),
    withdraw: (deposit, widget) => widget.txHashes.includes(deposit.tx_hash),
    earn:(deposit, widget) => widget.txHashes.includes(deposit.tx_hash),
  },
  orderBy: (a, b, widgetState) => a.value.timestamp - b.value.timestamp
})

Returned store will have the following shape:

{
  [wigetId]: {
    item: Widget,
    children: { 
      type: 'deposit' | 'withdraw' | 'earn', 
      value: Deposit | Withdraw | Earn 
    }[]
  }
}

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions