Skip to content

Feature Request: Standalone rxMutation Function #220

@rainerhahnekamp

Description

@rainerhahnekamp

Create a standalone version of rxMutation that can be used independently of SignalStore and contains the full mutation feature with RxJS-support.

Background

Currently, rxMutation is designed to work within the SignalStore context as part of the withMutations feature. While this works well for SignalStore-based applications, there's a need for a standalone version that can be used in various contexts without requiring the full SignalStore setup.

API Design Considerations

Based on internal discussions, several API design questions need to be addressed:

1. Implementation Details

Question: Why expose callCount in Mutation? This seems like an implementation detail.

Proposal: Make callCount internal or provide it only when explicitly requested.

2. Helper Functions

Proposal: Add convenient helper functions:

export interface RxMutation<Input, Value> {
  (input: Input): Promise<MutationResult<Value>>;
  value: Signal<Value | undefined>;
  error: Signal<unknown>;
  status: Signal<MutationStatus>;
  
  // Proposed helpers
  isPending(): boolean;
  isFulfilled(): boolean;
  hasValue(): boolean;
}

3. Value Access

Question: How to access current value from outside?

Solution: Ensure the value signal is available.

4. Simplified Overload

Proposal: Add overload that only requires the operation:

// Instead of
const mutation = rxMutation({
  executor: (id: string) => httpClient.delete(`/user/${id}`)
});

// Allow
const mutation = rxMutation((id: string) => httpClient.delete(`/user/${id}`));

This feature was discussed in #203

"TODO: Generally speaking, once we make rxMutation standalone, most tests of rxMutation will cover already what we have here."

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions