Class

StorageManager

StorageManager()

The StorageManager constructor. Initialises the storage namespace (key prefix) to relevant env parameters.

Checks for (in order):

  • env.REACT_APP_BASE_URL
  • env.REACT_APP_NAME
  • window.location.pathname

The storage manager builds a singleton instance, which is shared across the application. It can be imported and used as per the below example:

import { storage } from '@jcu/spark'

...

storage.saveData('important_info', 'This is an important message', {persist: true})
Constructor

# new StorageManager()

View Source services/StorageManager.ts, line 23

Classes

StorageManager

Methods

# deleteData(key)

Delete data from storage for a given key.

Checks session then local storage for a key, deletes the first one it finds.

Parameters:
Name Type Description
key string

The key you want to delete from storage

View Source services/StorageManager.ts, line 109

# loadData(key, options)

Load data from storage for a given key. The StorageManager internally handles adding an application specific prefix to the key provided to prevent possible overlap of data spaces for co-hosted applications.

There are currently no supported options for the loadData function.

Parameters:
Name Type Description
key string

The key you want to load from storage

options Object

Additional load options

View Source services/StorageManager.ts, line 129

# saveData(key, value, options) → {Object}

Save data to local or session storage depending on options provided. Contains a JSON.stringify call to allow the storage of more complex object data. If JSON.parse(JSON.stringify(<your object>)) works then it can be saved. The StorageManager internally handles adding an application specific prefix to the storage keys to prevent the possible overlap of data spaces for co-hosted applications.

The default behaviour of the save function is not persistent (session storage) and doesn't overwrite existing keys.

Parameters:
Name Type Description
key string

The key you want to save the data under

value *

The data you want to save

options Object

Additional save options

update boolean

Used to overwrite data if the provided key already exists

persist boolean

Used to determine if session or local storage is used. True is local (persistent)

View Source services/StorageManager.ts, line 55

An Object containing data defining the outcome of the save request

Object

# updateData(key, value, options)

A wrapper function for saveData where the update option is forced to true. Will overwrite existing keys or save the new key.

Parameters:
Name Type Description
key string

The key you want update or save new data too

value *

The data you want to save

options Object

Additional update options

persist boolean

Used to determine if session or local storage is used. True is local (persistent)

View Source services/StorageManager.ts, line 99