Skip to content

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

@Makisuo

Description

@Makisuo

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions