Explorar el Código

[build] 2.1.2

Evan You hace 8 años
padre
commit
253926fc09
Se han modificado 4 ficheros con 312 adiciones y 264 borrados
  1. 29 25
      dist/logger.js
  2. 281 237
      dist/vuex.js
  3. 0 0
      dist/vuex.js.map
  4. 2 2
      dist/vuex.min.js

+ 29 - 25
dist/logger.js

@@ -1,7 +1,7 @@
 (function (global, factory) {
-  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
-  typeof define === 'function' && define.amd ? define(factory) :
-  (global.createVuexLogger = factory());
+	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+	typeof define === 'function' && define.amd ? define(factory) :
+	(global.createVuexLogger = factory());
 }(this, (function () { 'use strict';
 
 /**
@@ -34,26 +34,30 @@ function deepCopy (obj, cache) {
   }
 
   // if obj is hit, it is in circular structure
-  var hit = find(cache, function (c) { return c.original === obj; })
+  var hit = find(cache, function (c) { return c.original === obj; });
   if (hit) {
     return hit.copy
   }
 
-  var copy = Array.isArray(obj) ? [] : {}
+  var copy = Array.isArray(obj) ? [] : {};
   // put the copy into cache at first
   // because we want to refer it in recursive deepCopy
   cache.push({
     original: obj,
     copy: copy
-  })
+  });
 
   Object.keys(obj).forEach(function (key) {
-    copy[key] = deepCopy(obj[key], cache)
-  })
+    copy[key] = deepCopy(obj[key], cache);
+  });
 
   return copy
 }
 
+/**
+ * forEach for object
+ */
+
 // Credits: borrowed code from fcomb/redux-logger
 
 function createLogger (ref) {
@@ -63,40 +67,40 @@ function createLogger (ref) {
   var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) { return mut; };
 
   return function (store) {
-    var prevState = deepCopy(store.state)
+    var prevState = deepCopy(store.state);
 
     store.subscribe(function (mutation, state) {
       if (typeof console === 'undefined') {
         return
       }
-      var nextState = deepCopy(state)
-      var time = new Date()
-      var formattedTime = " @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))
-      var formattedMutation = mutationTransformer(mutation)
-      var message = "mutation " + (mutation.type) + formattedTime
+      var nextState = deepCopy(state);
+      var time = new Date();
+      var formattedTime = " @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3));
+      var formattedMutation = mutationTransformer(mutation);
+      var message = "mutation " + (mutation.type) + formattedTime;
       var startMessage = collapsed
         ? console.groupCollapsed
-        : console.group
+        : console.group;
 
       // render
       try {
-        startMessage.call(console, message)
+        startMessage.call(console, message);
       } catch (e) {
-        console.log(message)
+        console.log(message);
       }
 
-      console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState))
-      console.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation)
-      console.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState))
+      console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState));
+      console.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation);
+      console.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState));
 
       try {
-        console.groupEnd()
+        console.groupEnd();
       } catch (e) {
-        console.log('—— log end ——')
+        console.log('—— log end ——');
       }
 
-      prevState = nextState
-    })
+      prevState = nextState;
+    });
   }
 }
 
@@ -110,4 +114,4 @@ function pad (num, maxLength) {
 
 return createLogger;
 
-})));
+})));

+ 281 - 237
dist/vuex.js

@@ -1,52 +1,52 @@
 /**
- * vuex v2.1.1
- * (c) 2016 Evan You
+ * vuex v2.1.2
+ * (c) 2017 Evan You
  * @license MIT
  */
 (function (global, factory) {
-  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
-  typeof define === 'function' && define.amd ? define(factory) :
-  (global.Vuex = factory());
+	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+	typeof define === 'function' && define.amd ? define(factory) :
+	(global.Vuex = factory());
 }(this, (function () { 'use strict';
 
 var devtoolHook =
   typeof window !== 'undefined' &&
-  window.__VUE_DEVTOOLS_GLOBAL_HOOK__
+  window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
 
 function devtoolPlugin (store) {
   if (!devtoolHook) { return }
 
-  store._devtoolHook = devtoolHook
+  store._devtoolHook = devtoolHook;
 
-  devtoolHook.emit('vuex:init', store)
+  devtoolHook.emit('vuex:init', store);
 
   devtoolHook.on('vuex:travel-to-state', function (targetState) {
-    store.replaceState(targetState)
-  })
+    store.replaceState(targetState);
+  });
 
   store.subscribe(function (mutation, state) {
-    devtoolHook.emit('vuex:mutation', mutation, state)
-  })
+    devtoolHook.emit('vuex:mutation', mutation, state);
+  });
 }
 
-function applyMixin (Vue) {
-  var version = Number(Vue.version.split('.')[0])
+var applyMixin = function (Vue) {
+  var version = Number(Vue.version.split('.')[0]);
 
   if (version >= 2) {
-    var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1
-    Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit })
+    var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1;
+    Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit });
   } else {
     // override init and inject vuex init procedure
     // for 1.x backwards compatibility.
-    var _init = Vue.prototype._init
+    var _init = Vue.prototype._init;
     Vue.prototype._init = function (options) {
       if ( options === void 0 ) options = {};
 
       options.init = options.init
         ? [vuexInit].concat(options.init)
-        : vuexInit
-      _init.call(this, options)
-    }
+        : vuexInit;
+      _init.call(this, options);
+    };
   }
 
   /**
@@ -54,92 +54,101 @@ function applyMixin (Vue) {
    */
 
   function vuexInit () {
-    var options = this.$options
+    var options = this.$options;
     // store injection
     if (options.store) {
-      this.$store = options.store
+      this.$store = options.store;
     } else if (options.parent && options.parent.$store) {
-      this.$store = options.parent.$store
+      this.$store = options.parent.$store;
     }
   }
-}
+};
 
 var mapState = normalizeNamespace(function (namespace, states) {
-  var res = {}
+  var res = {};
   normalizeMap(states).forEach(function (ref) {
     var key = ref.key;
     var val = ref.val;
 
     res[key] = function mappedState () {
-      var state = this.$store.state
-      var getters = this.$store.getters
+      var state = this.$store.state;
+      var getters = this.$store.getters;
       if (namespace) {
-        var module = this.$store._modulesNamespaceMap[namespace]
+        var module = getModuleByNamespace(this.$store, 'mapState', namespace);
         if (!module) {
-          warnNamespace('mapState', namespace)
           return
         }
-        state = module.state
-        getters = module.context.getters
+        state = module.context.state;
+        getters = module.context.getters;
       }
       return typeof val === 'function'
         ? val.call(this, state, getters)
         : state[val]
-    }
-  })
+    };
+  });
   return res
-})
+});
 
 var mapMutations = normalizeNamespace(function (namespace, mutations) {
-  var res = {}
+  var res = {};
   normalizeMap(mutations).forEach(function (ref) {
     var key = ref.key;
     var val = ref.val;
 
-    val = namespace + val
+    val = namespace + val;
     res[key] = function mappedMutation () {
       var args = [], len = arguments.length;
       while ( len-- ) args[ len ] = arguments[ len ];
 
+      if (namespace && !getModuleByNamespace(this.$store, 'mapMutations', namespace)) {
+        return
+      }
       return this.$store.commit.apply(this.$store, [val].concat(args))
-    }
-  })
+    };
+  });
   return res
-})
+});
 
 var mapGetters = normalizeNamespace(function (namespace, getters) {
-  var res = {}
+  var res = {};
   normalizeMap(getters).forEach(function (ref) {
     var key = ref.key;
     var val = ref.val;
 
-    val = namespace + val
+    val = namespace + val;
     res[key] = function mappedGetter () {
+      if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) {
+        return
+      }
       if (!(val in this.$store.getters)) {
-        console.error(("[vuex] unknown getter: " + val))
+        console.error(("[vuex] unknown getter: " + val));
+        return
       }
       return this.$store.getters[val]
-    }
-  })
+    };
+  });
   return res
-})
+});
 
 var mapActions = normalizeNamespace(function (namespace, actions) {
-  var res = {}
+  var res = {};
   normalizeMap(actions).forEach(function (ref) {
     var key = ref.key;
     var val = ref.val;
 
-    val = namespace + val
+    val = namespace + val;
     res[key] = function mappedAction () {
       var args = [], len = arguments.length;
       while ( len-- ) args[ len ] = arguments[ len ];
 
+      if (namespace && !getModuleByNamespace(this.$store, 'mapActions', namespace)) {
+        return
+      }
       return this.$store.dispatch.apply(this.$store, [val].concat(args))
-    }
-  })
+    };
+  });
   return res
-})
+});
 
 function normalizeMap (map) {
   return Array.isArray(map)
@@ -150,24 +159,47 @@ function normalizeMap (map) {
 function normalizeNamespace (fn) {
   return function (namespace, map) {
     if (typeof namespace !== 'string') {
-      map = namespace
-      namespace = ''
+      map = namespace;
+      namespace = '';
     } else if (namespace.charAt(namespace.length - 1) !== '/') {
-      namespace += '/'
+      namespace += '/';
     }
     return fn(namespace, map)
   }
 }
 
-function warnNamespace (helper, namespace) {
-  console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace))
+function getModuleByNamespace (store, helper, namespace) {
+  var module = store._modulesNamespaceMap[namespace];
+  if (!module) {
+    console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace));
+  }
+  return module
 }
 
+/**
+ * Get the first item that pass the test
+ * by second argument function
+ *
+ * @param {Array} list
+ * @param {Function} f
+ * @return {*}
+ */
+/**
+ * Deep copy the given object considering circular structure.
+ * This function caches all nested objects and its copies.
+ * If it detects circular structure, use cached copy to avoid infinite loop.
+ *
+ * @param {*} obj
+ * @param {Array<Object>} cache
+ * @return {*}
+ */
+
+
 /**
  * forEach for object
  */
 function forEachValue (obj, fn) {
-  Object.keys(obj).forEach(function (key) { return fn(obj[key], key); })
+  Object.keys(obj).forEach(function (key) { return fn(obj[key], key); });
 }
 
 function isObject (obj) {
@@ -183,9 +215,9 @@ function assert (condition, msg) {
 }
 
 var Module = function Module (rawModule, runtime) {
-  this.runtime = runtime
-  this._children = Object.create(null)
-  this._rawModule = rawModule
+  this.runtime = runtime;
+  this._children = Object.create(null);
+  this._rawModule = rawModule;
 };
 
 var prototypeAccessors$1 = { state: {},namespaced: {} };
@@ -199,11 +231,11 @@ prototypeAccessors$1.namespaced.get = function () {
 };
 
 Module.prototype.addChild = function addChild (key, module) {
-  this._children[key] = module
+  this._children[key] = module;
 };
 
 Module.prototype.removeChild = function removeChild (key) {
-  delete this._children[key]
+  delete this._children[key];
 };
 
 Module.prototype.getChild = function getChild (key) {
@@ -211,37 +243,37 @@ Module.prototype.getChild = function getChild (key) {
 };
 
 Module.prototype.update = function update (rawModule) {
-  this._rawModule.namespaced = rawModule.namespaced
+  this._rawModule.namespaced = rawModule.namespaced;
   if (rawModule.actions) {
-    this._rawModule.actions = rawModule.actions
+    this._rawModule.actions = rawModule.actions;
   }
   if (rawModule.mutations) {
-    this._rawModule.mutations = rawModule.mutations
+    this._rawModule.mutations = rawModule.mutations;
   }
   if (rawModule.getters) {
-    this._rawModule.getters = rawModule.getters
+    this._rawModule.getters = rawModule.getters;
   }
 };
 
 Module.prototype.forEachChild = function forEachChild (fn) {
-  forEachValue(this._children, fn)
+  forEachValue(this._children, fn);
 };
 
 Module.prototype.forEachGetter = function forEachGetter (fn) {
   if (this._rawModule.getters) {
-    forEachValue(this._rawModule.getters, fn)
+    forEachValue(this._rawModule.getters, fn);
   }
 };
 
 Module.prototype.forEachAction = function forEachAction (fn) {
   if (this._rawModule.actions) {
-    forEachValue(this._rawModule.actions, fn)
+    forEachValue(this._rawModule.actions, fn);
   }
 };
 
 Module.prototype.forEachMutation = function forEachMutation (fn) {
   if (this._rawModule.mutations) {
-    forEachValue(this._rawModule.mutations, fn)
+    forEachValue(this._rawModule.mutations, fn);
   }
 };
 
@@ -251,13 +283,13 @@ var ModuleCollection = function ModuleCollection (rawRootModule) {
   var this$1 = this;
 
   // register root module (Vuex.Store options)
-  this.root = new Module(rawRootModule, false)
+  this.root = new Module(rawRootModule, false);
 
   // register all nested modules
   if (rawRootModule.modules) {
     forEachValue(rawRootModule.modules, function (rawModule, key) {
-      this$1.register([key], rawModule, false)
-    })
+      this$1.register([key], rawModule, false);
+    });
   }
 };
 
@@ -268,44 +300,44 @@ ModuleCollection.prototype.get = function get (path) {
 };
 
 ModuleCollection.prototype.getNamespace = function getNamespace (path) {
-  var module = this.root
+  var module = this.root;
   return path.reduce(function (namespace, key) {
-    module = module.getChild(key)
+    module = module.getChild(key);
     return namespace + (module.namespaced ? key + '/' : '')
   }, '')
 };
 
 ModuleCollection.prototype.update = function update$1 (rawRootModule) {
-  update(this.root, rawRootModule)
+  update(this.root, rawRootModule);
 };
 
 ModuleCollection.prototype.register = function register (path, rawModule, runtime) {
     var this$1 = this;
     if ( runtime === void 0 ) runtime = true;
 
-  var parent = this.get(path.slice(0, -1))
-  var newModule = new Module(rawModule, runtime)
-  parent.addChild(path[path.length - 1], newModule)
+  var parent = this.get(path.slice(0, -1));
+  var newModule = new Module(rawModule, runtime);
+  parent.addChild(path[path.length - 1], newModule);
 
   // register nested modules
   if (rawModule.modules) {
     forEachValue(rawModule.modules, function (rawChildModule, key) {
-      this$1.register(path.concat(key), rawChildModule, runtime)
-    })
+      this$1.register(path.concat(key), rawChildModule, runtime);
+    });
   }
 };
 
 ModuleCollection.prototype.unregister = function unregister (path) {
-  var parent = this.get(path.slice(0, -1))
-  var key = path[path.length - 1]
+  var parent = this.get(path.slice(0, -1));
+  var key = path[path.length - 1];
   if (!parent.getChild(key).runtime) { return }
 
-  parent.removeChild(key)
+  parent.removeChild(key);
 };
 
 function update (targetModule, newModule) {
   // update target module
-  targetModule.update(newModule)
+  targetModule.update(newModule);
 
   // update nested modules
   if (newModule.modules) {
@@ -314,63 +346,63 @@ function update (targetModule, newModule) {
         console.warn(
           "[vuex] trying to add a new module '" + key + "' on hot reloading, " +
           'manual reload is needed'
-        )
+        );
         return
       }
-      update(targetModule.getChild(key), newModule.modules[key])
+      update(targetModule.getChild(key), newModule.modules[key]);
     }
   }
 }
 
-var Vue // bind on install
+var Vue; // bind on install
 
 var Store = function Store (options) {
   var this$1 = this;
   if ( options === void 0 ) options = {};
 
-  assert(Vue, "must call Vue.use(Vuex) before creating a store instance.")
-  assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.")
+  assert(Vue, "must call Vue.use(Vuex) before creating a store instance.");
+  assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser.");
 
   var state = options.state; if ( state === void 0 ) state = {};
   var plugins = options.plugins; if ( plugins === void 0 ) plugins = [];
   var strict = options.strict; if ( strict === void 0 ) strict = false;
 
   // store internal state
-  this._committing = false
-  this._actions = Object.create(null)
-  this._mutations = Object.create(null)
-  this._wrappedGetters = Object.create(null)
-  this._modules = new ModuleCollection(options)
-  this._modulesNamespaceMap = Object.create(null)
-  this._subscribers = []
-  this._watcherVM = new Vue()
+  this._committing = false;
+  this._actions = Object.create(null);
+  this._mutations = Object.create(null);
+  this._wrappedGetters = Object.create(null);
+  this._modules = new ModuleCollection(options);
+  this._modulesNamespaceMap = Object.create(null);
+  this._subscribers = [];
+  this._watcherVM = new Vue();
 
   // bind commit and dispatch to self
-  var store = this
+  var store = this;
   var ref = this;
   var dispatch = ref.dispatch;
   var commit = ref.commit;
-    this.dispatch = function boundDispatch (type, payload) {
+  this.dispatch = function boundDispatch (type, payload) {
     return dispatch.call(store, type, payload)
-  }
+  };
   this.commit = function boundCommit (type, payload, options) {
     return commit.call(store, type, payload, options)
-    }
+  };
 
-    // strict mode
-  this.strict = strict
+  // strict mode
+  this.strict = strict;
 
   // init root module.
   // this also recursively registers all sub-modules
   // and collects all module getters inside this._wrappedGetters
-  installModule(this, state, [], this._modules.root)
+  installModule(this, state, [], this._modules.root);
 
   // initialize the store vm, which is responsible for the reactivity
   // (also registers _wrappedGetters as computed properties)
-  resetStoreVM(this, state)
+  resetStoreVM(this, state);
 
   // apply plugins
-  plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); })
+  plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); });
 };
 
 var prototypeAccessors = { state: {} };
@@ -380,7 +412,7 @@ prototypeAccessors.state.get = function () {
 };
 
 prototypeAccessors.state.set = function (v) {
-  assert(false, "Use store.replaceState() to explicit replace store state.")
+  assert(false, "Use store.replaceState() to explicit replace store state.");
 };
 
 Store.prototype.commit = function commit (_type, _payload, _options) {
@@ -392,24 +424,24 @@ Store.prototype.commit = function commit (_type, _payload, _options) {
     var payload = ref.payload;
     var options = ref.options;
 
-  var mutation = { type: type, payload: payload }
-  var entry = this._mutations[type]
+  var mutation = { type: type, payload: payload };
+  var entry = this._mutations[type];
   if (!entry) {
-    console.error(("[vuex] unknown mutation type: " + type))
+    console.error(("[vuex] unknown mutation type: " + type));
     return
   }
   this._withCommit(function () {
     entry.forEach(function commitIterator (handler) {
-      handler(payload)
-    })
-  })
-  this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); })
+      handler(payload);
+    });
+  });
+  this._subscribers.forEach(function (sub) { return sub(mutation, this$1.state); });
 
   if (options && options.silent) {
     console.warn(
       "[vuex] mutation type: " + type + ". Silent option has been removed. " +
       'Use the filter functionality in the vue-devtools'
-    )
+    );
   }
 };
 
@@ -419,9 +451,9 @@ Store.prototype.dispatch = function dispatch (_type, _payload) {
     var type = ref.type;
     var payload = ref.payload;
 
-  var entry = this._actions[type]
+  var entry = this._actions[type];
   if (!entry) {
-    console.error(("[vuex] unknown action type: " + type))
+    console.error(("[vuex] unknown action type: " + type));
     return
   }
   return entry.length > 1
@@ -430,14 +462,14 @@ Store.prototype.dispatch = function dispatch (_type, _payload) {
 };
 
 Store.prototype.subscribe = function subscribe (fn) {
-  var subs = this._subscribers
+  var subs = this._subscribers;
   if (subs.indexOf(fn) < 0) {
-    subs.push(fn)
+    subs.push(fn);
   }
   return function () {
-    var i = subs.indexOf(fn)
+    var i = subs.indexOf(fn);
     if (i > -1) {
-      subs.splice(i, 1)
+      subs.splice(i, 1);
     }
   }
 };
@@ -445,7 +477,7 @@ Store.prototype.subscribe = function subscribe (fn) {
 Store.prototype.watch = function watch (getter, cb, options) {
     var this$1 = this;
 
-  assert(typeof getter === 'function', "store.watch only accepts a function.")
+  assert(typeof getter === 'function', "store.watch only accepts a function.");
   return this._watcherVM.$watch(function () { return getter(this$1.state, this$1.getters); }, cb, options)
 };
 
@@ -453,158 +485,160 @@ Store.prototype.replaceState = function replaceState (state) {
     var this$1 = this;
 
   this._withCommit(function () {
-    this$1._vm.state = state
-  })
+    this$1._vm.state = state;
+  });
 };
 
 Store.prototype.registerModule = function registerModule (path, rawModule) {
-  if (typeof path === 'string') { path = [path] }
-  assert(Array.isArray(path), "module path must be a string or an Array.")
-  this._modules.register(path, rawModule)
-  installModule(this, this.state, path, this._modules.get(path))
+  if (typeof path === 'string') { path = [path]; }
+  assert(Array.isArray(path), "module path must be a string or an Array.");
+  this._modules.register(path, rawModule);
+  installModule(this, this.state, path, this._modules.get(path));
   // reset store to update getters...
-  resetStoreVM(this, this.state)
+  resetStoreVM(this, this.state);
 };
 
 Store.prototype.unregisterModule = function unregisterModule (path) {
     var this$1 = this;
 
-  if (typeof path === 'string') { path = [path] }
-  assert(Array.isArray(path), "module path must be a string or an Array.")
-    this._modules.unregister(path)
+  if (typeof path === 'string') { path = [path]; }
+  assert(Array.isArray(path), "module path must be a string or an Array.");
+  this._modules.unregister(path);
   this._withCommit(function () {
-    var parentState = getNestedState(this$1.state, path.slice(0, -1))
-    Vue.delete(parentState, path[path.length - 1])
-  })
-  resetStore(this)
+    var parentState = getNestedState(this$1.state, path.slice(0, -1));
+    Vue.delete(parentState, path[path.length - 1]);
+  });
+  resetStore(this);
 };
 
 Store.prototype.hotUpdate = function hotUpdate (newOptions) {
-  this._modules.update(newOptions)
-  resetStore(this)
+  this._modules.update(newOptions);
+  resetStore(this, true);
 };
 
 Store.prototype._withCommit = function _withCommit (fn) {
-  var committing = this._committing
-  this._committing = true
-  fn()
-  this._committing = committing
+  var committing = this._committing;
+  this._committing = true;
+  fn();
+  this._committing = committing;
 };
 
 Object.defineProperties( Store.prototype, prototypeAccessors );
 
-function resetStore (store) {
-  store._actions = Object.create(null)
-  store._mutations = Object.create(null)
-  store._wrappedGetters = Object.create(null)
-  store._modulesNamespaceMap = Object.create(null)
-  var state = store.state
+function resetStore (store, hot) {
+  store._actions = Object.create(null);
+  store._mutations = Object.create(null);
+  store._wrappedGetters = Object.create(null);
+  store._modulesNamespaceMap = Object.create(null);
+  var state = store.state;
   // init all modules
-  installModule(store, state, [], store._modules.root, true)
+  installModule(store, state, [], store._modules.root, true);
   // reset vm
-  resetStoreVM(store, state)
+  resetStoreVM(store, state, hot);
 }
 
-function resetStoreVM (store, state) {
-  var oldVm = store._vm
+function resetStoreVM (store, state, hot) {
+  var oldVm = store._vm;
 
   // bind store public getters
-  store.getters = {}
-  var wrappedGetters = store._wrappedGetters
-  var computed = {}
+  store.getters = {};
+  var wrappedGetters = store._wrappedGetters;
+  var computed = {};
   forEachValue(wrappedGetters, function (fn, key) {
     // use computed to leverage its lazy-caching mechanism
-    computed[key] = function () { return fn(store); }
+    computed[key] = function () { return fn(store); };
     Object.defineProperty(store.getters, key, {
       get: function () { return store._vm[key]; },
       enumerable: true // for local getters
-    })
-  })
+    });
+  });
 
   // use a Vue instance to store the state tree
   // suppress warnings just in case the user has added
   // some funky global mixins
-  var silent = Vue.config.silent
-  Vue.config.silent = true
+  var silent = Vue.config.silent;
+  Vue.config.silent = true;
   store._vm = new Vue({
     data: { state: state },
     computed: computed
-  })
-  Vue.config.silent = silent
+  });
+  Vue.config.silent = silent;
 
   // enable strict mode for new vm
   if (store.strict) {
-    enableStrictMode(store)
+    enableStrictMode(store);
   }
 
   if (oldVm) {
-    // dispatch changes in all subscribed watchers
-    // to force getter re-evaluation.
-    store._withCommit(function () {
-      oldVm.state = null
-    })
-    Vue.nextTick(function () { return oldVm.$destroy(); })
+    if (hot) {
+      // dispatch changes in all subscribed watchers
+      // to force getter re-evaluation for hot reloading.
+      store._withCommit(function () {
+        oldVm.state = null;
+      });
+    }
+    Vue.nextTick(function () { return oldVm.$destroy(); });
   }
 }
 
 function installModule (store, rootState, path, module, hot) {
-  var isRoot = !path.length
-  var namespace = store._modules.getNamespace(path)
+  var isRoot = !path.length;
+  var namespace = store._modules.getNamespace(path);
 
   // register in namespace map
   if (namespace) {
-    store._modulesNamespaceMap[namespace] = module
+    store._modulesNamespaceMap[namespace] = module;
   }
 
   // set state
   if (!isRoot && !hot) {
-    var parentState = getNestedState(rootState, path.slice(0, -1))
-    var moduleName = path[path.length - 1]
+    var parentState = getNestedState(rootState, path.slice(0, -1));
+    var moduleName = path[path.length - 1];
     store._withCommit(function () {
-      Vue.set(parentState, moduleName, module.state)
-    })
+      Vue.set(parentState, moduleName, module.state);
+    });
   }
 
-  var local = module.context = makeLocalContext(store, namespace)
+  var local = module.context = makeLocalContext(store, namespace, path);
 
   module.forEachMutation(function (mutation, key) {
-    var namespacedType = namespace + key
-    registerMutation(store, namespacedType, mutation, path)
-  })
+    var namespacedType = namespace + key;
+    registerMutation(store, namespacedType, mutation, local);
+  });
 
   module.forEachAction(function (action, key) {
-    var namespacedType = namespace + key
-    registerAction(store, namespacedType, action, local, path)
-  })
+    var namespacedType = namespace + key;
+    registerAction(store, namespacedType, action, local);
+  });
 
   module.forEachGetter(function (getter, key) {
-    var namespacedType = namespace + key
-    registerGetter(store, namespacedType, getter, local, path)
-  })
+    var namespacedType = namespace + key;
+    registerGetter(store, namespacedType, getter, local);
+  });
 
   module.forEachChild(function (child, key) {
-    installModule(store, rootState, path.concat(key), child, hot)
-  })
+    installModule(store, rootState, path.concat(key), child, hot);
+  });
 }
 
 /**
- * make localized dispatch, commit and getters
+ * make localized dispatch, commit, getters and state
  * if there is no namespace, just use root ones
  */
-function makeLocalContext (store, namespace) {
-  var noNamespace = namespace === ''
+function makeLocalContext (store, namespace, path) {
+  var noNamespace = namespace === '';
 
   var local = {
     dispatch: noNamespace ? store.dispatch : function (_type, _payload, _options) {
-      var args = unifyObjectStyle(_type, _payload, _options)
+      var args = unifyObjectStyle(_type, _payload, _options);
       var payload = args.payload;
       var options = args.options;
       var type = args.type;
 
       if (!options || !options.root) {
-        type = namespace + type
+        type = namespace + type;
         if (!store._actions[type]) {
-          console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type))
+          console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
           return
         }
       }
@@ -613,42 +647,49 @@ function makeLocalContext (store, namespace) {
     },
 
     commit: noNamespace ? store.commit : function (_type, _payload, _options) {
-      var args = unifyObjectStyle(_type, _payload, _options)
+      var args = unifyObjectStyle(_type, _payload, _options);
       var payload = args.payload;
       var options = args.options;
       var type = args.type;
 
       if (!options || !options.root) {
-        type = namespace + type
+        type = namespace + type;
         if (!store._mutations[type]) {
-          console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type))
+          console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
           return
         }
       }
 
-      store.commit(type, payload, options)
+      store.commit(type, payload, options);
     }
-  }
-
-  // getters object must be gotten lazily
-  // because store.getters will be changed by vm update
-  Object.defineProperty(local, 'getters', {
-    get: noNamespace ? function () { return store.getters; } : function () { return makeLocalGetters(store, namespace); }
-  })
+  };
+
+  // getters and state object must be gotten lazily
+  // because they will be changed by vm update
+  Object.defineProperties(local, {
+    getters: {
+      get: noNamespace
+        ? function () { return store.getters; }
+        : function () { return makeLocalGetters(store, namespace); }
+    },
+    state: {
+      get: function () { return getNestedState(store.state, path); }
+    }
+  });
 
   return local
 }
 
 function makeLocalGetters (store, namespace) {
-  var gettersProxy = {}
+  var gettersProxy = {};
 
-  var splitPos = namespace.length
+  var splitPos = namespace.length;
   Object.keys(store.getters).forEach(function (type) {
     // skip if the target getter is not match this namespace
     if (type.slice(0, splitPos) !== namespace) { return }
 
     // extract local getter type
-    var localType = type.slice(splitPos)
+    var localType = type.slice(splitPos);
 
     // Add a port to the getters proxy.
     // Define as getter property because
@@ -656,63 +697,63 @@ function makeLocalGetters (store, namespace) {
     Object.defineProperty(gettersProxy, localType, {
       get: function () { return store.getters[type]; },
       enumerable: true
-    })
-  })
+    });
+  });
 
   return gettersProxy
 }
 
-function registerMutation (store, type, handler, path) {
-  var entry = store._mutations[type] || (store._mutations[type] = [])
+function registerMutation (store, type, handler, local) {
+  var entry = store._mutations[type] || (store._mutations[type] = []);
   entry.push(function wrappedMutationHandler (payload) {
-    handler(getNestedState(store.state, path), payload)
-  })
+    handler(local.state, payload);
+  });
 }
 
-function registerAction (store, type, handler, local, path) {
-  var entry = store._actions[type] || (store._actions[type] = [])
+function registerAction (store, type, handler, local) {
+  var entry = store._actions[type] || (store._actions[type] = []);
   entry.push(function wrappedActionHandler (payload, cb) {
     var res = handler({
       dispatch: local.dispatch,
       commit: local.commit,
       getters: local.getters,
-      state: getNestedState(store.state, path),
+      state: local.state,
       rootGetters: store.getters,
       rootState: store.state
-    }, payload, cb)
+    }, payload, cb);
     if (!isPromise(res)) {
-      res = Promise.resolve(res)
+      res = Promise.resolve(res);
     }
     if (store._devtoolHook) {
       return res.catch(function (err) {
-        store._devtoolHook.emit('vuex:error', err)
+        store._devtoolHook.emit('vuex:error', err);
         throw err
       })
     } else {
       return res
     }
-  })
+  });
 }
 
-function registerGetter (store, type, rawGetter, local, path) {
+function registerGetter (store, type, rawGetter, local) {
   if (store._wrappedGetters[type]) {
-    console.error(("[vuex] duplicate getter key: " + type))
+    console.error(("[vuex] duplicate getter key: " + type));
     return
   }
   store._wrappedGetters[type] = function wrappedGetter (store) {
     return rawGetter(
-      getNestedState(store.state, path), // local state
+      local.state, // local state
       local.getters, // local getters
       store.state, // root state
       store.getters // root getters
     )
-  }
+  };
 }
 
 function enableStrictMode (store) {
   store._vm.$watch('state', function () {
-    assert(store._committing, "Do not mutate vuex store state outside mutation handlers.")
-  }, { deep: true, sync: true })
+    assert(store._committing, "Do not mutate vuex store state outside mutation handlers.");
+  }, { deep: true, sync: true });
 }
 
 function getNestedState (state, path) {
@@ -723,10 +764,13 @@ function getNestedState (state, path) {
 
 function unifyObjectStyle (type, payload, options) {
   if (isObject(type) && type.type) {
-    options = payload
-    payload = type
-    type = type.type
+    options = payload;
+    payload = type;
+    type = type.type;
   }
+
+  assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + "."));
+
   return { type: type, payload: payload, options: options }
 }
 
@@ -734,28 +778,28 @@ function install (_Vue) {
   if (Vue) {
     console.error(
       '[vuex] already installed. Vue.use(Vuex) should be called only once.'
-    )
+    );
     return
   }
-  Vue = _Vue
-  applyMixin(Vue)
+  Vue = _Vue;
+  applyMixin(Vue);
 }
 
 // auto install in dist mode
 if (typeof window !== 'undefined' && window.Vue) {
-  install(window.Vue)
+  install(window.Vue);
 }
 
 var index = {
   Store: Store,
   install: install,
-  version: '2.1.1',
+  version: '2.1.2',
   mapState: mapState,
   mapMutations: mapMutations,
   mapGetters: mapGetters,
   mapActions: mapActions
-}
+};
 
 return index;
 
-})));
+})));

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 0 - 0
dist/vuex.js.map


La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 2
dist/vuex.min.js


Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio