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

gosyl-vuex-multi-tab-state

v1.0.17

Published

Share and synchronize status between multiple tabs with this plugin for Vuex.

Downloads

8

Readme

vuex-multi-tab-state

Tests npm codecov codebeat badge npm npm bundle size npm type definitions code style: prettier demo

This Vuex plugin allows you to sync and share the status of your Vue application across multiple tabs or windows using the local storage.

This repository has a gitter chat where you can ask questions and propose new features:

Gitter

Vue 3 and Vuex 4 compatibility :warning:

The plugin has been tested with Vue 3 and Vuex 4 and no problems have been found. There is an issue where you can find how the plugin has been used using the new Vue 3 Composition API. If you encounter a problem using the plugin with Vue 3 and Vuex 4, please post it there.

Installation

vuex-multi-tab-state is available in npm and can be installed with the following command:

npm i vuex-multi-tab-state

Usage

Just import vuex-multi-tab-state and add it in the plugins list of your Vuex Store object.

import Vue from 'vue';
import Vuex from 'vuex';
import createMultiTabState from 'vuex-multi-tab-state';

Vue.use(Vuex);

export default new Vuex.Store({
  state: { ... },
  mutations: { ... },
  actions: { ... },
  getters: { ... },
  plugins: [
    createMultiTabState(),
  ],
});

You can check the example provided here

NuxtJS

Integrating the plugin in NuxtJS requires a little more effort than in Vue. First of all, we have to create a file inside the plugins directory.

// ~/plugins/multiTabState.client.js
import createMultiTabState from 'vuex-multi-tab-state';

export default ({ store }) => {
  createMultiTabState()(store);
};

Note that the filename must have the following format *.client.js. The next step is to add this plugin to NuxtJS in nuxt.config.js:

// nuxt.config.js
export default {
  ...
  plugins: [{ src: '~/plugins/multiTabState.client.js' }],
  ...
}

If you didn't name the file according to the specified format, you can add the plugin this way:

// nuxt.config.js
export default {
  ...
  plugins: [{ src: '~/plugins/multiTabState.client.js', mode: 'client' }],
  ...
}

Both ways tell NuxtJS that the plugin should only be run client-side (because the plugin uses window, not available server-side).

API

createMultiTabState({options})

Creates a new instance of the plugin with the given options. The possible options are as follows:

  • statesPaths Array<String>: contains the name of the states to be synchronized with dot notation. If the param is not provided, the whole state of your app will be sync. Defaults to [].

    Example: Only the oranges will be synchronized.

    export default new Vuex.Store({
      state: {
        fruits: {
          oranges: 0,
          apples: 0,
        },
      },
      plugins: [createMultiTabState({
        statesPaths: ['fruits.oranges'],
      })],
    });
  • key? <String>: key of the local storage in which the state will be stored. Defaults to 'vuex-multi-tab'.

  • storageType <String>: 'sessionStorage' or 'localStorage'. Defaults to 'localStorage'

  • onBeforeReplace? <Function>: hook function that receives the state and allows to modify it before replacing it. The function can return either a modified state or a falsy value (which means that no modifications has been done inside the hook).

  • onBeforeSave? <Function>: hook function that receives the state and allows to modify it before saving it in local storage. The function can return either a modified state or a falsy value (which means that no modifications has been done inside the hook).

    export default new Vuex.Store({
      state: {
        fruits: {
          oranges: 0,
          apples: 0,
        },
      },
      plugins: [createMultiTabState({
        storageType: 'sessionStorage',
        statesPaths: ['fruits.oranges'],
        onBeforeSave: (state) => {
          // Modify state here
          return state;
        },
        onBeforeReplace: (state) => {
          // Modify state here
          return state;
        }
      })],
    });

Test

The tests have been written with mocha and chai.

npm install
npm run test

Collaborate

npm collaborators

If you feel that something can be improved, go on, create a pull request! Please follow the programming style and document your changes correctly.

License

NPM

This project is under the MIT license. More information here.