Skip to content

Feature request: onBeforeChange hook to intercept and optionally reject writes #633

@AleksY1991

Description

@AleksY1991

Problem:

Building apps with confirmation dialogs for destructive operations (bulk delete, mass updates). Currently:

  1. Change happens → onChange fires
  2. Show confirmation dialog
  3. If rejected → manually rollback to previous state

This is fragile because:

  • Other listeners already reacted to the change
  • Computed values recalculated unnecessarily
  • UI flickers (change → rollback)
  • Race conditions if user makes another change during dialog

Use case:
// User selects 50 nodes and clicks "Delete"
// Want to: intercept → show "Delete 50 nodes?" → allow/reject

Proposed solution:
store$.nodes.onBeforeChange(async ({ changes, value, prev }) => {
if (changes.length > 5) {
const confirmed = await showConfirmDialog(Update ${changes.length} items?);
if (!confirmed) {
return false; // Reject - change doesn't happen
}
}
return true; // Allow
});

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