sham-ui-data-storage
v3.0.0
Published
Data storage for sham-ui
Downloads
76
Readme
sham-ui-data-storage
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
DI
Object
Returns Storage
CreateStorageOptions
Options for createStorage
Type: Object
Properties
DI
string Registry storage in DI with this key. By default usestorage:<random key>
as key.LIFO
boolean Use LIFO (last input first output) for storage subscribers. By default falsesync
boolean Disable async run watchers callback. Callbacks will run only after callsync
storage method. By default false
createStorage
Create a new unique storage object for current DI.
Parameters
fieldsWithDefault
Object Fields of storageoptions
CreateStorageOptions? Extra options for storage (optional, default{}
)
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
DI
Object App DI container
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