apiref
stack-local-storage@0.2.0

ExclusiveStackLocalStorage  Class

Like a StackLocalStorage, but only allows one store to be set at a time.

Signature

export declare class ExclusiveStackLocalStorage<T> 

Example

const store = new ExclusiveStackLocalStorage({
  emptyErrorMessage: 'Store is empty',
  conflictErrorMessage: 'Store is already set'
})
store.run(1, () => {
  console.log(store.getStore()) // 1
  store.run(2, () => { ... }) // throws 'Store is already set'
})
console.log(store.getStore()) // throws 'Store is empty'

Constructors

ConstructorDescription
(constructor)(options)Creates a new ExclusiveStackLocalStorage.

Methods

MethodDescription
getStore()Returns the current store.
run(store, f, args)Runs a function with a given store.