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

RFC: $kv.setItemField('someField', params => value) #22

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

RFC: $kv.setItemField('someField', params => value) #22

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

Comments

@Kelin2025
Copy link
Member

Kelin2025 commented Jul 7, 2023

Case

There's a $kv.setItemField('someField') which puts event payload to someField
But sometimes you need to set specific value (or calculate it)
There's a mapItem((item, payload) => ...) but it updates a whole shape, so you have to return an object

Solution

Add optional callback to $kv.setItemField that defines what value to put

const metaItemApi = createItemApi({
  kv: $kv,
  events: {
    expand: $metaKv.setItemField('expanded', () => true),
    collapse: $metaKv.setItemField('expanded', () => false),
    toggle: $metaKv.setItemField('expanded', (item) => !item.expanded)
  }
})

metaItemApi.expand will set to true, collapse to false and toggle will change the value based on item

@Kelin2025 Kelin2025 added the enhancement New feature or request label Jul 7, 2023
@Kelin2025 Kelin2025 self-assigned this Jul 7, 2023
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

1 participant