11 lines
489 B
TypeScript
11 lines
489 B
TypeScript
/** A captured pointer may only finish the exact interaction that acquired it. */
|
|
export type EditingLease<T> = { preview(value: T): void; commit(): void; cancel(): void };
|
|
|
|
export function guardEditingLease<T>(isCurrent: () => boolean, actions: EditingLease<T>): EditingLease<T> {
|
|
return Object.freeze({
|
|
preview(value: T) { if (isCurrent()) actions.preview(value); },
|
|
commit() { if (isCurrent()) actions.commit(); },
|
|
cancel() { if (isCurrent()) actions.cancel(); },
|
|
});
|
|
}
|