TanStack / TanStack/db

Add a way to enforce collection mutations via actions disallowing inline mutations

Open
#996 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
TypeScript
Stars
3.9k
Forks
266
Avg merge
1d 4h
Merged PRs (30d)
55

Description

It would be great if we had a way to enforce only being able to use mutations like someCollection.insert inside of actions.

e.g.

This is allowed

const addTodo = createOptimisticAction<string>({
  onMutate: (text) => {
    todoCollection.insert({
      id: uuid(),
      text,
      completed: false
    })
  },
 ....
})

This should be forbidden

<Button onClick={() =>     
todoCollection.insert({
      id: uuid(),
      text,
      completed: false
    })}>
</Button
Why

The more I have used Tanstack DB the more I have realized almost all mutations I do have some sort of side effects, making single mutations quite useless. I started only using optimistic actions but coding agents and teammates often fall into the trap on using inline muations again. a way to enforce to enforce mutations through actions would be great

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the collection mutation APIs and optimistic action APIs referenced in the examples to understand where inline mutations and action mutations are distinguished. Done means there is an enforceable way to reject collection mutations outside actions while preserving mutations inside actions; the issue names no files or tests to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.