From 3d088ecb2309c5f233d281cffed0e09cce959dda Mon Sep 17 00:00:00 2001 From: Sean Larkin Date: Fri, 27 Apr 2018 23:20:17 -0500 Subject: [PATCH] chore(package.json): add sideEffects: false field to package.json --- dist/vuex.common.js | 75 +++++++++++++++++++++++++++++++++++++++------ package.json | 1 + 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/dist/vuex.common.js b/dist/vuex.common.js index 8a0b2ab0e..6ffe95c40 100644 --- a/dist/vuex.common.js +++ b/dist/vuex.common.js @@ -1,6 +1,6 @@ /** * vuex v3.0.1 - * (c) 2017 Evan You + * (c) 2018 Evan You * @license MIT */ 'use strict'; @@ -69,6 +69,8 @@ function devtoolPlugin (store) { * @param {Function} f * @return {*} */ + + /** * Deep copy the given object considering circular structure. * This function caches all nested objects and its copies. @@ -99,11 +101,16 @@ function assert (condition, msg) { if (!condition) { throw new Error(("[vuex] " + msg)) } } +// Base data struct for store's module, package with some attribute and method var Module = function Module (rawModule, runtime) { this.runtime = runtime; + // Store some children item this._children = Object.create(null); + // Store the origin module object which passed by programmer this._rawModule = rawModule; var rawState = rawModule.state; + + // Store the origin module's state this.state = (typeof rawState === 'function' ? rawState() : rawState) || {}; }; @@ -303,17 +310,12 @@ var Store = function Store (options) { if (process.env.NODE_ENV !== 'production') { 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."); + 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); @@ -340,6 +342,8 @@ var Store = function Store (options) { // strict mode this.strict = strict; + var state = this._modules.root.state; + // init root module. // this also recursively registers all sub-modules // and collects all module getters inside this._wrappedGetters @@ -365,7 +369,7 @@ prototypeAccessors.state.get = function () { prototypeAccessors.state.set = function (v) { if (process.env.NODE_ENV !== 'production') { - assert(false, "Use store.replaceState() to explicit replace store state."); + assert(false, "use store.replaceState() to explicit replace store state."); } }; @@ -745,7 +749,7 @@ function registerGetter (store, type, rawGetter, local) { function enableStrictMode (store) { store._vm.$watch(function () { return this._data.$$state }, function () { if (process.env.NODE_ENV !== 'production') { - 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 }); } @@ -764,7 +768,7 @@ function unifyObjectStyle (type, payload, options) { } if (process.env.NODE_ENV !== 'production') { - 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 } @@ -783,6 +787,12 @@ function install (_Vue) { applyMixin(Vue); } +/** + * Reduce the code which written in Vue.js for getting the state. + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} states # Object's item can be a function which accept state and getters for param, you can do something for state and getters in it. + * @param {Object} + */ var mapState = normalizeNamespace(function (namespace, states) { var res = {}; normalizeMap(states).forEach(function (ref) { @@ -810,6 +820,12 @@ var mapState = normalizeNamespace(function (namespace, states) { return res }); +/** + * Reduce the code which written in Vue.js for committing the mutation + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} mutations # Object's item can be a function which accept `commit` function as the first param, it can accept anthor params. You can commit mutation and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ var mapMutations = normalizeNamespace(function (namespace, mutations) { var res = {}; normalizeMap(mutations).forEach(function (ref) { @@ -820,6 +836,7 @@ var mapMutations = normalizeNamespace(function (namespace, mutations) { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; + // Get the commit method from store var commit = this.$store.commit; if (namespace) { var module = getModuleByNamespace(this.$store, 'mapMutations', namespace); @@ -836,12 +853,19 @@ var mapMutations = normalizeNamespace(function (namespace, mutations) { return res }); +/** + * Reduce the code which written in Vue.js for getting the getters + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} getters + * @return {Object} + */ var mapGetters = normalizeNamespace(function (namespace, getters) { var res = {}; normalizeMap(getters).forEach(function (ref) { var key = ref.key; var val = ref.val; + // thie namespace has been mutate by normalizeNamespace val = namespace + val; res[key] = function mappedGetter () { if (namespace && !getModuleByNamespace(this.$store, 'mapGetters', namespace)) { @@ -859,6 +883,12 @@ var mapGetters = normalizeNamespace(function (namespace, getters) { return res }); +/** + * Reduce the code which written in Vue.js for dispatch the action + * @param {String} [namespace] - Module's namespace + * @param {Object|Array} actions # Object's item can be a function which accept `dispatch` function as the first param, it can accept anthor params. You can dispatch action and do any other things in this function. specially, You need to pass anthor params from the mapped function. + * @return {Object} + */ var mapActions = normalizeNamespace(function (namespace, actions) { var res = {}; normalizeMap(actions).forEach(function (ref) { @@ -869,6 +899,7 @@ var mapActions = normalizeNamespace(function (namespace, actions) { var args = [], len = arguments.length; while ( len-- ) args[ len ] = arguments[ len ]; + // get dispatch function from store var dispatch = this.$store.dispatch; if (namespace) { var module = getModuleByNamespace(this.$store, 'mapActions', namespace); @@ -885,6 +916,11 @@ var mapActions = normalizeNamespace(function (namespace, actions) { return res }); +/** + * Rebinding namespace param for mapXXX function in special scoped, and return them by simple object + * @param {String} namespace + * @return {Object} + */ var createNamespacedHelpers = function (namespace) { return ({ mapState: mapState.bind(null, namespace), mapGetters: mapGetters.bind(null, namespace), @@ -892,12 +928,24 @@ var createNamespacedHelpers = function (namespace) { return ({ mapActions: mapActions.bind(null, namespace) }); }; +/** + * Normalize the map + * normalizeMap([1, 2, 3]) => [ { key: 1, val: 1 }, { key: 2, val: 2 }, { key: 3, val: 3 } ] + * normalizeMap({a: 1, b: 2, c: 3}) => [ { key: 'a', val: 1 }, { key: 'b', val: 2 }, { key: 'c', val: 3 } ] + * @param {Array|Object} map + * @return {Object} + */ 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] }); }) } +/** + * Return a function expect two param contains namespace and map. it will normalize the namespace and then the param's function will handle the new namespace and the map. + * @param {Function} fn + * @return {Function} + */ function normalizeNamespace (fn) { return function (namespace, map) { if (typeof namespace !== 'string') { @@ -910,6 +958,13 @@ function normalizeNamespace (fn) { } } +/** + * Search a special module from store by namespace. if module not exist, print error message. + * @param {Object} store + * @param {String} helper + * @param {String} namespace + * @return {Object} + */ function getModuleByNamespace (store, helper, namespace) { var module = store._modulesNamespaceMap[namespace]; if (process.env.NODE_ENV !== 'production' && !module) { diff --git a/package.json b/package.json index 700927af3..8f7591286 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "module": "dist/vuex.esm.js", "unpkg": "dist/vuex.js", "typings": "types/index.d.ts", + "sideEffects": false, "files": [ "dist", "types/index.d.ts",