Giter Site home page Giter Site logo

vue-reactive-storage's Introduction

vue-reactive-storage

Reactive layer for interacting with localStorage from Vue. Plugin for Vue 2.

install

npm install --save https://github.com/ropbla9/vue-reactive-storage

  • This package is not on NPM, use GitHub source only.

why

window.localStorage cannot be reactive if you use it directly with Vue, ex

new Vue({
    data {
      localStorage: window.localStorage
    },
    template: " <div> {{localStorage.notes}}, {{localStorage.lang}} ... </div> ",
    created: function() {
        this.localStorage.lang = "other value";
    }
})

Code above will not react, even bind to view. So...

how to use

import reactiveStorage from "vue-reactive-storage";
// Set initial values
Vue.use(reactiveStorage, {
    "notes": 'foo',
    "lang": 'foo',
    "name": 'foo',
    "count": 1,
    "userConfig": {age: 10, name: 'fred'}
});

Define vars that will be stored and proxied by Vue (any other var in window.localStorage that is not on this array will not be proxied).

Now you can acess the namespace localStorage in Vue.

new Vue({
    template: " <div> {{localStorage.notes}}, {{localStorage.lang}} ... </div> ",
    created: function() {
        this.localStorage.lang = "other value"; // will react on the view and on real localStorage.
    }
})

vue-reactive-storage's People

Contributors

ropbla9 avatar vinicius73 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

vue-reactive-storage's Issues

swap store for store2

Hi @ropbla9 can this be extended to swap store for store2 which is a more advanced local / session storage api. It should also be possible to add values to localstorage without having to list the variables in the array and still have them reactive just like observables? I am looking to try something like that, will do a PR if it works

Uglify Error

i get this warning when i try to "npm run build" in my "vue-cli pwa template" app.

ERROR in static/js/vendor.e94132c75cc782c7d66d.js from UglifyJs
Unexpected token name «key», expected punc «;» [./~/vue-reactivestorage/index.js:15,0][static/js/vendor.e94132c75cc782c7d66d.js:56346,21]

I know this is somehow connected to to limitations of Uglify.

But maybe somebody can help on that?

Distribute production builds or not at all

This npm package's main file is defined to be dist/index.js, which is generated by webpack in development mode.

Run webpack with -p or set "mode": "production" in the config.

Or just set main in package.json to be src/index.js instead, and let the webpack of the users of the package build it.

Vuex

How do you use this inside Vuex or Middleware ?

Unexpected let

Hi, there's a single let statement in the code that trips up uglify-js when I try to compile a project in webpack. It means I have to add a specific rule to test for this file and run babel on it in order for it to work.
Could the module be made ES5-compliant please?

Release 1.3.1

Hi!
Has the current master been released to npmjs? Npmjs states version 1.3.0, while master package.json states 1.3.1.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.