All Projects → xanf → Vuex Shared Mutations

xanf / Vuex Shared Mutations

Licence: mit
Share vuex mutations between tabs/windows

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Vuex Shared Mutations

Vue Project
基于vue-cli构建的财务后台管理系统(vue2+vuex+axios+vue-router+element-ui+echarts+websocket+vue-i18n)
Stars: ✭ 301 (-43.42%)
Mutual labels:  vuex, vuejs2
Vue Spotify
Spotify client built with vue.js / vuex
Stars: ✭ 407 (-23.5%)
Mutual labels:  vuex, vuejs2
Vue Kindergarten
Modular security for Vue, Vuex, Vue-Router and Nuxt
Stars: ✭ 303 (-43.05%)
Mutual labels:  vuex, vuejs2
Paascloud Mall Web
模拟商城,完整的购物流程、后端运营平台,使用 spring cloud + vue 全家桶实现快速搭建企业级微服务项目
Stars: ✭ 287 (-46.05%)
Mutual labels:  vuex, vuejs2
Vue Socket.io Extended
✌️⚡️ Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
Stars: ✭ 506 (-4.89%)
Mutual labels:  vuex, vuejs2
Roastandbrew
Updated content available! We learned a lot since we originally wrote this article. We now have this updated for Laravel 8, Vue, and NuxtJS 👉 https://srvrsi.de/book
Stars: ✭ 300 (-43.61%)
Mutual labels:  vuex, vuejs2
Vue Acl
Access Control List plugin for VueJS 2.0
Stars: ✭ 376 (-29.32%)
Mutual labels:  vuex, vuejs2
Copilot
Responsive Bootstrap 3 Admin Template based on AdminLTE with vue.js
Stars: ✭ 2,698 (+407.14%)
Mutual labels:  vuex, vuejs2
Douban
Douban book website demo by server side render
Stars: ✭ 468 (-12.03%)
Mutual labels:  vuex, vuejs2
Vue Boilerplate Template
🍎 Efficient development of web SPA using Vue.js(2.*) + Webpack + Element-ui + Pwa + Vuex + Vuex-router + Vue-i18n + Dayjs + Lodash.
Stars: ✭ 461 (-13.35%)
Mutual labels:  vuex, vuejs2
Vue Home
🏠 A simple project(Vue Community SPA) which bases on vue+vue-cli+vue-router+axios+ scss.
Stars: ✭ 256 (-51.88%)
Mutual labels:  vuex, vuejs2
Sing App Vue Dashboard
Vue.js admin dashboard template built with Bootstrap 4.5
Stars: ✭ 482 (-9.4%)
Mutual labels:  vuex, vuejs2
Vue Cnode
🔥Vue.js打造一个开源的CNode社区。CNode by Vue.js
Stars: ✭ 249 (-53.2%)
Mutual labels:  vuex, vuejs2
Dashboard
A dashboard scaffolding based on Vue.js 3.0 created by Vite.
Stars: ✭ 497 (-6.58%)
Mutual labels:  vuex, vuejs2
Vue Axios Github
Vue 全家桶 + axios 前端实现登录拦截、登出、拦截器等功能
Stars: ✭ 2,622 (+392.86%)
Mutual labels:  vuex, vuejs2
Lulumi Browser
Lulumi-browser is a lightweight browser coded with Vue.js 2 and Electron.
Stars: ✭ 367 (-31.02%)
Mutual labels:  vuex, vuejs2
Vuemmerce
👉 Responsive ecommerce template 🛒 built with Vue.js and Nuxt.js
Stars: ✭ 223 (-58.08%)
Mutual labels:  vuex, vuejs2
Shop Vue
It's just a shopping cart experiment using VueJS.
Stars: ✭ 225 (-57.71%)
Mutual labels:  vuex, vuejs2
Vuet
允许你定义飙车过程的集中式状态管理模式
Stars: ✭ 430 (-19.17%)
Mutual labels:  vuex, vuejs2
Vue Develop Template
A Vue.js template that can support more than 100 thousand lines of code in our business, I hope it can help you too~
Stars: ✭ 481 (-9.59%)
Mutual labels:  vuex, vuejs2

vuex-shared-mutations

Share certain Vuex mutations across multiple tabs/windows. NPM version Build Status BrowserStack Status

Installation

$ npm install vuex-shared-mutations

Usage

import createMutationsSharer from "vuex-shared-mutations";

const store = new Vuex.Store({
  // ...
  plugins: [createMutationsSharer({ predicate: ["mutation1", "mutation2"] })]
});

Same as:

import createMutationsSharer from "vuex-shared-mutations";

const store = new Vuex.Store({
  // ...
  plugins: [
    createMutationsSharer({
      predicate: (mutation, state) => {
        const predicate = ["mutation1", "mutation2"];
        // Conditionally trigger other plugins subscription event here to
        // have them called only once (in the tab where the commit happened)
        // ie. save certain values to localStorage
        // pluginStateChanged(mutation, state)
        return predicate.indexOf(mutation.type) >= 0;
      }
    })
  ]
});

API

createMutationsSharer([options])

Creates a new instance of the plugin with the given options. The following options can be provided to configure the plugin for your specific needs:

  • predicate <Array<string> | (mutation: { type: string, payload: any }, state: any) => boolean>: Either an array of mutation types to be shared or predicate function, which accepts whole mutation object (and state) and returns true if this mutation should be shared.
  • strategy: { addEventListener: (fn: function) => any, share(any) => any } - strategy is an object which provides two functions:
    • addEventListener - plugin will subscribe to changes events using this function
    • share - plugin will call this function when data should be shared

How it works

Initially, this plugin started as a small plugin to share data between tabs using localStorage. But several inconsistencies in Internet Explorer lead to entire plugin rewrite and now it is not tied to localStorage anymore If you do not supply strategy system will use BroadcastChannel if available and downgrade to localStorage if it fails.

If you need to configure strategies you can do that by hand, for example:

import createMutationsSharer, { BroadcastStrategy } from 'vuex-shared-mutations';

const store = new Vuex.Store({
  // ...
  plugins: [
    createMutationsSharer({
      predicate: ['m-1'],
      strategy: new BroadcastStrategy({ key: 'CHANNEL_NAME' })
    }),
  ],
});

Options accepted by BroadcastStrategy: - key: string - channel name, using for sharing

Options accepted by LocalStorageStrategy: - key: string - key, used in localStorage (default: 'vuex-shared-mutations') - maxMessageLength: number - In some browsers (hello, Internet Explorer), when you're setting big payload on localStorage, "storage" event is not triggered. This strategy bypasses it by splitting message in chunk. If you do not need to support old browsers, you can increase this number (default: 4096)

Contributing

  • Fork
  • > git clone
  • > npm install
  • Make your changes
  • > npm run test (assuming you have Chrome installed in your system)
  • > npm run lint
  • If everything is passing: - Update CHANGELOG.md - Commit and Make a pull request

License

MIT © Illya Klymov

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