All Projects → dreambo8563 → vue-storage-watcher

dreambo8563 / vue-storage-watcher

Licence: MIT license
a reactive storage plugin for vue 👀🔭

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to vue-storage-watcher

Awesome Web Storage
😎 Everything you need to know about Client-side Storage.
Stars: ✭ 227 (+278.33%)
Mutual labels:  localstorage, sessionstorage
mst-persist
Persist and hydrate MobX-state-tree stores (in < 100 LoC)
Stars: ✭ 75 (+25%)
Mutual labels:  localstorage, sessionstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (+10%)
Mutual labels:  localstorage, sessionstorage
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (-73.33%)
Mutual labels:  localstorage, sessionstorage
Ngx Store
Angular decorators to automagically keep variables in HTML5 LocalStorage, SessionStorage, cookies; injectable services for managing and listening to data changes and a bit more.
Stars: ✭ 152 (+153.33%)
Mutual labels:  localstorage, sessionstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-83.33%)
Mutual labels:  localstorage, sessionstorage
Vue Mail List
vue全家桶+localStorage实现一个简易的通讯录
Stars: ✭ 81 (+35%)
Mutual labels:  localstorage, sessionstorage
Angular Locker
🗄️ A simple & configurable abstraction for local/session storage in angular js projects
Stars: ✭ 318 (+430%)
Mutual labels:  localstorage, sessionstorage
React Storage Hooks
React hooks for persistent state
Stars: ✭ 146 (+143.33%)
Mutual labels:  localstorage, sessionstorage
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+2643.33%)
Mutual labels:  localstorage, sessionstorage
Web Storage Cache
对localStorage 和sessionStorage 进行了扩展,添加了超时时间,序列化方法
Stars: ✭ 582 (+870%)
Mutual labels:  localstorage, sessionstorage
Brownies
🍫 Tastier cookies, local, session, and db storage in a tiny package. Includes subscribe() events for changes.
Stars: ✭ 2,386 (+3876.67%)
Mutual labels:  localstorage, sessionstorage
Vue Ls
💥 Vue plugin for work with local storage, session storage and memory storage from Vue context
Stars: ✭ 468 (+680%)
Mutual labels:  localstorage, sessionstorage
cache-bucket
Light Cache for nodeJs and browserJs with TTL.
Stars: ✭ 14 (-76.67%)
Mutual labels:  localstorage, sessionstorage
Ng2 Webstorage
Localstorage and sessionstorage manager - Angular service
Stars: ✭ 395 (+558.33%)
Mutual labels:  localstorage, sessionstorage
Bin
A tiny (<1kb) localStorage and sessionStorage helper library.
Stars: ✭ 70 (+16.67%)
Mutual labels:  localstorage, sessionstorage
svelte-persistent-store
A Svelte store that keep its value through pages and reloads
Stars: ✭ 111 (+85%)
Mutual labels:  localstorage, sessionstorage
Immortaldb
🔩 A relentless key-value store for the browser.
Stars: ✭ 2,962 (+4836.67%)
Mutual labels:  localstorage, sessionstorage
Nuxt Storage
🛢 Utilities for easy read and write browser's storage in Nuxt.js project
Stars: ✭ 98 (+63.33%)
Mutual labels:  localstorage, sessionstorage
React Local Storage
Showcase on how to use the native localStorage of the browser in React.
Stars: ✭ 168 (+180%)
Mutual labels:  localstorage, sessionstorage

Codacy Badge All Contributors Build Status Greenkeeper badge License: MIT Known Vulnerabilities FOSSA Status npm type definitions npm

vue-storage-watcher

For Vue3 => https://github.com/dreambo8563/next-vue-storage-watcher

the real reactive watcher for localStorge. I search a few days for a lib to watch the ls, but failed.

you can use this tiny ls wrapper which works well with vue.js.

you can use this as persistent data layer even instead of vuex.

  • familiar usage just like bus.
  • reactive
  • type supported
  • small size

TODO:

  • support sessionStorage
  • logo design
  • ttl method like redis to get remaining lifetime in ms
  • show usage with github pages maybe

Install

npm install vue-storage-watcher --save

Sample

import lsWatcher from 'vue-storage-watcher';

Vue.use(lsWatcher, { prefix: 'myproject_' });

storage type

  • localStorage
  • sessionStorage

Options

  • prefix => default is ""
  • storage => default is "local" which means window.localStorage will be used as Storage Object. Another alternative is "session"

Methods

this.$ls or this.$ss in Component context for localStorage/sessionStorage Vue.$ls or Vue.$ss in global.

I will list basic api just with ls.

set

this.$ls.set('token', 'abccc');

the value will be saved in storage with the prefix + key and emit the changes to all the subscribers.

you also can give the key an expire duration with the unit of ms

this.$ls.set('token', 'abccc', 3000);

the key will be expried in 3s, you will get null after that.

ttl

ttl will return -1 if one of the following scenarios happen:

  • the key is non-exist
  • the key is already expired
  • the key has no expire time

else return the remaining lifetime with ms as the unit

this.$ls.ttl('token');

get

this.$ls.get('token', 'default');

get the value with a default return value if it's not existed

keys

this.$ls.keys();

get all keys stored in the storage.

subscribe the key

this.$ls.on('token', callback);

subscribe the key in the storage, will trigger the callback function if any changes happen.

the return value is the handler need to be used to unsubscribe

tricky there is an immediate options as a third args which will trigger cb immediate if set true

this.$ls.on('token', callback, true);

unsubscribe the key

const handler = this.$ls.on('token', cb);
this.$ls.off('token', handler);

please make sure you unsubscribe beforeDestroy the component

remove

this.$ls.remove('token');

remove will delete the key in storage and emit all the subscribers with null value

clear

this.$ls.clear();

delete all the keys with your prefix. and all the subscribers will not receive changes any more

init

this.$ls.init();

init will set all your current localStorge keys into the plugins

  • add prefix for all the keys

and then you can use get and on mehtod to make them reactive

FAQ

  • if you want to using localStorage and sessionStorage at same page, pls use the plugin as following
import lsWatcher from 'vue-storage-watcher';

Vue.use({ ...lsWatcher }, { prefix: 'myproject_' });

Vue.use({ ...lsWatcher }, { prefix: 'myproject_ss_', storage: 'session' });
  • possibly polyfill
// wather polyfill for IE 11
import 'core-js/fn/symbol';
import 'core-js/fn/map';
  • possibly polyfill
// wather polyfill for IE 11
import "core-js/fn/symbol"
import "core-js/fn/map"

License

FOSSA Status

Contributors

Thanks goes to these wonderful people (emoji key):

Vincent Guo
Vincent Guo

💻 📖 🐛

This project follows the all-contributors specification. Contributions of any kind welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].