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: $kv.setItemField('someField', params => value) #22

@Kelin2025

Description

@Kelin2025

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

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