Skip to main content

ChangeRecorder

Records changes to a object which can later be reversed.

Index

Constructors

constructor

Methods

publiconRestore

  • onRestore<O>(o: O, onRestore: (obj: O) => void): void
  • Register callback, for o, which will be invoked when restoreAll is called. Useful when a more complex state needs to be restored when restoreAll is called. The callback is then responsible for modifying o when restoreAll is called.


    Type parameters

    • O: unknown

    Parameters

    • o: O

      Object to register callback for.

    • onRestore: (obj: O) => void

      callback.

    Returns void

publicrestoreAll

  • restoreAll(): void
  • Reverts all changes made to the objects.


    Returns void

publicsave

  • save<O, P>(obj: O, prop: P): void
  • Save a property prop on obj. This value will be restored when restoreAll is called later.


    Type parameters

    • O: unknown
    • P: string | number | symbol

    Parameters

    • obj: O
    • prop: P

    Returns void

publicset

  • set<O, P, V>(obj: O, prop: P, newValue: V): void
  • Set a property prop on obj to newValue. This can later be reversed by calling restoreAll.


    Type parameters

    • O: unknown
    • P: string | number | symbol
    • V

    Parameters

    • obj: O

      Object to set property on.

    • prop: P

      Property to set

    • newValue: V

      New value which obj[prop] will get.

    Returns void