Options
All
  • Public
  • Public/Protected
  • All
Menu

Defines a saver that uses IndexedDB to save documents.

This saver stores the document as a "file" into an IndexedDB instance. The objects are not really files but similar to files. Henceforth, the name "file" will be used without quotes to refer to the objects stored.

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

  • 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: Options

      The options specific to this class.

    Returns Saver

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.

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 initPromise

initPromise: Promise<void> = Promise.resolve()

Protected initialized

initialized: boolean = false

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

Private name

name: string

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 store

store: Store

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

_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

_update

  • _update(name: string, data: string, autosave: boolean, savingGeneration: number): Promise<void>
  • Parameters

    • name: string
    • data: string
    • autosave: boolean
    • savingGeneration: number

    Returns Promise<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