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."); 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(); // bind commit and dispatch to self var store = this; var ref = this; var dispatch = ref.dispatch; var commit = ref.commit; 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; // init root module. // this also recursively registers all sub-modules // and collects all module getters inside this._wrappedGetters 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); // apply plugins plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); }); }
n/a
function install(_Vue) { if (Vue) { console.error( '[vuex] already installed. Vue.use(Vuex) should be called only once.' ); return } Vue = _Vue; applyMixin(Vue); }
n/a
mapActions = function (namespace, map) { if (typeof namespace !== 'string') { map = namespace; namespace = ''; } else if (namespace.charAt(namespace.length - 1) !== '/') { namespace += '/'; } return fn(namespace, map) }
n/a
mapGetters = function (namespace, map) { if (typeof namespace !== 'string') { map = namespace; namespace = ''; } else if (namespace.charAt(namespace.length - 1) !== '/') { namespace += '/'; } return fn(namespace, map) }
n/a
mapMutations = function (namespace, map) { if (typeof namespace !== 'string') { map = namespace; namespace = ''; } else if (namespace.charAt(namespace.length - 1) !== '/') { namespace += '/'; } return fn(namespace, map) }
n/a
mapState = function (namespace, map) { if (typeof namespace !== 'string') { map = namespace; namespace = ''; } else if (namespace.charAt(namespace.length - 1) !== '/') { namespace += '/'; } return fn(namespace, map) }
n/a
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."); 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(); // bind commit and dispatch to self var store = this; var ref = this; var dispatch = ref.dispatch; var commit = ref.commit; 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; // init root module. // this also recursively registers all sub-modules // and collects all module getters inside this._wrappedGetters 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); // apply plugins plugins.concat(devtoolPlugin).forEach(function (plugin) { return plugin(this$1); }); }
n/a
function _withCommit(fn) { var committing = this._committing; this._committing = true; fn(); this._committing = committing; }
...
var mutation = { type: type, payload: payload };
var entry = this._mutations[type];
if (!entry) {
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) {
...
function commit(_type, _payload, _options) { var this$1 = this; // check object-style commit var ref = unifyObjectStyle(_type, _payload, _options); var type = ref.type; var payload = ref.payload; var options = ref.options; var mutation = { type: type, payload: payload }; var entry = this._mutations[type]; if (!entry) { 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) { console.warn( "[vuex] mutation type: " + type + ". Silent option has been removed. " + 'Use the filter functionality in the vue-devtools' ); } }
...
type = namespace + type;
if (!store._mutations[type]) {
console.error(("[vuex] unknown local mutation type: " + (args.type) + ", global type: " + type));
return
}
}
store.commit(type, payload, options);
}
};
// getters and state object must be gotten lazily
// because they will be changed by vm update
Object.defineProperties(local, {
getters: {
...
function dispatch(_type, _payload) { // check object-style dispatch var ref = unifyObjectStyle(_type, _payload); var type = ref.type; var payload = ref.payload; var entry = this._actions[type]; if (!entry) { console.error(("[vuex] unknown action type: " + type)); return } return entry.length > 1 ? Promise.all(entry.map(function (handler) { return handler(payload); })) : entry[0](payload) }
...
type = namespace + type;
if (!store._actions[type]) {
console.error(("[vuex] unknown local action type: " + (args.type) + ", global type: " + type));
return
}
}
return store.dispatch(type, payload)
},
commit: noNamespace ? store.commit : function (_type, _payload, _options) {
var args = unifyObjectStyle(_type, _payload, _options);
var payload = args.payload;
var options = args.options;
var type = args.type;
...
function hotUpdate(newOptions) { this._modules.update(newOptions); resetStore(this, true); }
n/a
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)); // reset store to update getters... resetStoreVM(this, this.state); }
n/a
function replaceState(state) { var this$1 = this; this._withCommit(function () { this$1._vm._data.$$state = state; }); }
...
if (!devtoolHook) { return }
store._devtoolHook = devtoolHook;
devtoolHook.emit('vuex:init', store);
devtoolHook.on('vuex:travel-to-state', function (targetState) {
store.replaceState(targetState);
});
store.subscribe(function (mutation, state) {
devtoolHook.emit('vuex:mutation', mutation, state);
});
}
...
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); } } }
...
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true;
var transformer = ref.transformer; if ( transformer === void 0 ) transformer = function (state) { return state; };
var mutationTransformer = ref.mutationTransformer; if ( mutationTransformer === void 0 ) mutationTransformer = function (mut) {
return mut; };
return function (store) {
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);
...
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); this._withCommit(function () { var parentState = getNestedState(this$1.state, path.slice(0, -1)); Vue.delete(parentState, path[path.length - 1]); }); resetStore(this); }
n/a
function watch(getter, cb, options) { var this$1 = this; 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) }
n/a