Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vuex

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vuex - npm Package Compare versions

Comparing version 0.6.2 to 0.6.3

140

dist/vuex.js
/*!
* Vuex v0.6.2
* Vuex v0.6.3
* (c) 2016 Evan You

@@ -161,2 +161,6 @@ * Released under the MIT License.

/**
* Vuex init hook, injected into each instances init hooks list.
*/
function vuexInit() {

@@ -198,3 +202,3 @@ var options = this.$options;

for (var _key in actions) {
options.methods[_key] = makeBoundAction(actions[_key], this.$store);
options.methods[_key] = makeBoundAction(this.$store, actions[_key], _key);
}

@@ -205,2 +209,6 @@ }

/**
* Setter for all getter properties.
*/
function setter() {

@@ -210,13 +218,37 @@ throw new Error('vuex getter properties are read-only.');

/**
* Define a Vuex getter on an instance.
*
* @param {Vue} vm
* @param {String} key
* @param {Function} getter
*/
function defineVuexGetter(vm, key, getter) {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
});
if (typeof getter !== 'function') {
console.warn('[vuex] Getter bound to key \'vuex.getters.' + key + '\' is not a function.');
} else {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
});
}
}
/**
* Make a computed getter, using the same caching mechanism of computed
* properties. In addition, it is cached on the raw getter function using
* the store's unique cache id. This makes the same getter shared
* across all components use the same underlying watcher, and makes
* the getter evaluated only once during every flush.
*
* @param {Store} store
* @param {Function} getter
*/
function makeComputedGetter(store, getter) {
var id = store._getterCacheId;
// cached

@@ -245,3 +277,14 @@ if (getter[id]) {

function makeBoundAction(action, store) {
/**
* Make a bound-to-store version of a raw action function.
*
* @param {Store} store
* @param {Function} action
* @param {String} key
*/
function makeBoundAction(store, action, key) {
if (typeof action !== 'function') {
console.warn('[vuex] Action bound to key \'vuex.actions.' + key + '\' is not a function.');
}
return function vuexBoundAction() {

@@ -352,4 +395,2 @@ for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) {

value: function dispatch(type) {
var _this2 = this;
for (var _len2 = arguments.length, payload = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {

@@ -359,12 +400,11 @@ payload[_key2 - 1] = arguments[_key2];

var silent = false;
// compatibility for object actions, e.g. FSA
if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) {
payload = [type];
payload = [type.payload];
if (type.silent) silent = true;
type = type.type;
}
var mutation = this._mutations[type];
var prevSnapshot = this._prevSnapshot;
var state = this.state;
var snapshot = void 0,
clonedPayload = void 0;
if (mutation) {

@@ -381,16 +421,3 @@ this._dispatching = true;

this._dispatching = false;
// invoke middlewares
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state);
clonedPayload = deepClone(payload);
}
this._middlewares.forEach(function (m) {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this2);
} else {
m.onMutation({ type: type, payload: payload }, state, _this2);
}
}
});
if (!silent) this._applyMiddlewares(type, payload);
} else {

@@ -414,6 +441,6 @@ console.warn('[vuex] Unknown mutation: ' + type);

value: function watch(expOrFn, cb, options) {
var _this3 = this;
var _this2 = this;
return this._vm.$watch(function () {
return typeof expOrFn === 'function' ? expOrFn(_this3.state) : _this3._vm.$get(expOrFn);
return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
}, cb, options);

@@ -452,6 +479,4 @@ }

value: function _setupModuleState(state, modules) {
var setPath = Vue.parsers.path.setPath;
Object.keys(modules).forEach(function (key) {
setPath(state, key, modules[key].state || {});
Vue.set(state, key, modules[key].state || {});
});

@@ -471,4 +496,2 @@ }

var modules = this._modules;
var getPath = Vue.parsers.path.getPath;
var allMutations = [this._rootMutations];

@@ -490,3 +513,3 @@ Object.keys(updatedModules).forEach(function (key) {

original.apply(undefined, [getPath(state, key)].concat(args));
original.apply(undefined, [state[key]].concat(args));
};

@@ -511,3 +534,3 @@ });

value: function _setupMutationCheck() {
var _this4 = this;
var _this3 = this;

@@ -517,3 +540,3 @@ var Watcher = getWatcher(this._vm);

new Watcher(this._vm, '$data', function () {
if (!_this4._dispatching) {
if (!_this3._dispatching) {
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');

@@ -539,3 +562,3 @@ }

value: function _setupMiddlewares(middlewares, state) {
var _this5 = this;
var _this4 = this;

@@ -553,7 +576,38 @@ this._middlewares = [devtoolMiddleware].concat(middlewares);

if (m.onInit) {
m.onInit(m.snapshot ? initialSnapshot : state, _this5);
m.onInit(m.snapshot ? initialSnapshot : state, _this4);
}
});
}
/**
* Apply the middlewares on a given mutation.
*
* @param {String} type
* @param {Array} payload
*/
}, {
key: '_applyMiddlewares',
value: function _applyMiddlewares(type, payload) {
var _this5 = this;
var state = this.state;
var prevSnapshot = this._prevSnapshot;
var snapshot = void 0,
clonedPayload = void 0;
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state);
clonedPayload = deepClone(payload);
}
this._middlewares.forEach(function (m) {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this5);
} else {
m.onMutation({ type: type, payload: payload }, state, _this5);
}
}
});
}
}, {
key: 'state',

@@ -571,2 +625,6 @@ get: function get() {

function install(_Vue) {
if (Vue) {
console.warn('[vuex] already installed. Vue.use(Vuex) should be called only once.');
return;
}
Vue = _Vue;

@@ -573,0 +631,0 @@ override(Vue);

/*!
* Vuex v0.6.2
* Vuex v0.6.3
* (c) 2016 Evan You
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Vuex=e()}(this,function(){"use strict";function t(t){return t.reduce(function(t,e){return Object.keys(e).forEach(function(n){var o=t[n];o?Array.isArray(o)?o.push(e[n]):t[n]=[t[n],e[n]]:t[n]=e[n]}),t},{})}function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"===("undefined"==typeof t?"undefined":s["typeof"](t))){for(var n={},o=Object.keys(t),r=0,i=o.length;i>r;r++){var a=o[r];n[a]=e(t[a])}return n}return t}function n(t){if(!u){var e=t.$watch("__vuex__",function(t){return t});u=t._watchers[0].constructor,e()}return u}function o(t){return c||(c=t._data.__ob__.dep.constructor),c}function r(t){function e(){var t=this.$options,e=t.store,n=t.vuex;if(e?this.$store=e:t.parent&&t.parent.$store&&(this.$store=t.parent.$store),n){this.$store||console.warn("[vuex] store not injected. make sure to provide the store option in your root component.");var o=n.state,r=n.getters,a=n.actions;if(o&&!r&&(console.warn("[vuex] vuex.state option will been deprecated in 1.0. Use vuex.getters instead."),r=o),r){t.computed=t.computed||{};for(var u in r)i(this,u,r[u])}if(a){t.methods=t.methods||{};for(var c in a)t.methods[c]=s(a[c],this.$store)}}}function r(){throw new Error("vuex getter properties are read-only.")}function i(t,e,n){Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:a(t.$store,n),set:r})}function a(t,e){var r=t._getterCacheId;if(e[r])return e[r];var i=t._vm,a=n(i),s=o(i),u=new a(i,function(t){return e(t)},null,{lazy:!0}),c=function(){return u.dirty&&u.evaluate(),s.target&&u.depend(),u.value};return e[r]=c,c}function s(t,e){return function(){for(var n=arguments.length,o=Array(n),r=0;n>r;r++)o[r]=arguments[r];return t.call.apply(t,[this,e].concat(o))}}var u=t.prototype._init;t.prototype._init=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t.init=t.init?[e].concat(t.init):e,u.call(this,t)};var c=t.config.optionMergeStrategies.computed;t.config.optionMergeStrategies.vuex=function(t,e){return t?e?{getters:c(t.getters,e.getters),state:c(t.state,e.state),actions:c(t.actions,e.actions)}:t:e}}function i(t){d=t,r(d)}function a(){console.warn("[vuex] Vuex.createLogger has been deprecated.Use `import createLogger from 'vuex/logger' instead.")}var s={};s["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},s.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},s.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),s.toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)};var u=void 0,c=void 0,f="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,h={onInit:function(t,e){f&&(f.emit("vuex:init",e),f.on("vuex:travel-to-state",function(t){var n=e._vm._data;e._dispatching=!0,Object.keys(t).forEach(function(e){n[e]=t[e]}),e._dispatching=!1}))},onMutation:function(t,e){f&&f.emit("vuex:mutation",t,e)}},d=void 0,l=0,p=function(){function o(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.state,r=void 0===n?{}:n,i=e.mutations,a=void 0===i?{}:i,u=e.modules,c=void 0===u?{}:u,f=e.middlewares,h=void 0===f?[]:f,p=e.strict,v=void 0===p?!1:p;s.classCallCheck(this,o),this._getterCacheId="vuex_store_"+l++,this._dispatching=!1,this._rootMutations=this._mutations=a,this._modules=c;var y=this.dispatch;if(this.dispatch=function(){for(var e=arguments.length,n=Array(e),o=0;e>o;o++)n[o]=arguments[o];y.apply(t,n)},!d)throw new Error("[vuex] must call Vue.use(Vuex) before creating a store instance.");var _=d.config.silent;d.config.silent=!0,this._vm=new d({data:r}),d.config.silent=_,this._setupModuleState(r,c),this._setupModuleMutations(c),this._setupMiddlewares(h,r),v&&this._setupMutationCheck()}return s.createClass(o,[{key:"dispatch",value:function(t){for(var n=this,o=arguments.length,r=Array(o>1?o-1:0),i=1;o>i;i++)r[i-1]=arguments[i];"object"===("undefined"==typeof t?"undefined":s["typeof"](t))&&t.type&&1===arguments.length&&(r=[t],t=t.type);var a=this._mutations[t],u=this._prevSnapshot,c=this.state,f=void 0,h=void 0;a?(this._dispatching=!0,Array.isArray(a)?a.forEach(function(t){return t.apply(void 0,[c].concat(s.toConsumableArray(r)))}):a.apply(void 0,[c].concat(s.toConsumableArray(r))),this._dispatching=!1,this._needSnapshots&&(f=this._prevSnapshot=e(c),h=e(r)),this._middlewares.forEach(function(e){e.onMutation&&(e.snapshot?e.onMutation({type:t,payload:h},f,u,n):e.onMutation({type:t,payload:r},c,n))})):console.warn("[vuex] Unknown mutation: "+t)}},{key:"watch",value:function(t,e,n){var o=this;return this._vm.$watch(function(){return"function"==typeof t?t(o.state):o._vm.$get(t)},e,n)}},{key:"hotUpdate",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.mutations,n=t.modules;this._rootMutations=this._mutations=e||this._rootMutations,this._setupModuleMutations(n||this._modules)}},{key:"_setupModuleState",value:function(t,e){var n=d.parsers.path.setPath;Object.keys(e).forEach(function(o){n(t,o,e[o].state||{})})}},{key:"_setupModuleMutations",value:function(e){var n=this._modules,o=d.parsers.path.getPath,r=[this._rootMutations];Object.keys(e).forEach(function(t){n[t]=e[t]}),Object.keys(n).forEach(function(t){var e=n[t];if(e&&e.mutations){var i={};Object.keys(e.mutations).forEach(function(n){var r=e.mutations[n];i[n]=function(e){for(var n=arguments.length,i=Array(n>1?n-1:0),a=1;n>a;a++)i[a-1]=arguments[a];r.apply(void 0,[o(e,t)].concat(i))}}),r.push(i)}}),this._mutations=t(r)}},{key:"_setupMutationCheck",value:function(){var t=this,e=n(this._vm);new e(this._vm,"$data",function(){if(!t._dispatching)throw new Error("[vuex] Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}},{key:"_setupMiddlewares",value:function(t,n){var o=this;this._middlewares=[h].concat(t),this._needSnapshots=t.some(function(t){return t.snapshot}),this._needSnapshots&&console.log("[vuex] One or more of your middlewares are taking state snapshots for each mutation. Make sure to use them only during development.");var r=this._prevSnapshot=this._needSnapshots?e(n):null;this._middlewares.forEach(function(t){t.onInit&&t.onInit(t.snapshot?r:n,o)})}},{key:"state",get:function(){return this._vm._data},set:function(t){throw new Error("[vuex] Vuex root state is read only.")}}]),o}();"undefined"!=typeof window&&window.Vue&&i(window.Vue);var v={Store:p,install:i,createLogger:a};return v});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.Vuex=e()}(this,function(){"use strict";function t(t){return t.reduce(function(t,e){return Object.keys(e).forEach(function(n){var o=t[n];o?Array.isArray(o)?o.push(e[n]):t[n]=[t[n],e[n]]:t[n]=e[n]}),t},{})}function e(t){if(Array.isArray(t))return t.map(e);if(t&&"object"===("undefined"==typeof t?"undefined":s["typeof"](t))){for(var n={},o=Object.keys(t),i=0,r=o.length;r>i;i++){var a=o[i];n[a]=e(t[a])}return n}return t}function n(t){if(!u){var e=t.$watch("__vuex__",function(t){return t});u=t._watchers[0].constructor,e()}return u}function o(t){return c||(c=t._data.__ob__.dep.constructor),c}function i(t){function e(){var t=this.$options,e=t.store,n=t.vuex;if(e?this.$store=e:t.parent&&t.parent.$store&&(this.$store=t.parent.$store),n){this.$store||console.warn("[vuex] store not injected. make sure to provide the store option in your root component.");var o=n.state,i=n.getters,a=n.actions;if(o&&!i&&(console.warn("[vuex] vuex.state option will been deprecated in 1.0. Use vuex.getters instead."),i=o),i){t.computed=t.computed||{};for(var u in i)r(this,u,i[u])}if(a){t.methods=t.methods||{};for(var c in a)t.methods[c]=s(this.$store,a[c],c)}}}function i(){throw new Error("vuex getter properties are read-only.")}function r(t,e,n){"function"!=typeof n?console.warn("[vuex] Getter bound to key 'vuex.getters."+e+"' is not a function."):Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get:a(t.$store,n),set:i})}function a(t,e){var i=t._getterCacheId;if(e[i])return e[i];var r=t._vm,a=n(r),s=o(r),u=new a(r,function(t){return e(t)},null,{lazy:!0}),c=function(){return u.dirty&&u.evaluate(),s.target&&u.depend(),u.value};return e[i]=c,c}function s(t,e,n){return"function"!=typeof e&&console.warn("[vuex] Action bound to key 'vuex.actions."+n+"' is not a function."),function(){for(var n=arguments.length,o=Array(n),i=0;n>i;i++)o[i]=arguments[i];return e.call.apply(e,[this,t].concat(o))}}var u=t.prototype._init;t.prototype._init=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];t.init=t.init?[e].concat(t.init):e,u.call(this,t)};var c=t.config.optionMergeStrategies.computed;t.config.optionMergeStrategies.vuex=function(t,e){return t?e?{getters:c(t.getters,e.getters),state:c(t.state,e.state),actions:c(t.actions,e.actions)}:t:e}}function r(t){return h?void console.warn("[vuex] already installed. Vue.use(Vuex) should be called only once."):(h=t,void i(h))}function a(){console.warn("[vuex] Vuex.createLogger has been deprecated.Use `import createLogger from 'vuex/logger' instead.")}var s={};s["typeof"]="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},s.classCallCheck=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},s.createClass=function(){function t(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,o.key,o)}}return function(e,n,o){return n&&t(e.prototype,n),o&&t(e,o),e}}(),s.toConsumableArray=function(t){if(Array.isArray(t)){for(var e=0,n=Array(t.length);e<t.length;e++)n[e]=t[e];return n}return Array.from(t)};var u=void 0,c=void 0,f="undefined"!=typeof window&&window.__VUE_DEVTOOLS_GLOBAL_HOOK__,d={onInit:function(t,e){f&&(f.emit("vuex:init",e),f.on("vuex:travel-to-state",function(t){var n=e._vm._data;e._dispatching=!0,Object.keys(t).forEach(function(e){n[e]=t[e]}),e._dispatching=!1}))},onMutation:function(t,e){f&&f.emit("vuex:mutation",t,e)}},h=void 0,l=0,p=function(){function o(){var t=this,e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=e.state,i=void 0===n?{}:n,r=e.mutations,a=void 0===r?{}:r,u=e.modules,c=void 0===u?{}:u,f=e.middlewares,d=void 0===f?[]:f,p=e.strict,v=void 0===p?!1:p;s.classCallCheck(this,o),this._getterCacheId="vuex_store_"+l++,this._dispatching=!1,this._rootMutations=this._mutations=a,this._modules=c;var y=this.dispatch;if(this.dispatch=function(){for(var e=arguments.length,n=Array(e),o=0;e>o;o++)n[o]=arguments[o];y.apply(t,n)},!h)throw new Error("[vuex] must call Vue.use(Vuex) before creating a store instance.");var _=h.config.silent;h.config.silent=!0,this._vm=new h({data:i}),h.config.silent=_,this._setupModuleState(i,c),this._setupModuleMutations(c),this._setupMiddlewares(d,i),v&&this._setupMutationCheck()}return s.createClass(o,[{key:"dispatch",value:function(t){for(var e=arguments.length,n=Array(e>1?e-1:0),o=1;e>o;o++)n[o-1]=arguments[o];var i=!1;"object"===("undefined"==typeof t?"undefined":s["typeof"](t))&&t.type&&1===arguments.length&&(n=[t.payload],t.silent&&(i=!0),t=t.type);var r=this._mutations[t],a=this.state;r?(this._dispatching=!0,Array.isArray(r)?r.forEach(function(t){return t.apply(void 0,[a].concat(s.toConsumableArray(n)))}):r.apply(void 0,[a].concat(s.toConsumableArray(n))),this._dispatching=!1,i||this._applyMiddlewares(t,n)):console.warn("[vuex] Unknown mutation: "+t)}},{key:"watch",value:function(t,e,n){var o=this;return this._vm.$watch(function(){return"function"==typeof t?t(o.state):o._vm.$get(t)},e,n)}},{key:"hotUpdate",value:function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.mutations,n=t.modules;this._rootMutations=this._mutations=e||this._rootMutations,this._setupModuleMutations(n||this._modules)}},{key:"_setupModuleState",value:function(t,e){Object.keys(e).forEach(function(n){h.set(t,n,e[n].state||{})})}},{key:"_setupModuleMutations",value:function(e){var n=this._modules,o=[this._rootMutations];Object.keys(e).forEach(function(t){n[t]=e[t]}),Object.keys(n).forEach(function(t){var e=n[t];if(e&&e.mutations){var i={};Object.keys(e.mutations).forEach(function(n){var o=e.mutations[n];i[n]=function(e){for(var n=arguments.length,i=Array(n>1?n-1:0),r=1;n>r;r++)i[r-1]=arguments[r];o.apply(void 0,[e[t]].concat(i))}}),o.push(i)}}),this._mutations=t(o)}},{key:"_setupMutationCheck",value:function(){var t=this,e=n(this._vm);new e(this._vm,"$data",function(){if(!t._dispatching)throw new Error("[vuex] Do not mutate vuex store state outside mutation handlers.")},{deep:!0,sync:!0})}},{key:"_setupMiddlewares",value:function(t,n){var o=this;this._middlewares=[d].concat(t),this._needSnapshots=t.some(function(t){return t.snapshot}),this._needSnapshots&&console.log("[vuex] One or more of your middlewares are taking state snapshots for each mutation. Make sure to use them only during development.");var i=this._prevSnapshot=this._needSnapshots?e(n):null;this._middlewares.forEach(function(t){t.onInit&&t.onInit(t.snapshot?i:n,o)})}},{key:"_applyMiddlewares",value:function(t,n){var o=this,i=this.state,r=this._prevSnapshot,a=void 0,s=void 0;this._needSnapshots&&(a=this._prevSnapshot=e(i),s=e(n)),this._middlewares.forEach(function(e){e.onMutation&&(e.snapshot?e.onMutation({type:t,payload:s},a,r,o):e.onMutation({type:t,payload:n},i,o))})}},{key:"state",get:function(){return this._vm._data},set:function(t){throw new Error("[vuex] Vuex root state is read only.")}}]),o}();"undefined"!=typeof window&&window.Vue&&r(window.Vue);var v={Store:p,install:r,createLogger:a};return v});
{
"name": "vuex",
"version": "0.6.2",
"version": "0.6.3",
"description": "state management for Vue.js",

@@ -56,2 +56,4 @@ "main": "dist/vuex.js",

"rollup-plugin-babel": "^2.4.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0",
"todomvc-app-css": "^2.0.3",

@@ -58,0 +60,0 @@ "uglify-js": "^2.6.2",

@@ -9,3 +9,3 @@ # Vuex [![Build Status](https://img.shields.io/circleci/project/vuejs/vuex/master.svg)](https://circleci.com/gh/vuejs/vuex) [![npm package](https://img.shields.io/npm/v/vuex.svg)](https://www.npmjs.com/package/vuex)

- [Documentation](http://vuex.vuejs.org/)
- [Documentation](http://vuejs.github.io/vuex/)
- [Great introduction and explanation by @skyronic](http://skyronic.com/2016/01/03/vuex-basics-tutorial/) (using outdated 0.3.0 API, but still worth a read!)

@@ -38,2 +38,2 @@ - [Vuex introduction video - James Browne from London Vue.js Meetup #1](https://www.youtube.com/watch?v=l1KHL-TX3qs)

- Hot Reloading
- Time Travel (with upcoming vue-devtools support)
- Time Travel (with [vue-devtools](https://github.com/vuejs/vue-devtools) support)

@@ -80,11 +80,11 @@ import { mergeObjects, deepClone, getWatcher } from './util'

dispatch (type, ...payload) {
let silent = false
// compatibility for object actions, e.g. FSA
if (typeof type === 'object' && type.type && arguments.length === 1) {
payload = [type]
payload = [type.payload]
if (type.silent) silent = true
type = type.type
}
const mutation = this._mutations[type]
const prevSnapshot = this._prevSnapshot
const state = this.state
let snapshot, clonedPayload
if (mutation) {

@@ -99,16 +99,3 @@ this._dispatching = true

this._dispatching = false
// invoke middlewares
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state)
clonedPayload = deepClone(payload)
}
this._middlewares.forEach(m => {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type, payload: clonedPayload }, snapshot, prevSnapshot, this)
} else {
m.onMutation({ type, payload }, state, this)
}
}
})
if (!silent) this._applyMiddlewares(type, payload)
} else {

@@ -158,5 +145,4 @@ console.warn(`[vuex] Unknown mutation: ${type}`)

_setupModuleState (state, modules) {
const { setPath } = Vue.parsers.path
Object.keys(modules).forEach(key => {
setPath(state, key, modules[key].state || {})
Vue.set(state, key, modules[key].state || {})
})

@@ -174,3 +160,2 @@ }

const modules = this._modules
const { getPath } = Vue.parsers.path
const allMutations = [this._rootMutations]

@@ -188,3 +173,3 @@ Object.keys(updatedModules).forEach(key => {

mutations[name] = (state, ...args) => {
original(getPath(state, key), ...args)
original(state[key], ...args)
}

@@ -249,5 +234,37 @@ })

}
/**
* Apply the middlewares on a given mutation.
*
* @param {String} type
* @param {Array} payload
*/
_applyMiddlewares (type, payload) {
const state = this.state
const prevSnapshot = this._prevSnapshot
let snapshot, clonedPayload
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state)
clonedPayload = deepClone(payload)
}
this._middlewares.forEach(m => {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type, payload: clonedPayload }, snapshot, prevSnapshot, this)
} else {
m.onMutation({ type, payload }, state, this)
}
}
})
}
}
function install (_Vue) {
if (Vue) {
console.warn(
'[vuex] already installed. Vue.use(Vuex) should be called only once.'
)
return
}
Vue = _Vue

@@ -254,0 +271,0 @@ override(Vue)

@@ -13,2 +13,6 @@ import { getWatcher, getDep } from './util'

/**
* Vuex init hook, injected into each instances init hooks list.
*/
function vuexInit () {

@@ -51,3 +55,3 @@ const options = this.$options

for (let key in actions) {
options.methods[key] = makeBoundAction(actions[key], this.$store)
options.methods[key] = makeBoundAction(this.$store, actions[key], key)
}

@@ -58,2 +62,6 @@ }

/**
* Setter for all getter properties.
*/
function setter () {

@@ -63,13 +71,37 @@ throw new Error('vuex getter properties are read-only.')

/**
* Define a Vuex getter on an instance.
*
* @param {Vue} vm
* @param {String} key
* @param {Function} getter
*/
function defineVuexGetter (vm, key, getter) {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
})
if (typeof getter !== 'function') {
console.warn(`[vuex] Getter bound to key 'vuex.getters.${key}' is not a function.`)
} else {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
})
}
}
/**
* Make a computed getter, using the same caching mechanism of computed
* properties. In addition, it is cached on the raw getter function using
* the store's unique cache id. This makes the same getter shared
* across all components use the same underlying watcher, and makes
* the getter evaluated only once during every flush.
*
* @param {Store} store
* @param {Function} getter
*/
function makeComputedGetter (store, getter) {
const id = store._getterCacheId
// cached

@@ -101,3 +133,14 @@ if (getter[id]) {

function makeBoundAction (action, store) {
/**
* Make a bound-to-store version of a raw action function.
*
* @param {Store} store
* @param {Function} action
* @param {String} key
*/
function makeBoundAction (store, action, key) {
if (typeof action !== 'function') {
console.warn(`[vuex] Action bound to key 'vuex.actions.${key}' is not a function.`)
}
return function vuexBoundAction (...args) {

@@ -104,0 +147,0 @@ return action.call(this, store, ...args)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc