npm.io
3.0.0 • Published 2 years ago

sham-ui-data-storage

Licence
MIT
Version
3.0.0
Deps
1
Size
23 kB
Vulns
1
Weekly
0

sham-ui-data-storage

Build Status npm version MIT Licence

Data storage for sham-ui

Install

# npm
npm install -D sham-ui-data-storage
# yarn
yarn add sham-ui-data-storage --dev

API

Table of Contents
StorageGetter

Getter for storage

Type: Function

Parameters

Returns Storage

CreateStorageOptions

Options for createStorage

Type: Object

Properties
  • DI string Registry storage in DI with this key. By default use storage:<random key> as key.
  • LIFO boolean Use LIFO (last input first output) for storage subscribers. By default false
  • sync boolean Disable async run watchers callback. Callbacks will run only after call sync storage method. By default false
createStorage

Create a new unique storage object for current DI.

Parameters
Examples
import createStorage from 'sham-ui-data-storage';
export const { storage, useStorage } = createStorage( {
   name: '',
   email: '',
   sessionValidated: false,
   isAuthenticated: false
}, { DI: 'session:storage' } );

Returns {storage: StorageGetter, useStorage: (function ())}

storage

Return storage for DI container

Parameters

Returns Storage

useStorage

Decorator for component

Parameters
  • storageAlias string Name of classProperty for access to storage fields
Examples
<template>
  <span class="logged-name">
    {{sessionData.name}}
  </span>
</template>

<script>
  import { useStorage } from '../../../storages/session';

  function Profile {

  }

  export default Component( Template, useStorage( ref( 'sessionData' ) ), Profile );
</script>

Returns Function

Storage

Type: Object

addWatcher

Add watcher for field

Parameters
removeWatcher

Remove watcher for field

Parameters
reset

Remove all watchers & reset storage field to default values

sync

Run all deferred subscribers immediate