All Projects → spatie → Vue Save State

spatie / Vue Save State

Licence: mit
A Vue mixin to save the state of a component to local storage

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vue Save State

Modernavplayer
ModernAVPlayer is a persistence AVPlayer wrapper
Stars: ✭ 179 (-26.34%)
Mutual labels:  state-machine
Store.js
Cross-browser storage for all use cases, used across the web.
Stars: ✭ 13,656 (+5519.75%)
Mutual labels:  localstorage
Angular Cached Resource
An AngularJS module to interact with RESTful resources, even when browser is offline
Stars: ✭ 218 (-10.29%)
Mutual labels:  localstorage
Python Statemachine
Python Finite State Machines made easy.
Stars: ✭ 184 (-24.28%)
Mutual labels:  state-machine
Liquidstate
Efficient asynchronous and synchronous state machines for .NET
Stars: ✭ 197 (-18.93%)
Mutual labels:  state-machine
Reactiveautomaton
🤖 ReactiveCocoa + State Machine, inspired by Redux and Elm.
Stars: ✭ 205 (-15.64%)
Mutual labels:  state-machine
Rosmaro
Visual automata-based programming in functional JavaScript
Stars: ✭ 176 (-27.57%)
Mutual labels:  state-machine
Canvas Sketch
App to sketch out a business model canvas
Stars: ✭ 232 (-4.53%)
Mutual labels:  localstorage
Timelite
Why is it 5 AM? Isn't there something simple I can use to track what I'm doing with all this time?
Stars: ✭ 201 (-17.28%)
Mutual labels:  localstorage
Laravel State Machine
Winzou State Machine service provider for Laravel
Stars: ✭ 213 (-12.35%)
Mutual labels:  state-machine
Awesome Fsm
🤖 A curated list of awesome resources related to finite state machines and statecharts.
Stars: ✭ 189 (-22.22%)
Mutual labels:  state-machine
Aws Lambda Power Tuning
AWS Lambda Power Tuning is an open-source tool that can help you visualize and fine-tune the memory/power configuration of Lambda functions. It runs in your own AWS account - powered by AWS Step Functions - and it supports three optimization strategies: cost, speed, and balanced.
Stars: ✭ 3,040 (+1151.03%)
Mutual labels:  state-machine
Flutter localstorage
📦flutter localstorage for ios/android/desktop/web
Stars: ✭ 206 (-15.23%)
Mutual labels:  localstorage
Remotestorage.js
⬡ JavaScript client library for integrating remoteStorage in apps
Stars: ✭ 2,155 (+786.83%)
Mutual labels:  localstorage
Use Machine
React Hook for using Statecharts powered by XState. use-machine.
Stars: ✭ 226 (-7%)
Mutual labels:  state-machine
State Machine Component
⚙️ State machine -powered components in 250 bytes
Stars: ✭ 178 (-26.75%)
Mutual labels:  state-machine
Ui Router
The de-facto solution to flexible routing with nested views in AngularJS
Stars: ✭ 13,738 (+5553.5%)
Mutual labels:  state-machine
Vuex Along
📝 A plugins to auto save and restore state for vuex
Stars: ✭ 239 (-1.65%)
Mutual labels:  localstorage
Awesome Web Storage
😎 Everything you need to know about Client-side Storage.
Stars: ✭ 227 (-6.58%)
Mutual labels:  localstorage
Brownies
🍫 Tastier cookies, local, session, and db storage in a tiny package. Includes subscribe() events for changes.
Stars: ✭ 2,386 (+881.89%)
Mutual labels:  localstorage

A Vue mixin to save the state of a component to local storage

Latest Version on NPM Software License Build Status npm

This package provides a SaveState mixin that automatically saves any change in the state of your component to localStorage. The next time that component gets initialized it will restore its state from the saved values in local storage.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment we highly apprecatie you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

All postcards are published on our website.

Install

You can install the package via yarn:

yarn add vue-save-state

or npm

npm install vue-save-state

Usage

In order to save the state of your component you'll need to add the SaveState mixin:

import saveState from 'vue-save-state';

export default {

    mixins: [saveState],

    ...
}

Next you'll need to add a method called getSaveStateConfig:

import saveState from 'vue-save-state';

export default {

    mixins: [saveState],
    
    // ...

    methods: {

        getSaveStateConfig() {
            return {
                'cacheKey': 'nameOfYourComponent',
            };
        },
    },
}

With these steps done any change to the state of your component will get written to local storage. The value given in cacheKey determines to which key in local storage the state of this component will get written. When the component is created it'll restore its state from local storage.

Only save certain properties of the state

There's also a configuration option to determine which properties of the state should be saved/restored:

import saveState from 'vue-save-state';

export default {
    
    // ...

    methods: {

        getSaveStateConfig() {
            return {
                'cacheKey': 'nameOfYourComponent',
                'saveProperties': ['title', 'text'],
            };
        },
    },
}

With this configuration only the title and text properties of your state will get saved/restored.

Alternatively you could specify which fields to ignore:

import saveState from 'vue-save-state';

export default {

    // ...

    methods: {

        getSaveStateConfig() {
            return {
                'cacheKey': 'nameOfYourComponent',
                'ignoreProperties': ['title'],
            };
        },
    },
}

In this scenario all fields except for the title property in your state will get saved/restored.

Transforming the state on load

If you want to transform the values stored in local storage before loading the into the state of the component add an onLoad function to the object return by getSaveStateConfig.

import saveState from 'vue-save-state';

export default {

    // ...

    methods: {

        getSaveStateConfig() {
            return {
                'onLoad': (key, value) => {
                    //return a new value
                },
            };
        },
    },
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ npm run test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please contact Freek Van der Herten instead of using the issue tracker.

Credits

About Spatie

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

The MIT License (MIT). Please see License File for more information.

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].