# sham-ui-data-storage

> Data storage for sham-ui

Latest version **3.0.0** (published 2023-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install sham-ui-data-storage
pnpm add sham-ui-data-storage
yarn add sham-ui-data-storage
bun add sham-ui-data-storage
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2023-11-10 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 23.1 KB |
| Known vulnerabilities | 0 (+4 in 1 direct dependencies) |
| Install scripts | no |
| Author | Eugeny Burnashov |
| Maintainers | shamcode |

## Links

- npm: https://www.npmjs.com/package/sham-ui-data-storage
- npm.io page: https://npm.io/package/sham-ui-data-storage

## Dependencies (1)

- [nanoid](https://npm.io/package/nanoid.md) ^1.3.1

## Recent versions

- 3.0.0 (latest) — 2023-11-10
- 3.0.0-alpha.7 — 2023-10-19
- 3.0.0-alpha.6 — 2023-09-26
- 3.0.0-alpha.5 — 2022-12-08
- 3.0.0-alpha.4 — 2022-10-20
- 3.0.0-alpha.3 — 2022-10-05
- 3.0.0-alpha.2 — 2022-09-13
- 3.0.0-alpha.1 — 2022-09-07
- 2.0.0 — 2022-08-05
- 2.0.0-alpha.11 — 2021-11-24
- 2.0.0-alpha.10 — 2021-11-04
- 2.0.0-alpha.9 — 2021-09-03
- 2.0.0-alpha.8 — 2021-07-08
- 2.0.0-alpha.7 — 2021-07-02
- 2.0.0-alpha.6 — 2021-06-25
- … 17 more at https://npm.io/package/sham-ui-data-storage/versions

## README

# sham-ui-data-storage

[![Build Status](https://travis-ci.com/sham-ui/sham-ui-data-storage.svg?branch=master)](https://travis-ci.com/sham-ui/sham-ui-data-storage)
[![npm version](https://badge.fury.io/js/sham-ui-data-storage.svg)](https://badge.fury.io/js/sham-ui-data-storage)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php)

 Data storage for sham-ui

## Install

```bash
# npm
npm install -D sham-ui-data-storage
```

```bash
# yarn
yarn add sham-ui-data-storage --dev
```

## API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

#### Table of Contents

-   [StorageGetter](#storagegetter)
    -   [Parameters](#parameters)
-   [CreateStorageOptions](#createstorageoptions)
    -   [Properties](#properties)
-   [createStorage](#createstorage)
    -   [Parameters](#parameters-1)
    -   [Examples](#examples)
-   [storage](#storage)
    -   [Parameters](#parameters-2)
-   [useStorage](#usestorage)
    -   [Parameters](#parameters-3)
    -   [Examples](#examples-1)
-   [Storage](#storage-1)
    -   [addWatcher](#addwatcher)
        -   [Parameters](#parameters-4)
    -   [removeWatcher](#removewatcher)
        -   [Parameters](#parameters-5)
    -   [reset](#reset)
    -   [sync](#sync)

### StorageGetter

Getter for storage

Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)

#### Parameters

-   `DI` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** 

Returns **[Storage](#storage)** 

### CreateStorageOptions

Options for `createStorage`

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### Properties

-   `DI` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Registry storage in DI with this key. By default use `storage:<random key>` as key.
-   `LIFO` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Use LIFO (last input first output) for storage subscribers. By default false
-   `sync` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/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

-   `fieldsWithDefault` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Fields of storage
-   `options` **[CreateStorageOptions](#createstorageoptions)?** Extra options for storage (optional, default `{}`)

#### Examples

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

Returns **{storage: [StorageGetter](#storagegetter), useStorage: (function ())}** 

### storage

Return storage for DI container

#### Parameters

-   `DI` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** App DI container

Returns **[Storage](#storage)** 

### useStorage

Decorator for component

#### Parameters

-   `storageAlias` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of classProperty for access to storage fields

#### Examples

```javascript
<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](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** 

### Storage

Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)

#### addWatcher

Add watcher for field

##### Parameters

-   `field` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of field
-   `cb` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Callback

#### removeWatcher

Remove watcher for field

##### Parameters

-   `field` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of field
-   `cb` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Callback

#### reset

Remove all watchers & reset storage field to default values

#### sync

Run all deferred subscribers immediate

---
_Source: https://npm.io/package/sham-ui-data-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
