vendor/assets/javascripts/dist/vuex.js in vuejs-rails-2.4.2 vs vendor/assets/javascripts/dist/vuex.js in vuejs-rails-2.5.13
- old
+ new
@@ -1,7 +1,7 @@
/**
- * vuex v2.3.0
+ * vuex v3.0.1
* (c) 2017 Evan You
* @license MIT
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
@@ -11,12 +11,11 @@
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 });
+ Vue.mixin({ beforeCreate: vuexInit });
} else {
// override init and inject vuex init procedure
// for 1.x backwards compatibility.
var _init = Vue.prototype._init;
Vue.prototype._init = function (options) {
@@ -35,11 +34,13 @@
function vuexInit () {
var options = this.$options;
// store injection
if (options.store) {
- this.$store = options.store;
+ this.$store = typeof options.store === 'function'
+ ? options.store()
+ : options.store;
} else if (options.parent && options.parent.$store) {
this.$store = options.parent.$store;
}
}
};
@@ -108,11 +109,11 @@
this._rawModule = rawModule;
var rawState = rawModule.state;
this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
};
-var prototypeAccessors$1 = { namespaced: {} };
+var prototypeAccessors$1 = { namespaced: { configurable: true } };
prototypeAccessors$1.namespaced.get = function () {
return !!this._rawModule.namespaced
};
@@ -164,21 +165,12 @@
};
Object.defineProperties( Module.prototype, prototypeAccessors$1 );
var ModuleCollection = function ModuleCollection (rawRootModule) {
- var this$1 = this;
-
// register root module (Vuex.Store options)
- 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.register([], rawRootModule, false);
};
ModuleCollection.prototype.get = function get (path) {
return path.reduce(function (module, key) {
return module.getChild(key)
@@ -192,20 +184,28 @@
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));
+ {
+ assertRawModule(path, rawModule);
+ }
+
var newModule = new Module(rawModule, runtime);
- parent.addChild(path[path.length - 1], newModule);
+ if (path.length === 0) {
+ this.root = newModule;
+ } else {
+ var parent = this.get(path.slice(0, -1));
+ 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);
@@ -219,45 +219,111 @@
if (!parent.getChild(key).runtime) { return }
parent.removeChild(key);
};
-function update (targetModule, newModule) {
+function update (path, targetModule, newModule) {
+ {
+ assertRawModule(path, newModule);
+ }
+
// update target module
targetModule.update(newModule);
// update nested modules
if (newModule.modules) {
for (var key in newModule.modules) {
if (!targetModule.getChild(key)) {
- console.warn(
- "[vuex] trying to add a new module '" + key + "' on hot reloading, " +
- 'manual reload is needed'
- );
+ {
+ 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(
+ path.concat(key),
+ targetModule.getChild(key),
+ newModule.modules[key]
+ );
}
}
}
+var functionAssert = {
+ assert: function (value) { return typeof value === 'function'; },
+ expected: 'function'
+};
+
+var objectAssert = {
+ assert: function (value) { return typeof value === 'function' ||
+ (typeof value === 'object' && typeof value.handler === 'function'); },
+ expected: 'function or object with "handler" function'
+};
+
+var assertTypes = {
+ getters: functionAssert,
+ mutations: functionAssert,
+ actions: objectAssert
+};
+
+function assertRawModule (path, rawModule) {
+ Object.keys(assertTypes).forEach(function (key) {
+ if (!rawModule[key]) { return }
+
+ var assertOptions = assertTypes[key];
+
+ forEachValue(rawModule[key], function (value, type) {
+ assert(
+ assertOptions.assert(value),
+ makeAssertionMessage(path, key, type, value, assertOptions.expected)
+ );
+ });
+ });
+}
+
+function makeAssertionMessage (path, key, type, value, expected) {
+ var buf = key + " should be " + expected + " but \"" + key + "." + type + "\"";
+ if (path.length > 0) {
+ buf += " in module \"" + (path.join('.')) + "\"";
+ }
+ buf += " is " + (JSON.stringify(value)) + ".";
+ return buf
+}
+
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.");
+ // Auto install if it is not done yet and `window` has `Vue`.
+ // To allow users to avoid auto-installation in some cases,
+ // this code should be placed here. See #731
+ if (!Vue && typeof window !== 'undefined' && window.Vue) {
+ install(window.Vue);
+ }
- var state = options.state; if ( state === void 0 ) state = {};
+ {
+ 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(this instanceof Store, "Store must be called with the new operator.");
+ }
+
var plugins = options.plugins; if ( plugins === void 0 ) plugins = [];
var strict = options.strict; if ( strict === void 0 ) strict = false;
+ var state = options.state; if ( state === void 0 ) state = {};
+ if (typeof state === 'function') {
+ state = state() || {};
+ }
+
// store internal state
this._committing = false;
this._actions = Object.create(null);
+ this._actionSubscribers = [];
this._mutations = Object.create(null);
this._wrappedGetters = Object.create(null);
this._modules = new ModuleCollection(options);
this._modulesNamespaceMap = Object.create(null);
this._subscribers = [];
@@ -286,21 +352,27 @@
// initialize the store vm, which is responsible for the reactivity
// (also registers _wrappedGetters as computed properties)
resetStoreVM(this, state);
// apply plugins
- plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); });
+ plugins.forEach(function (plugin) { return plugin(this$1); });
+
+ if (Vue.config.devtools) {
+ devtoolPlugin(this);
+ }
};
-var prototypeAccessors = { state: {} };
+var prototypeAccessors = { state: { configurable: true } };
prototypeAccessors.state.get = function () {
return this._vm._data.$$state
};
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) {
var this$1 = this;
@@ -311,61 +383,71 @@
var options = ref.options;
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); });
- if (options && options.silent) {
+ if (
+ "development" !== 'production' &&
+ options && options.silent
+ ) {
console.warn(
"[vuex] mutation type: " + type + ". Silent option has been removed. " +
'Use the filter functionality in the vue-devtools'
);
}
};
Store.prototype.dispatch = function dispatch (_type, _payload) {
+ var this$1 = this;
+
// check object-style dispatch
var ref = unifyObjectStyle(_type, _payload);
var type = ref.type;
var payload = ref.payload;
+ var action = { type: type, payload: payload };
var entry = this._actions[type];
if (!entry) {
- console.error(("[vuex] unknown action type: " + type));
+ {
+ console.error(("[vuex] unknown action type: " + type));
+ }
return
}
+
+ this._actionSubscribers.forEach(function (sub) { return sub(action, this$1.state); });
+
return entry.length > 1
? Promise.all(entry.map(function (handler) { return handler(payload); }))
: entry[0](payload)
};
Store.prototype.subscribe = function subscribe (fn) {
- var subs = this._subscribers;
- if (subs.indexOf(fn) < 0) {
- subs.push(fn);
- }
- return function () {
- var i = subs.indexOf(fn);
- if (i > -1) {
- subs.splice(i, 1);
- }
- }
+ return genericSubscribe(fn, this._subscribers)
};
+Store.prototype.subscribeAction = function subscribeAction (fn) {
+ return genericSubscribe(fn, this._actionSubscribers)
+};
+
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)
};
Store.prototype.replaceState = function replaceState (state) {
var this$1 = this;
@@ -373,24 +455,35 @@
this._withCommit(function () {
this$1._vm._data.$$state = state;
});
};
-Store.prototype.registerModule = function registerModule (path, rawModule) {
+Store.prototype.registerModule = function registerModule (path, rawModule, options) {
+ if ( options === void 0 ) options = {};
+
if (typeof path === 'string') { path = [path]; }
- assert(Array.isArray(path), "module path must be a string or an Array.");
+
+ {
+ assert(Array.isArray(path), "module path must be a string or an Array.");
+ assert(path.length > 0, 'cannot register the root module by using registerModule.');
+ }
+
this._modules.register(path, rawModule);
- installModule(this, this.state, path, this._modules.get(path));
+ installModule(this, this.state, path, this._modules.get(path), options.preserveState);
// reset store to update getters...
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.");
+
+ {
+ 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]);
});
@@ -409,10 +502,22 @@
this._committing = committing;
};
Object.defineProperties( Store.prototype, prototypeAccessors );
+function genericSubscribe (fn, subs) {
+ if (subs.indexOf(fn) < 0) {
+ subs.push(fn);
+ }
+ return function () {
+ var i = subs.indexOf(fn);
+ if (i > -1) {
+ subs.splice(i, 1);
+ }
+ }
+}
+
function resetStore (store, hot) {
store._actions = Object.create(null);
store._mutations = Object.create(null);
store._wrappedGetters = Object.create(null);
store._modulesNamespaceMap = Object.create(null);
@@ -493,12 +598,13 @@
var namespacedType = namespace + key;
registerMutation(store, namespacedType, mutation, local);
});
module.forEachAction(function (action, key) {
- var namespacedType = namespace + key;
- registerAction(store, namespacedType, action, local);
+ var type = action.root ? key : namespace + key;
+ var handler = action.handler || action;
+ registerAction(store, type, handler, local);
});
module.forEachGetter(function (getter, key) {
var namespacedType = namespace + key;
registerGetter(store, namespacedType, getter, local);
@@ -523,11 +629,11 @@
var options = args.options;
var type = args.type;
if (!options || !options.root) {
type = namespace + type;
- if (!store._actions[type]) {
+ if ("development" !== 'production' && !store._actions[type]) {
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
return
}
}
@@ -540,11 +646,11 @@
var options = args.options;
var type = args.type;
if (!options || !options.root) {
type = namespace + type;
- if (!store._mutations[type]) {
+ if ("development" !== 'production' && !store._mutations[type]) {
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
return
}
}
@@ -592,18 +698,18 @@
}
function registerMutation (store, type, handler, local) {
var entry = store._mutations[type] || (store._mutations[type] = []);
entry.push(function wrappedMutationHandler (payload) {
- handler(local.state, payload);
+ handler.call(store, local.state, payload);
});
}
function registerAction (store, type, handler, local) {
var entry = store._actions[type] || (store._actions[type] = []);
entry.push(function wrappedActionHandler (payload, cb) {
- var res = handler({
+ var res = handler.call(store, {
dispatch: local.dispatch,
commit: local.commit,
getters: local.getters,
state: local.state,
rootGetters: store.getters,
@@ -623,11 +729,13 @@
});
}
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(
local.state, // local state
@@ -638,11 +746,13 @@
};
}
function enableStrictMode (store) {
store._vm.$watch(function () { return this._data.$$state }, function () {
- assert(store._committing, "Do not mutate vuex store state outside mutation handlers.");
+ {
+ assert(store._committing, "Do not mutate vuex store state outside mutation handlers.");
+ }
}, { deep: true, sync: true });
}
function getNestedState (state, path) {
return path.length
@@ -655,31 +765,30 @@
options = payload;
payload = type;
type = type.type;
}
- assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + "."));
+ {
+ assert(typeof type === 'string', ("Expects string as the type, but found " + (typeof type) + "."));
+ }
return { type: type, payload: payload, options: options }
}
function install (_Vue) {
- if (Vue) {
- console.error(
- '[vuex] already installed. Vue.use(Vuex) should be called only once.'
- );
+ if (Vue && _Vue === Vue) {
+ {
+ console.error(
+ '[vuex] already installed. Vue.use(Vuex) should be called only once.'
+ );
+ }
return
}
Vue = _Vue;
applyMixin(Vue);
}
-// auto install in dist mode
-if (typeof window !== 'undefined' && window.Vue) {
- install(window.Vue);
-}
-
var mapState = normalizeNamespace(function (namespace, states) {
var res = {};
normalizeMap(states).forEach(function (ref) {
var key = ref.key;
var val = ref.val;
@@ -709,19 +818,25 @@
var res = {};
normalizeMap(mutations).forEach(function (ref) {
var key = ref.key;
var val = ref.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
+ var commit = this.$store.commit;
+ if (namespace) {
+ var module = getModuleByNamespace(this.$store, 'mapMutations', namespace);
+ if (!module) {
+ return
+ }
+ commit = module.context.commit;
}
- return this.$store.commit.apply(this.$store, [val].concat(args))
+ return typeof val === 'function'
+ ? val.apply(this, [commit].concat(args))
+ : commit.apply(this.$store, [val].concat(args))
};
});
return res
});
@@ -734,11 +849,11 @@
val = namespace + val;
res[key] = function mappedGetter () {
if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) {
return
}
- if (!(val in this.$store.getters)) {
+ if ("development" !== 'production' && !(val in this.$store.getters)) {
console.error(("[vuex] unknown getter: " + val));
return
}
return this.$store.getters[val]
};
@@ -752,24 +867,37 @@
var res = {};
normalizeMap(actions).forEach(function (ref) {
var key = ref.key;
var val = ref.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
+ var dispatch = this.$store.dispatch;
+ if (namespace) {
+ var module = getModuleByNamespace(this.$store, 'mapActions', namespace);
+ if (!module) {
+ return
+ }
+ dispatch = module.context.dispatch;
}
- return this.$store.dispatch.apply(this.$store, [val].concat(args))
+ return typeof val === 'function'
+ ? val.apply(this, [dispatch].concat(args))
+ : dispatch.apply(this.$store, [val].concat(args))
};
});
return res
});
+var createNamespacedHelpers = function (namespace) { return ({
+ mapState: mapState.bind(null, namespace),
+ mapGetters: mapGetters.bind(null, namespace),
+ mapMutations: mapMutations.bind(null, namespace),
+ mapActions: mapActions.bind(null, namespace)
+}); };
+
function normalizeMap (map) {
return Array.isArray(map)
? map.map(function (key) { return ({ key: key, val: key }); })
: Object.keys(map).map(function (key) { return ({ key: key, val: map[key] }); })
}
@@ -786,23 +914,24 @@
}
}
function getModuleByNamespace (store, helper, namespace) {
var module = store._modulesNamespaceMap[namespace];
- if (!module) {
+ if ("development" !== 'production' && !module) {
console.error(("[vuex] module namespace not found in " + helper + "(): " + namespace));
}
return module
}
var index = {
Store: Store,
install: install,
- version: '2.3.0',
+ version: '3.0.1',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
- mapActions: mapActions
+ mapActions: mapActions,
+ createNamespacedHelpers: createNamespacedHelpers
};
return index;
})));