StoreBeforeChangeHandler

See source code

Handler function called before a record is updated in the store. The handler receives the current and new versions of the record and can return a modified version or the original to prevent the change.

type StoreBeforeChangeHandler<R extends UnknownRecord> = (
  prev: R,
  next: R,
  source: 'remote' | 'user'
) => R

Example

const handler: StoreBeforeChangeHandler<ShapeRecord> = (prev, next, source) => {
  // Prevent shapes from being moved outside the canvas bounds
  if (next.x < 0 || next.y < 0) {
    return prev // Block the change
  }
  return next
}

Parameters

NameDescription

prev

The current version of the record in the store

next

The proposed new version of the record

source

Whether the change originated from 'user' interaction or 'remote' synchronization

Prev
StoreAfterDeleteHandler
Next
StoreBeforeCreateHandler