Options
All
  • Public
  • Public/Protected
  • All
Menu

A saver responsible for communicating with a server to save the data edited by a wed editor.

param

The runtime under which this saver is created.

param

The version of wed for which this object is created.

param

The updater that the editor created for its data tree.

param

The editor's data tree.

param

The options specific to this class.

Hierarchy

Index

Constructors

constructor

Properties

Protected _events

_events: Subject<SaveEvents>

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

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.

Private etag

etag: string | undefined

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.

Private headers

headers: Record<string, string>

Protected initialized

initialized: boolean = false

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

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.

Private url

url: string

Protected version

version: string

The version of wed for which this object is created.

Methods

Protected _fail

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

    Parameters

    Returns void

Private _post

  • Utility wrapper for Ajax queries. Read the code for more information.

    Parameters

    Returns Promise<Response>

    A promise that resolves when the post is over.

_recover

  • _recover(): Promise<boolean>

_save

  • _save(autosave: boolean): 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.

init

  • init(): Promise<void>

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