|
@@ -1,5 +1,5 @@
|
|
/**
|
|
/**
|
|
- * vuex v2.4.1
|
|
|
|
|
|
+ * vuex v2.5.0
|
|
* (c) 2017 Evan You
|
|
* (c) 2017 Evan You
|
|
* @license MIT
|
|
* @license MIT
|
|
*/
|
|
*/
|
|
@@ -246,26 +246,44 @@ function update (path, targetModule, newModule) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+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) {
|
|
function assertRawModule (path, rawModule) {
|
|
- ['getters', 'actions', 'mutations'].forEach(function (key) {
|
|
|
|
|
|
+ Object.keys(assertTypes).forEach(function (key) {
|
|
if (!rawModule[key]) { return }
|
|
if (!rawModule[key]) { return }
|
|
|
|
|
|
|
|
+ var assertOptions = assertTypes[key];
|
|
|
|
+
|
|
forEachValue(rawModule[key], function (value, type) {
|
|
forEachValue(rawModule[key], function (value, type) {
|
|
assert(
|
|
assert(
|
|
- typeof value === 'function',
|
|
|
|
- makeAssertionMessage(path, key, type, value)
|
|
|
|
|
|
+ assertOptions.assert(value),
|
|
|
|
+ makeAssertionMessage(path, key, type, value, assertOptions.expected)
|
|
);
|
|
);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-function makeAssertionMessage (path, key, type, value) {
|
|
|
|
- var buf = key + " should be function but \"" + key + "." + type + "\"";
|
|
|
|
|
|
+function makeAssertionMessage (path, key, type, value, expected) {
|
|
|
|
+ var buf = key + " should be " + expected + " but \"" + key + "." + type + "\"";
|
|
if (path.length > 0) {
|
|
if (path.length > 0) {
|
|
buf += " in module \"" + (path.join('.')) + "\"";
|
|
buf += " in module \"" + (path.join('.')) + "\"";
|
|
}
|
|
}
|
|
buf += " is " + (JSON.stringify(value)) + ".";
|
|
buf += " is " + (JSON.stringify(value)) + ".";
|
|
-
|
|
|
|
return buf
|
|
return buf
|
|
}
|
|
}
|
|
|
|
|
|
@@ -293,12 +311,13 @@ var Store = function Store (options) {
|
|
|
|
|
|
var state = options.state; if ( state === void 0 ) state = {};
|
|
var state = options.state; if ( state === void 0 ) state = {};
|
|
if (typeof state === 'function') {
|
|
if (typeof state === 'function') {
|
|
- state = state();
|
|
|
|
|
|
+ state = state() || {};
|
|
}
|
|
}
|
|
|
|
|
|
// store internal state
|
|
// store internal state
|
|
this._committing = false;
|
|
this._committing = false;
|
|
this._actions = Object.create(null);
|
|
this._actions = Object.create(null);
|
|
|
|
+ this._actionSubscribers = [];
|
|
this._mutations = Object.create(null);
|
|
this._mutations = Object.create(null);
|
|
this._wrappedGetters = Object.create(null);
|
|
this._wrappedGetters = Object.create(null);
|
|
this._modules = new ModuleCollection(options);
|
|
this._modules = new ModuleCollection(options);
|
|
@@ -386,11 +405,14 @@ Store.prototype.commit = function commit (_type, _payload, _options) {
|
|
};
|
|
};
|
|
|
|
|
|
Store.prototype.dispatch = function dispatch (_type, _payload) {
|
|
Store.prototype.dispatch = function dispatch (_type, _payload) {
|
|
|
|
+ var this$1 = this;
|
|
|
|
+
|
|
// check object-style dispatch
|
|
// check object-style dispatch
|
|
var ref = unifyObjectStyle(_type, _payload);
|
|
var ref = unifyObjectStyle(_type, _payload);
|
|
var type = ref.type;
|
|
var type = ref.type;
|
|
var payload = ref.payload;
|
|
var payload = ref.payload;
|
|
|
|
|
|
|
|
+ var action = { type: type, payload: payload };
|
|
var entry = this._actions[type];
|
|
var entry = this._actions[type];
|
|
if (!entry) {
|
|
if (!entry) {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -398,22 +420,20 @@ Store.prototype.dispatch = function dispatch (_type, _payload) {
|
|
}
|
|
}
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ this._actionSubscribers.forEach(function (sub) { return sub(action, this$1.state); });
|
|
|
|
+
|
|
return entry.length > 1
|
|
return entry.length > 1
|
|
? Promise.all(entry.map(function (handler) { return handler(payload); }))
|
|
? Promise.all(entry.map(function (handler) { return handler(payload); }))
|
|
: entry[0](payload)
|
|
: entry[0](payload)
|
|
};
|
|
};
|
|
|
|
|
|
Store.prototype.subscribe = function subscribe (fn) {
|
|
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) {
|
|
Store.prototype.watch = function watch (getter, cb, options) {
|
|
@@ -433,7 +453,9 @@ Store.prototype.replaceState = function replaceState (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]; }
|
|
if (typeof path === 'string') { path = [path]; }
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -442,7 +464,7 @@ Store.prototype.registerModule = function registerModule (path, rawModule) {
|
|
}
|
|
}
|
|
|
|
|
|
this._modules.register(path, rawModule);
|
|
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...
|
|
// reset store to update getters...
|
|
resetStoreVM(this, this.state);
|
|
resetStoreVM(this, this.state);
|
|
};
|
|
};
|
|
@@ -478,6 +500,18 @@ Store.prototype._withCommit = function _withCommit (fn) {
|
|
|
|
|
|
Object.defineProperties( Store.prototype, prototypeAccessors );
|
|
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) {
|
|
function resetStore (store, hot) {
|
|
store._actions = Object.create(null);
|
|
store._actions = Object.create(null);
|
|
store._mutations = Object.create(null);
|
|
store._mutations = Object.create(null);
|
|
@@ -562,8 +596,9 @@ function installModule (store, rootState, path, module, hot) {
|
|
});
|
|
});
|
|
|
|
|
|
module.forEachAction(function (action, key) {
|
|
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) {
|
|
module.forEachGetter(function (getter, key) {
|
|
@@ -886,7 +921,7 @@ function getModuleByNamespace (store, helper, namespace) {
|
|
var index = {
|
|
var index = {
|
|
Store: Store,
|
|
Store: Store,
|
|
install: install,
|
|
install: install,
|
|
- version: '2.4.1',
|
|
|
|
|
|
+ version: '2.5.0',
|
|
mapState: mapState,
|
|
mapState: mapState,
|
|
mapMutations: mapMutations,
|
|
mapMutations: mapMutations,
|
|
mapGetters: mapGetters,
|
|
mapGetters: mapGetters,
|