Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/archakov06/smit

😎 Tiny library tracking changes in the LocalStorage
https://github.com/archakov06/smit

localstorage smit storage tiny tracking

Last synced: about 3 hours ago
JSON representation

😎 Tiny library tracking changes in the LocalStorage

Awesome Lists containing this project

README

        

# Smit

Is a tiny library 🔥~270 (gziped) byte localStorage emitter. Smit has no dependencies, supports all browsers and IE9+.

## Install

```
npm install smit
```

or

```
yarn add smit
```

If you are in a CommonJS environment (eg Node), then you will need to add .default to your import:

```js
// ES6
import smit from 'smit';

// CommonJS
var smit = require('smit').default;

// UMD

// Just one function (IIFE)

```

## Usage

```js
import smit from 'smit';

const storage = smit();

// Callback called when a key "title" is updated in localStorage
storage.on('title', title => console.log('title updated', title));

// Listen of many keys in localStorage
storage.on('foo', value => console.log('foo', value)).on('bar', value => console.log('bar', value));

// Remove listener
storage.off('foo');

// Remove all listeners
storage.off();

// destroy the smit
storage.destroy();
```

## Examples

If you want to check how this smit works, open any of the following demos in two tabs.

### Chat

**VanillaJS:** [Source](https://codesandbox.io/s/thirsty-gagarin-2dnp9) | [Demo](https://2dnp9.csb.app/)


**VueJS:** [Source](https://codesandbox.io/s/vue-template-f17f6) | [Demo](https://f17f6.csb.app/)


**ReactJS:** [Source](https://codesandbox.io/s/happy-mclean-umjel) | [Demo](https://umjel.csb.app/)

### Audio

**VanillaJS:** [Source](https://trycode.pw/c/J0ERM) | [Demo](https://trycode.pw/c/J0ERM.html)

## Motivation

...

## How it works?

...

## License

[MIT License](https://opensource.org/licenses/MIT) © [Archakov Dennis](https://archakov.im/about)