Skip to content

chore(package.json): add sideEffects: false field to package.json #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 65 additions & 10 deletions dist/vuex.common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* vuex v3.0.1
* (c) 2017 Evan You
* (c) 2018 Evan You
* @license MIT
*/
'use strict';
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) || {};
};

Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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.");
}
};

Expand Down Expand Up @@ -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 });
}
Expand All @@ -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 }
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -885,19 +916,36 @@ 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),
mapMutations: mapMutations.bind(null, namespace),
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') {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down