npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

revuest

v1.1.5

Published

Reactive Vue Storage

Downloads

19

Readme

Revuest

Revuest stands for Reactive Vue Storage. It provides reactive access to browser's storage objects (sessionStorage and localStorage).

Quickstart

Installation
$ npm install revuest
Basic Usage
// main.js

import Vue from "vue";
import App from "App.vue";
import revuest from "revuest";

Vue.use(revuest);

new Vue({
    el: "#app",
    render: h => h(App)
});
<!-- App.vue -->

<template>
    <div>
        <h1>{{ localStorage.message }}</h1>
    </div>
</template>

How it Works

Revuest uses Vue.mixin method to inject four properties to every instance of Vue: the localStorage and sessionStorage, that are used for accessing the stored key-value pairs, and the $localStorage and $sessionStorage, that exposes wrappers to the browser's native storage objects functions get, set, delete, clear and other functions.

As long as the key-value pairs exist on the browser storage, they can be accessed from within templates like any other properties.

The plugin also uses the Vue.watch function and the browser's native storage event to make the localStorage and sessionStorage objects reactive, which means that when the value is changed in one side, the data will be reflected on the other side.

That means it can be used inside inputs and other html elements like bellow:

<template>
    <div>
        <input type="text" v-model="localStorage.message" />
    </div>
</template>

But note that due to Vue.watch limitation to watch for new properties, the code above only works if the data is already set on the storage before the Vue instance get created.

In order to solve that, use the beforeCreate hook to initialize the storage like the example bellow:

<script>
export default {
    beforeCreate() {
        this.$localStorage.$default({
            message: "my message"
        });
    }
}
</script>

By doing so, the default values will be saved to the browser storage before Revuest initialization. Revuest uses the Object.assign function to merge the defaults with the storaged data so that any existing values do not be overwritten.

SSR - Server Side Rendering

Starting on version 1.1.0, revuest works fine with SSR.

$localStorage.$default() and $sessionStorage.$default() functions must be used to initialize the data, otherwise an empty object will be assigned to the localStorage and sessionStorage objects. The data can be referenced on the template the same way as in the client side rendering.

Note: By the time that the client side takes over, the default values will be reevaluated and if the data stored on the browser is different from the default values used by the server, localStorage and sessionStorage objects will be automatically updated to reflect the browser values, the same way it happens when $default() is used directly on the client side. If the data does not exist on the browser storage it will be automatically saved to storage at this time.

License

MIT