A Node.JS module to use Vuex on WebExtensions on "shared" context, the module allows you to start several instances of Vuex store and keep them synchronized throught WebExtensions messaging API.
Uses the Vuex store instance on background script as master, and replicate the state of master to others instances on diferent context (popup or content scripts), when you commit any mutation to any store instance the rest will also be updated automatically.
You can work with the Vuex store like a unic instance (or standart Vue.js application), without worry for the different WebExtensions contexts, the module gona solve all WebExtensions problems for you automatically.
Run the following command inside your WebExtensions project to install the module:
npm install vuex-webextensions --save
Import the module into your store file:
import VuexWebExtensions from 'vuex-webextensions';
Then add it as plugin on Vuex store initialization:
export default new Vuex.Store({
...
plugins: [VuexWebExtensions()]
});
All done!
⚠ Persistent states make use ofLocalStorage
to save the states in your browser, to use it, you should grantstorage
permision to your webextension
You can establish through the options of the plugin the states that you want to be persistent, your data will be preserved after the restart of the extension or the browser.
It is established passing the state names through persistentStates option in array:
export default new Vuex.Store({
...
plugins: [VuexWebExtensions({
persistentStates: ['stateone', 'statetwo']
})]
});
Then stateone
and statetwo
gona have the value commited by last mutation after extension or browser restart.
On version 2.5.0 vuex introduce a new method on their API to watch and hook any action of store, this plugin sync actionslike mutations by default.
Note: Event objects (like click for example) on action payload are automatically trimmered because cause serialization errors, you can pass value or object as payload anyways always that are serializable.
If you want to disable the actions sync, just set syncActions
to false on the plugin settings.
export default new Vuex.Store({
...
plugins: [VuexWebExtensions({
syncActions: false
})]
});
You can ignore specific actions like mutations too on ignoredActions
list.
It's possible skip the sync on desired mutations or actions adding their type to ignoredMutations or ignoredActions option.
All mutations or actions added to this list skip the sync process, you should update the value or process manually on desired contexts.
export default new Vuex.Store({
...
plugins: [VuexWebExtensions({
ignoredMutations: ['MUTATION_TYPE_ONE', 'MUTATION_TYPE_TWO'],
ignoredActions: ['ACTION_TYPE_ONE', 'ACTION_TYPE_TWO']
})]
});
It's possible specify the minimun logging level of the plugin with the loggerLevel
option, by default only warnings and errors gona be printed on console.
The available options are: debug, verbose, info, warning, error and none.
The none option disable all logging related with the plugin.
export default new Vuex.Store({
...
plugins: [VuexWebExtensions({
loggerLevel: 'debug'
})]
});
⚠ This version have a breaking changes please check the new install method and remove the old install on your scripts
If you encounter a problem, issue or question feel free to open a new issue on this repository.
If you have some improvements, new features or fixes feel free to fork this repository and send a pull request.
Vuex 是 状态管理工具. 简单的说, Vuex 帮我们管理 "全局变量", 供任何页面在任何时刻使用. Vuex 非常重要. 不管是大项目还是小项目,都有用到它的时候. 我们必须会用. 完整官方文档: https://vuex.vuejs.org/zh-cn/getting-started.html 必看. 正常使用的顺序 假设,我们有两个页面: "页面1" 和"页面2" , 共同使用一个变量
前言 vuex想必不需要我介绍很多了,这一节主要是为了填补项目没有引入vuex的问题,之后做完脚手架可以选择是否使用vuex。 因为vuex用的实在是很普遍,就不介绍细节了,我们直接搭项目。 新建文件 在app目录新建文件夹store: app/store ├── README.md ├── actions.js ├── getters.js ├── index.js ├── mutat
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化。 Vuex 也集成到 Vue 的官方调试工具 devtools extension,提供了诸如零配置的 time-travel 调试、状态快照导入导出等高级调试功能。
An implementation of the @handsontable/vue component with a readOnly toggle switch and the Vuex state manager implemented. Toggle readOnly for the entire table Vuex store dump: Toggle readOnly for the
由于使用了单一状态树,应用的所有状态都包含在一个大对象内。但是,随着我们应用规模的不断增长,这个Store变得非常臃肿。 为了解决这个问题,Vuex 允许我们把 store 分 module(模块)。每一个模块包含各自的状态、mutation、action 和 getter,甚至是嵌套模块, 如下就是它的组织方式: const moduleA = { state: { ... }, mutat
action 和 mutation 类似,区别在于: action 不改变状态,只提交(commit) mutation。 action 可以包含任意异步操作。 让我们注册一个简单的 action: const store = new Vuex.Store({ state: { count: 0 }, mutations: { increment (state) { s