Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Saver

A saver is responsible for saving a document's data. This class cannot be instantiated as-is, but only through subclasses.

Hierarchy

Index

Constructors

constructor

  • Parameters

    • runtime: Runtime

      The runtime under which this saver is created.

    • version: string

      The version of wed for which this object is created.

    • dataUpdater: TreeUpdater

      The updater that the editor created for its data tree.

    • dataTree: Node

      The editor's data tree.

    • options: SaverOptions

    Returns Saver

Properties

Private _boundAutosave

_boundAutosave: Function

Protected _events

_events: Subject<SaveEvents>

The object on which this class and subclasses may push new events.

Private autosaveInterval

autosaveInterval: number = 0

The interval at which to autosave, in milliseconds.

Private autosaveTimeout

autosaveTimeout: number | undefined

The current timeout object which will trigger an autosave. It has the value undefined if there is no current timeout.

Protected currentGeneration

currentGeneration: number = 0

The generation that is currently being edited. It is mutable. Derived classes can read it but not modify it.

Protected dataTree

dataTree: Node

The editor's data tree.

Protected dataUpdater

dataUpdater: TreeUpdater

The updater that the editor created for its data tree.

events

events: Observable<SaveEvents>

The observable on which clients can listen for events.

Protected failed

failed: boolean = false

Subclasses must set this variable to true if the saver is in a failed state. Note that the "failed" state is for cases where it makes no sense to attempt a recovery operation.

One effect of being in a "failed" state is that the saver won't perform a recover operation if it is in a "failed" state.

Protected initialized

initialized: boolean = false

Subclasses must set this variable to true once they have finished with their initialization.

Private lastModification

lastModification: number | undefined

The date of last modification.

Private lastSave

lastSave: number | undefined

The date of last save.

Private lastSaveKind

lastSaveKind: SaveKind | undefined

The last kind of save.

Protected options

options: SaverOptions

Protected runtime

runtime: Runtime

The runtime under which this saver is created.

Protected savedGeneration

savedGeneration: number = 0

The generation that has last been saved. Derived classes can read it but not modify it.

Protected version

version: string

The version of wed for which this object is created.

Methods

Private _autosave

  • _autosave(): void
  • This is the function called internally when an autosave is needed.

    Returns void

Protected _fail

  • Must be called by derived classes when they fail to perform their task.

    Parameters

    Returns void

Protected Abstract _recover

  • _recover(): Promise<boolean>
  • This method is called when recovering. This is the method responsible for the implementation-specific details.

    Returns Promise<boolean>

    A promise that resolves to true if the recovery operation was successful, and false if not.

Protected Abstract _save

  • _save(autosave: boolean): Promise<void>
  • This method is called when saving or autosaving. This is the method responsible for the implementation-specific details.

    Parameters

    • autosave: boolean

      true if called by an autosave, false if not.

    Returns Promise<void>

Protected _saveSuccess

  • _saveSuccess(autosave: boolean, savingGeneration: number): void
  • Must be called by derived class upon a successful save.

    Parameters

    • autosave: boolean

      true if called for an autosave operation, false if not.

    • savingGeneration: number

      The generation being saved. It is necessary to pass this value due to the asynchronous nature of some saving operations.

    Returns void

getData

  • getData(): string
  • This method returns the data to be saved in a save operation. Derived classes must call this method rather than get the data directly from the data tree.

    Returns string

getLastSaveKind

  • getLastSaveKind(): number | undefined
  • Returns the last kind of save that occurred.

    Returns number | undefined

    The kind. The value will be undefined if there has not been any save yet.

getModifiedWhen

  • getModifiedWhen(): false | string
  • Returns information regarding whether the saver sees the data tree as having been modified since the last save occurred.

    Returns false | string

    false if the tree has not been modified. Otherwise, returns a string that describes how long ago the modification happened.

getSavedWhen

  • getSavedWhen(): undefined | string
  • Produces a string that indicates in human readable format when the last save occurred.

    Returns undefined | string

    The string. The value undefined is returned if no save has occurred yet.

Abstract init

  • init(): Promise<void>
  • This method must be called before using the saver. MUST BE CALLED ONLY ONCE.

    Returns Promise<void>

    A promise that is resolved when the saver is initialized.

recover

  • recover(): Promise<boolean | undefined>
  • This method is to be used by wed upon encountering a fatal error. It will attempt to record the last state of the data tree before wed dies.

    Returns Promise<boolean | undefined>

    A promise which resolves to undefined if the method did not do anything because the Saver object is in an unintialized state or has already failed. It resolves to true if the recovery operation was successful, and false if not.

save

  • save(): Promise<void>
  • This method must be called when the user manually initiates a save.

    Returns Promise<void>

    A promise which resolves if the save was successful.

setAutosaveInterval

  • setAutosaveInterval(interval: number): void
  • Changes the interval at which autosaves are performed. Note that calling this function will stop the current countdown and restart it from zero. If, for instance, the previous interval was 5 minutes, and 4 minutes had elapsed since the last save, the next autosave should happen one minute from now. However, if I now call this function with a new interval of 4 minutes, this will cause the next autosave to happen 4 minutes after the call, rather than one minute.

    Parameters

    • interval: number

      The interval between autosaves in milliseconds. 0 turns off autosaves.

    Returns void

Generated using TypeDoc