This is part of GoCloudStorage and not part of the main GoJS library. Storage can be found in the GoJS kit under the `projects` folder. See the Storage intro page for more information.

### Hierarchy

- GoCloudStorage
  - GoLocalStorage

Class for saving / loading GoJS Models to / from Local Storage. GoLocalStorage is the only GoCloudStorage subclass than can be used in a local page; that is, one not served by a web server.

Note: This class will not work with browsers that do not have Local Storage support (like some old versions of Internet Explorer).

## Index

### Constructors

- constructor

### Properties

- localStorage

### Methods

- authorize
- checkFileExists
- getFile
- load
- loadWithUI
- remove
- removeWithUI
- save
- saveWithUI
- showUI

## Inherited Members

### Properties

- GoCloudStorage.className
- GoCloudStorage.clientId
- GoCloudStorage.currentDiagramFile
- GoCloudStorage.defaultModel
- GoCloudStorage.iconsRelativeDirectory
- GoCloudStorage.isAutoSaving
- GoCloudStorage.managedDiagrams
- GoCloudStorage.serviceName
- GoCloudStorage.ui

### Methods

- GoCloudStorage.create
- GoCloudStorage.getUserInfo
- GoCloudStorage.hideUI

## Constructors

### constructor

- new GoLocalStorage(managedDiagrams: Diagram | Diagram[], defaultModel?: string, iconsRelativeDirectory?: string): GoLocalStorage

- #### Parameters

  - ##### managedDiagrams: Diagram | Diagram[]

    An array of GoJS Diagrams whose model(s) will be saved to / loaded from Local Storage. Can also be a single Diagram.

  - ##### Optional defaultModel: string

    String representation of the default model data for new diagrams. If this is null, default new diagrams will be empty. Usually a value given by calling Model.toJson on a GoJS Diagram's Model.

  - ##### Optional iconsRelativeDirectory: string

    The directory path relative to the page in which this instance of GoLocalStorage exists, in which the storage service brand icons can be found. The default value is "../goCloudStorageIcons/".

  #### Returns GoLocalStorage

## Properties

### Read-only localStorage: Storage

- Get the browser window's Local Storage property.

## Methods

### Override authorize

- authorize(refreshToken?: boolean): Promise<any>

- Check if Local Storage is supported by the current browser.

  #### Parameters

  - ##### refreshToken: boolean = false

    This parameter can be ignored. It exists only to maintain GoCloudStorage system structure

  #### Returns Promise<any>

  Returns a Promise that resolves with a boolean (true if local storage is supported, false if not)

### Override checkFileExists

- checkFileExists(path: string): Promise<unknown>

- Check whether a file exists in Local Storage at a given path.

  #### Parameters

  - ##### path: string

    A valid key corresponding to a saved diagram file in Local Storage

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a boolean stating whether a file exists in LocalStorage at a given path

### Override getFile

- getFile(path: string): Promise<unknown>

- Get information about a diagram file saved to Local Storage. This data includes:

  - content: The content of the saved file (a string respresentation of a GoJS Diagram Model)
  - id: The key of the file in local storage
  - name: Same as id value
  - path: Same as id value

  Note: Id, name, and path are all provided (despite being the same). They are required for creating valid DiagramFiles.

  #### Parameters

  - ##### path: string

    A valid key corresponding to a saved diagram file in Local Storage

  #### Returns Promise<unknown>

  Returns a Promise that resolves with information about a diagram file saved to local storage

### Override load

- load(path: string): Promise<unknown>

- Get the contents of a given file; load to managedDiagrams model.

  #### Parameters

  - ##### path: string

    A valid localstorage key to load diagram model data from

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### Override loadWithUI

- loadWithUI(): Promise<unknown>

- Get the contents of a given file; load to managedDiagrams model. Use the custom filepicker ui.

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the loaded file

### Override remove

- remove(path: string): Promise<unknown>

- Delete a given diagram from Local Storage.

  #### Parameters

  - ##### path: string

    A valid localstorage key to delete diagram model data from

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### Override removeWithUI

- removeWithUI(): Promise<unknown>

- Delete a diagram from Local Storage using the custom filepicker menu ui.

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the deleted file

### Override save

- save(path?: string): Promise<unknown>

- Save managedDiagrams' model data to Local Storage. If path is supplied save to that path. If no path is supplied but currentDiagramFile has non-null, valid properties, update saved diagram file content at the key in Local Storage corresponding to currentDiagramFile.path with current managedDiagrams' model data. If no path is supplied and currentDiagramFile is null or has null properties, this calls saveWithUI.

  #### Parameters

  - ##### Optional path: string

    A string to save diagram model data to (becomes the key for the file in Local Storage)

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### Override saveWithUI

- saveWithUI(): Promise<unknown>

- Save the current managedDiagrams's model data to Local Storage using the custom filepicker ui.

  #### Returns Promise<unknown>

  Returns a Promise that resolves with a DiagramFile representing the saved file

### Override showUI

- showUI(action: string, numAdditionalFiles?: number): any

- Show the custom Go Local Storage filepicker ui.

  #### Parameters

  - ##### action: string

    Clarify what action is being done after file selection. Must be one of the following:

    - New
    - Open
    - Save
    - Delete

  - ##### Optional numAdditionalFiles: number

    Optional: Number of files to show in UI, in addition to a static numerical property (that can only be modified by changing source code). This prevents long wait times while the UI loads if there are a large number of diagram files stored in Local Storage.

  #### Returns any

  Returns a Promise that resolves (in save, load, or remove with an DiagramFile representing the saved/loaded/deleted file

Copyright © 1998-2022 by Northwoods Software Corporation.