@jakguru/vueprint / @jakguru/vueprint/services/localStorage / LocalStorageService
Class: LocalStorageService
@jakguru/vueprint/services/localStorage.LocalStorageService
The Local Storage service is an SSR-Friendly service used to store information used by the application. It keeps all information encrypted using secure-ls as a driver, while ensuring that all components of the application and all instances of the application in the same browser are kept in sync.
Accessing the Local Storage Service
The Local Storage Service is both injectable and accessible from the global Vue
instance:
<script lang="ts">
import { defineComponent, inject } from 'vue'
import type { LocalStorageService } from '@jakguru/vueprint'
export default defineComponent({
setup() {
const ls = inject<LocalStorageService>('ls')
return {}
}
mounted() {
const ls: LocalStorageService = this.config.globalProperties.$ls
}
})
</script>
Constructors
constructor
• new LocalStorageService(namespace
): LocalStorageService
Create a new LocalStorage instance.
Parameters
Name | Type | Description |
---|---|---|
namespace | string | The namespace to use for the local storage. |
Returns
Defined in
src/services/localStorage.ts:60
Accessors
loaded
• get
loaded(): boolean
Whether or not the local storage has been loaded.
Returns
boolean
Defined in
src/services/localStorage.ts:122
promise
• get
promise(): Promise
<void
>
A promise which resolves when the local storage has been loaded.
Returns
Promise
<void
>
Defined in
src/services/localStorage.ts:129
value
• get
value(): Record
<string
, any
>
The current content of the local storage.
Returns
Record
<string
, any
>
Defined in
src/services/localStorage.ts:136
Methods
clear
▸ clear(): void
Clear the local storage.
Returns
void
Defined in
src/services/localStorage.ts:306
get
▸ get(key
): any
Get the value of a key in the local storage.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to fetch from the local storage. |
Returns
any
The value of the key in the local storage, if it exists
Defined in
src/services/localStorage.ts:199
getAllKeys
▸ getAllKeys(): string
[]
Get all of the keys in the local storage.
Returns
string
[]
An array of all of the keys in the local storage.
Defined in
src/services/localStorage.ts:222
getDataFromLocalStorage
▸ getDataFromLocalStorage(key
): null
| string
Get the value of a key in the local storage.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to fetch from the local storage. |
Returns
null
| string
The value of the key in the local storage, if it exists
Defined in
src/services/localStorage.ts:211
getEncryptionSecret
▸ getEncryptionSecret(): string
Get the encryption secret used by the local storage.
Returns
string
Defined in
src/services/localStorage.ts:185
merge
▸ merge(data
): void
Merge data into the local storage.
Parameters
Name | Type | Description |
---|---|---|
data | any | The data to merge into the local storage. |
Returns
void
Defined in
src/services/localStorage.ts:260
off
▸ off(event
, callback
): void
Remove a listener for an event on the local bus.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event name. |
callback | (...args : any []) => void | The callback function. |
Returns
void
Defined in
src/services/localStorage.ts:340
on
▸ on(event
, callback
): void
Add a listener for an event on the local bus.
Parameters
Name | Type | Description |
---|---|---|
event | string | The event name. |
callback | (...args : any []) => void | The callback function. |
Returns
void
Defined in
src/services/localStorage.ts:331
once
▸ once(event
, callback
): void
Add a listener for an event on the local bus one time
Parameters
Name | Type | Description |
---|---|---|
event | string | The event name. |
callback | (...args : any []) => void | The callback function. |
Returns
void
Defined in
src/services/localStorage.ts:349
refresh
▸ refresh(): void
Refresh the information in the service from the browser's local storage.
Returns
void
Defined in
src/services/localStorage.ts:165
remove
▸ remove(key
): void
Remove a key from the local storage.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to remove from the local storage. |
Returns
void
Defined in
src/services/localStorage.ts:284
removeAll
▸ removeAll(): void
Remove all keys from the local storage.
Returns
void
Defined in
src/services/localStorage.ts:295
resetAllKeys
▸ resetAllKeys(): []
Reset all keys in the local storage.
Returns
[]
Defined in
src/services/localStorage.ts:319
set
▸ set(key
, data
): void
Set the value of a key in the local storage.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to set in the local storage. |
data | any | The value to set for the key in the local storage. |
Returns
void
Defined in
src/services/localStorage.ts:234
setDataToLocalStorage
▸ setDataToLocalStorage(key
, data
): void
Set the value of a key in the local storage.
Parameters
Name | Type | Description |
---|---|---|
key | string | The key to set in the local storage. |
data | string | The value to set for the key in the local storage. |
Returns
void