Comparing version 4.0.0-beta.2 to 4.0.0-beta.3
@@ -1,10 +0,28 @@ | ||
# [4.0.0-beta.2](https://github.com/vuejs/vuex/compare/v4.0.0-beta.1...v4.0.0-beta.2) (2020-05-11) | ||
# [4.0.0-beta.3](https://github.com/vuejs/vuex/compare/v4.0.0-beta.2...v4.0.0-beta.3) (2020-06-29) | ||
### Bug Fixes | ||
* UMD bundle containing `process.env` flag ([#1749](https://github.com/vuejs/vuex/issues/1749)) ([0fea8c4](https://github.com/vuejs/vuex/commit/0fea8c44060d08b3b421f1ddaa809fdffbc89b00)) | ||
### Features | ||
* Allow action subscribers to catch rejections. ([#1740](https://github.com/vuejs/vuex/issues/1740)) ([6ebbe64](https://github.com/vuejs/vuex/commit/6ebbe64c5821d19e55a41dc8b1d81cfce6cbd195)), closes [#1489](https://github.com/vuejs/vuex/issues/1489) [#1558](https://github.com/vuejs/vuex/issues/1558) [#1625](https://github.com/vuejs/vuex/issues/1625) | ||
* include `createLogger` function in core export ([afa566d](https://github.com/vuejs/vuex/commit/afa566d7f7b8e516389463b437fbfcb9eafdbd1b)) | ||
* include logger plugin to the core export ([#1783](https://github.com/vuejs/vuex/issues/1783)) ([04e2bd8](https://github.com/vuejs/vuex/commit/04e2bd8b3509c67398a6fe73a3d53660069feca8)) | ||
# [3.4.0](https://github.com/vuejs/vuex/compare/4.0.0-beta.2...v3.4.0) (2020-05-11) | ||
# [4.0.0-beta.2](https://github.com/vuejs/vuex/compare/v4.0.0-beta.1...v4.0.0-beta.2) (2020-05-11) | ||
### Bug Fixes | ||
- types: add `useStore` function ([#1736](https://github.com/vuejs/vuex/issues/1736)) [#1739](https://github.com/vuejs/vuex/issues/1736) | ||
- build: fix `iife` build containing `process.env`. | ||
# [4.0.0-beta.1](https://github.com/vuejs/vuex/compare/v3.3.0...v4.0.0-beta.1) (2020-04-25) | ||
@@ -109,2 +127,10 @@ | ||
# [3.4.0](https://github.com/vuejs/vuex/compare/v3.3.0...v3.4.0) (2020-05-11) | ||
### Features | ||
* Allow action subscribers to catch rejections. ([#1740](https://github.com/vuejs/vuex/issues/1740)) ([6ebbe64](https://github.com/vuejs/vuex/commit/6ebbe64c5821d19e55a41dc8b1d81cfce6cbd195)), closes [#1489](https://github.com/vuejs/vuex/issues/1489) [#1558](https://github.com/vuejs/vuex/issues/1558) [#1625](https://github.com/vuejs/vuex/issues/1625) | ||
# [3.3.0](https://github.com/vuejs/vuex/compare/v3.2.0...v3.3.0) (2020-04-25) | ||
@@ -111,0 +137,0 @@ |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
@@ -53,4 +53,45 @@ * @license MIT | ||
*/ | ||
function find (list, f) { | ||
return list.filter(f)[0] | ||
} | ||
/** | ||
* Deep copy the given object considering circular structure. | ||
* This function caches all nested objects and its copies. | ||
* If it detects circular structure, use cached copy to avoid infinite loop. | ||
* | ||
* @param {*} obj | ||
* @param {Array<Object>} cache | ||
* @return {*} | ||
*/ | ||
function deepCopy (obj, cache) { | ||
if ( cache === void 0 ) cache = []; | ||
// just return if obj is immutable value | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// if obj is hit, it is in circular structure | ||
var hit = find(cache, function (c) { return c.original === obj; }); | ||
if (hit) { | ||
return hit.copy | ||
} | ||
var copy = Array.isArray(obj) ? [] : {}; | ||
// put the copy into cache at first | ||
// because we want to refer it in recursive deepCopy | ||
cache.push({ | ||
original: obj, | ||
copy: copy | ||
}); | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = deepCopy(obj[key], cache); | ||
}); | ||
return copy | ||
} | ||
/** | ||
* forEach for object | ||
@@ -292,3 +333,3 @@ */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); | ||
@@ -1033,4 +1074,95 @@ assert(this instanceof Store, "store must be called with the new operator."); | ||
// Credits: borrowed code from fcomb/redux-logger | ||
function createLogger (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; | ||
var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return 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; }; | ||
var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; | ||
var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; | ||
var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; | ||
var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; | ||
var logger = ref.logger; if ( logger === void 0 ) logger = console; | ||
return function (store) { | ||
var prevState = deepCopy(store.state); | ||
if (typeof logger === 'undefined') { | ||
return | ||
} | ||
if (logMutations) { | ||
store.subscribe(function (mutation, state) { | ||
var nextState = deepCopy(state); | ||
if (filter(mutation, prevState, nextState)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedMutation = mutationTransformer(mutation); | ||
var message = "mutation " + (mutation.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); | ||
logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); | ||
logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); | ||
endMessage(logger); | ||
} | ||
prevState = nextState; | ||
}); | ||
} | ||
if (logActions) { | ||
store.subscribeAction(function (action, state) { | ||
if (actionFilter(action, state)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedAction = actionTransformer(action); | ||
var message = "action " + (action.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); | ||
endMessage(logger); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function startMessage (logger, message, collapsed) { | ||
var startMessage = collapsed | ||
? logger.groupCollapsed | ||
: logger.group; | ||
// render | ||
try { | ||
startMessage.call(logger, message); | ||
} catch (e) { | ||
logger.log(message); | ||
} | ||
} | ||
function endMessage (logger) { | ||
try { | ||
logger.groupEnd(); | ||
} catch (e) { | ||
logger.log('—— log end ——'); | ||
} | ||
} | ||
function getFormattedTime () { | ||
var time = new Date(); | ||
return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) | ||
} | ||
function repeat (str, times) { | ||
return (new Array(times + 1)).join(str) | ||
} | ||
function pad (num, maxLength) { | ||
return repeat('0', maxLength - num.toString().length) + num | ||
} | ||
var index_cjs = { | ||
version: '4.0.0-beta.2', | ||
version: '4.0.0-beta.3', | ||
createStore: createStore, | ||
@@ -1043,5 +1175,6 @@ Store: Store, | ||
mapActions: mapActions, | ||
createNamespacedHelpers: createNamespacedHelpers | ||
createNamespacedHelpers: createNamespacedHelpers, | ||
createLogger: createLogger | ||
}; | ||
module.exports = index_cjs; |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
@@ -51,4 +51,45 @@ * @license MIT | ||
*/ | ||
function find (list, f) { | ||
return list.filter(f)[0] | ||
} | ||
/** | ||
* Deep copy the given object considering circular structure. | ||
* This function caches all nested objects and its copies. | ||
* If it detects circular structure, use cached copy to avoid infinite loop. | ||
* | ||
* @param {*} obj | ||
* @param {Array<Object>} cache | ||
* @return {*} | ||
*/ | ||
function deepCopy (obj, cache) { | ||
if ( cache === void 0 ) cache = []; | ||
// just return if obj is immutable value | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// if obj is hit, it is in circular structure | ||
var hit = find(cache, function (c) { return c.original === obj; }); | ||
if (hit) { | ||
return hit.copy | ||
} | ||
var copy = Array.isArray(obj) ? [] : {}; | ||
// put the copy into cache at first | ||
// because we want to refer it in recursive deepCopy | ||
cache.push({ | ||
original: obj, | ||
copy: copy | ||
}); | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = deepCopy(obj[key], cache); | ||
}); | ||
return copy | ||
} | ||
/** | ||
* forEach for object | ||
@@ -290,3 +331,3 @@ */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
{ | ||
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); | ||
@@ -1031,4 +1072,95 @@ assert(this instanceof Store, "store must be called with the new operator."); | ||
// Credits: borrowed code from fcomb/redux-logger | ||
function createLogger (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; | ||
var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return 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; }; | ||
var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; | ||
var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; | ||
var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; | ||
var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; | ||
var logger = ref.logger; if ( logger === void 0 ) logger = console; | ||
return function (store) { | ||
var prevState = deepCopy(store.state); | ||
if (typeof logger === 'undefined') { | ||
return | ||
} | ||
if (logMutations) { | ||
store.subscribe(function (mutation, state) { | ||
var nextState = deepCopy(state); | ||
if (filter(mutation, prevState, nextState)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedMutation = mutationTransformer(mutation); | ||
var message = "mutation " + (mutation.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); | ||
logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); | ||
logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); | ||
endMessage(logger); | ||
} | ||
prevState = nextState; | ||
}); | ||
} | ||
if (logActions) { | ||
store.subscribeAction(function (action, state) { | ||
if (actionFilter(action, state)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedAction = actionTransformer(action); | ||
var message = "action " + (action.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); | ||
endMessage(logger); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function startMessage (logger, message, collapsed) { | ||
var startMessage = collapsed | ||
? logger.groupCollapsed | ||
: logger.group; | ||
// render | ||
try { | ||
startMessage.call(logger, message); | ||
} catch (e) { | ||
logger.log(message); | ||
} | ||
} | ||
function endMessage (logger) { | ||
try { | ||
logger.groupEnd(); | ||
} catch (e) { | ||
logger.log('—— log end ——'); | ||
} | ||
} | ||
function getFormattedTime () { | ||
var time = new Date(); | ||
return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) | ||
} | ||
function repeat (str, times) { | ||
return (new Array(times + 1)).join(str) | ||
} | ||
function pad (num, maxLength) { | ||
return repeat('0', maxLength - num.toString().length) + num | ||
} | ||
var index = { | ||
version: '4.0.0-beta.2', | ||
version: '4.0.0-beta.3', | ||
createStore: createStore, | ||
@@ -1041,6 +1173,7 @@ Store: Store, | ||
mapActions: mapActions, | ||
createNamespacedHelpers: createNamespacedHelpers | ||
createNamespacedHelpers: createNamespacedHelpers, | ||
createLogger: createLogger | ||
}; | ||
export default index; | ||
export { Store, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; | ||
export { Store, createLogger, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
@@ -51,4 +51,45 @@ * @license MIT | ||
*/ | ||
function find (list, f) { | ||
return list.filter(f)[0] | ||
} | ||
/** | ||
* Deep copy the given object considering circular structure. | ||
* This function caches all nested objects and its copies. | ||
* If it detects circular structure, use cached copy to avoid infinite loop. | ||
* | ||
* @param {*} obj | ||
* @param {Array<Object>} cache | ||
* @return {*} | ||
*/ | ||
function deepCopy (obj, cache) { | ||
if ( cache === void 0 ) cache = []; | ||
// just return if obj is immutable value | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// if obj is hit, it is in circular structure | ||
var hit = find(cache, function (c) { return c.original === obj; }); | ||
if (hit) { | ||
return hit.copy | ||
} | ||
var copy = Array.isArray(obj) ? [] : {}; | ||
// put the copy into cache at first | ||
// because we want to refer it in recursive deepCopy | ||
cache.push({ | ||
original: obj, | ||
copy: copy | ||
}); | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = deepCopy(obj[key], cache); | ||
}); | ||
return copy | ||
} | ||
/** | ||
* forEach for object | ||
@@ -68,6 +109,2 @@ */ | ||
function assert (condition, msg) { | ||
if (!condition) { throw new Error(("[vuex] " + msg)) } | ||
} | ||
function partial (fn, arg) { | ||
@@ -237,7 +274,2 @@ return function () { | ||
if (process.env.NODE_ENV !== 'production') { | ||
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 = []; | ||
@@ -885,4 +917,95 @@ var strict = options.strict; if ( strict === void 0 ) strict = false; | ||
// Credits: borrowed code from fcomb/redux-logger | ||
function createLogger (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; | ||
var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return 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; }; | ||
var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; | ||
var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; | ||
var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; | ||
var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; | ||
var logger = ref.logger; if ( logger === void 0 ) logger = console; | ||
return function (store) { | ||
var prevState = deepCopy(store.state); | ||
if (typeof logger === 'undefined') { | ||
return | ||
} | ||
if (logMutations) { | ||
store.subscribe(function (mutation, state) { | ||
var nextState = deepCopy(state); | ||
if (filter(mutation, prevState, nextState)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedMutation = mutationTransformer(mutation); | ||
var message = "mutation " + (mutation.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); | ||
logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); | ||
logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); | ||
endMessage(logger); | ||
} | ||
prevState = nextState; | ||
}); | ||
} | ||
if (logActions) { | ||
store.subscribeAction(function (action, state) { | ||
if (actionFilter(action, state)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedAction = actionTransformer(action); | ||
var message = "action " + (action.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); | ||
endMessage(logger); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function startMessage (logger, message, collapsed) { | ||
var startMessage = collapsed | ||
? logger.groupCollapsed | ||
: logger.group; | ||
// render | ||
try { | ||
startMessage.call(logger, message); | ||
} catch (e) { | ||
logger.log(message); | ||
} | ||
} | ||
function endMessage (logger) { | ||
try { | ||
logger.groupEnd(); | ||
} catch (e) { | ||
logger.log('—— log end ——'); | ||
} | ||
} | ||
function getFormattedTime () { | ||
var time = new Date(); | ||
return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) | ||
} | ||
function repeat (str, times) { | ||
return (new Array(times + 1)).join(str) | ||
} | ||
function pad (num, maxLength) { | ||
return repeat('0', maxLength - num.toString().length) + num | ||
} | ||
var index = { | ||
version: '4.0.0-beta.2', | ||
version: '4.0.0-beta.3', | ||
createStore: createStore, | ||
@@ -895,6 +1018,7 @@ Store: Store, | ||
mapActions: mapActions, | ||
createNamespacedHelpers: createNamespacedHelpers | ||
createNamespacedHelpers: createNamespacedHelpers, | ||
createLogger: createLogger | ||
}; | ||
export default index; | ||
export { Store, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; | ||
export { Store, createLogger, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
@@ -51,4 +51,45 @@ * @license MIT | ||
*/ | ||
function find (list, f) { | ||
return list.filter(f)[0] | ||
} | ||
/** | ||
* Deep copy the given object considering circular structure. | ||
* This function caches all nested objects and its copies. | ||
* If it detects circular structure, use cached copy to avoid infinite loop. | ||
* | ||
* @param {*} obj | ||
* @param {Array<Object>} cache | ||
* @return {*} | ||
*/ | ||
function deepCopy (obj, cache) { | ||
if ( cache === void 0 ) cache = []; | ||
// just return if obj is immutable value | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// if obj is hit, it is in circular structure | ||
var hit = find(cache, function (c) { return c.original === obj; }); | ||
if (hit) { | ||
return hit.copy | ||
} | ||
var copy = Array.isArray(obj) ? [] : {}; | ||
// put the copy into cache at first | ||
// because we want to refer it in recursive deepCopy | ||
cache.push({ | ||
original: obj, | ||
copy: copy | ||
}); | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = deepCopy(obj[key], cache); | ||
}); | ||
return copy | ||
} | ||
/** | ||
* forEach for object | ||
@@ -290,3 +331,3 @@ */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
if ((process.env.NODE_ENV !== 'production')) { | ||
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); | ||
@@ -1031,4 +1072,95 @@ assert(this instanceof Store, "store must be called with the new operator."); | ||
// Credits: borrowed code from fcomb/redux-logger | ||
function createLogger (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; | ||
var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return 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; }; | ||
var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; | ||
var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; | ||
var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; | ||
var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; | ||
var logger = ref.logger; if ( logger === void 0 ) logger = console; | ||
return function (store) { | ||
var prevState = deepCopy(store.state); | ||
if (typeof logger === 'undefined') { | ||
return | ||
} | ||
if (logMutations) { | ||
store.subscribe(function (mutation, state) { | ||
var nextState = deepCopy(state); | ||
if (filter(mutation, prevState, nextState)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedMutation = mutationTransformer(mutation); | ||
var message = "mutation " + (mutation.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); | ||
logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); | ||
logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); | ||
endMessage(logger); | ||
} | ||
prevState = nextState; | ||
}); | ||
} | ||
if (logActions) { | ||
store.subscribeAction(function (action, state) { | ||
if (actionFilter(action, state)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedAction = actionTransformer(action); | ||
var message = "action " + (action.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); | ||
endMessage(logger); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function startMessage (logger, message, collapsed) { | ||
var startMessage = collapsed | ||
? logger.groupCollapsed | ||
: logger.group; | ||
// render | ||
try { | ||
startMessage.call(logger, message); | ||
} catch (e) { | ||
logger.log(message); | ||
} | ||
} | ||
function endMessage (logger) { | ||
try { | ||
logger.groupEnd(); | ||
} catch (e) { | ||
logger.log('—— log end ——'); | ||
} | ||
} | ||
function getFormattedTime () { | ||
var time = new Date(); | ||
return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) | ||
} | ||
function repeat (str, times) { | ||
return (new Array(times + 1)).join(str) | ||
} | ||
function pad (num, maxLength) { | ||
return repeat('0', maxLength - num.toString().length) + num | ||
} | ||
var index = { | ||
version: '4.0.0-beta.2', | ||
version: '4.0.0-beta.3', | ||
createStore: createStore, | ||
@@ -1041,6 +1173,7 @@ Store: Store, | ||
mapActions: mapActions, | ||
createNamespacedHelpers: createNamespacedHelpers | ||
createNamespacedHelpers: createNamespacedHelpers, | ||
createLogger: createLogger | ||
}; | ||
export default index; | ||
export { Store, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; | ||
export { Store, createLogger, createNamespacedHelpers, createStore, mapActions, mapGetters, mapMutations, mapState, useStore }; |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
@@ -52,4 +52,45 @@ * @license MIT | ||
*/ | ||
function find (list, f) { | ||
return list.filter(f)[0] | ||
} | ||
/** | ||
* Deep copy the given object considering circular structure. | ||
* This function caches all nested objects and its copies. | ||
* If it detects circular structure, use cached copy to avoid infinite loop. | ||
* | ||
* @param {*} obj | ||
* @param {Array<Object>} cache | ||
* @return {*} | ||
*/ | ||
function deepCopy (obj, cache) { | ||
if ( cache === void 0 ) cache = []; | ||
// just return if obj is immutable value | ||
if (obj === null || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// if obj is hit, it is in circular structure | ||
var hit = find(cache, function (c) { return c.original === obj; }); | ||
if (hit) { | ||
return hit.copy | ||
} | ||
var copy = Array.isArray(obj) ? [] : {}; | ||
// put the copy into cache at first | ||
// because we want to refer it in recursive deepCopy | ||
cache.push({ | ||
original: obj, | ||
copy: copy | ||
}); | ||
Object.keys(obj).forEach(function (key) { | ||
copy[key] = deepCopy(obj[key], cache); | ||
}); | ||
return copy | ||
} | ||
/** | ||
* forEach for object | ||
@@ -291,3 +332,3 @@ */ | ||
if (process.env.NODE_ENV !== 'production') { | ||
{ | ||
assert(typeof Promise !== 'undefined', "vuex requires a Promise polyfill in this browser."); | ||
@@ -1032,4 +1073,95 @@ assert(this instanceof Store, "store must be called with the new operator."); | ||
// Credits: borrowed code from fcomb/redux-logger | ||
function createLogger (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var collapsed = ref.collapsed; if ( collapsed === void 0 ) collapsed = true; | ||
var filter = ref.filter; if ( filter === void 0 ) filter = function (mutation, stateBefore, stateAfter) { return 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; }; | ||
var actionFilter = ref.actionFilter; if ( actionFilter === void 0 ) actionFilter = function (action, state) { return true; }; | ||
var actionTransformer = ref.actionTransformer; if ( actionTransformer === void 0 ) actionTransformer = function (act) { return act; }; | ||
var logMutations = ref.logMutations; if ( logMutations === void 0 ) logMutations = true; | ||
var logActions = ref.logActions; if ( logActions === void 0 ) logActions = true; | ||
var logger = ref.logger; if ( logger === void 0 ) logger = console; | ||
return function (store) { | ||
var prevState = deepCopy(store.state); | ||
if (typeof logger === 'undefined') { | ||
return | ||
} | ||
if (logMutations) { | ||
store.subscribe(function (mutation, state) { | ||
var nextState = deepCopy(state); | ||
if (filter(mutation, prevState, nextState)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedMutation = mutationTransformer(mutation); | ||
var message = "mutation " + (mutation.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState)); | ||
logger.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation); | ||
logger.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState)); | ||
endMessage(logger); | ||
} | ||
prevState = nextState; | ||
}); | ||
} | ||
if (logActions) { | ||
store.subscribeAction(function (action, state) { | ||
if (actionFilter(action, state)) { | ||
var formattedTime = getFormattedTime(); | ||
var formattedAction = actionTransformer(action); | ||
var message = "action " + (action.type) + formattedTime; | ||
startMessage(logger, message, collapsed); | ||
logger.log('%c action', 'color: #03A9F4; font-weight: bold', formattedAction); | ||
endMessage(logger); | ||
} | ||
}); | ||
} | ||
} | ||
} | ||
function startMessage (logger, message, collapsed) { | ||
var startMessage = collapsed | ||
? logger.groupCollapsed | ||
: logger.group; | ||
// render | ||
try { | ||
startMessage.call(logger, message); | ||
} catch (e) { | ||
logger.log(message); | ||
} | ||
} | ||
function endMessage (logger) { | ||
try { | ||
logger.groupEnd(); | ||
} catch (e) { | ||
logger.log('—— log end ——'); | ||
} | ||
} | ||
function getFormattedTime () { | ||
var time = new Date(); | ||
return (" @ " + (pad(time.getHours(), 2)) + ":" + (pad(time.getMinutes(), 2)) + ":" + (pad(time.getSeconds(), 2)) + "." + (pad(time.getMilliseconds(), 3))) | ||
} | ||
function repeat (str, times) { | ||
return (new Array(times + 1)).join(str) | ||
} | ||
function pad (num, maxLength) { | ||
return repeat('0', maxLength - num.toString().length) + num | ||
} | ||
var index_cjs = { | ||
version: '4.0.0-beta.2', | ||
version: '4.0.0-beta.3', | ||
createStore: createStore, | ||
@@ -1042,3 +1174,4 @@ Store: Store, | ||
mapActions: mapActions, | ||
createNamespacedHelpers: createNamespacedHelpers | ||
createNamespacedHelpers: createNamespacedHelpers, | ||
createLogger: createLogger | ||
}; | ||
@@ -1045,0 +1178,0 @@ |
/*! | ||
* vuex v4.0.0-beta.2 | ||
* vuex v4.0.0-beta.3 | ||
* (c) 2020 Evan You | ||
* @license MIT | ||
*/ | ||
var Vuex=function(t){"use strict";var e=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function n(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function r(t){return null!==t&&"object"==typeof t}function o(t,e){if(!t)throw new Error("[vuex] "+e)}var i=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var n=t.state;this.state=("function"==typeof n?n():n)||{}},s={namespaced:{configurable:!0}};s.namespaced.get=function(){return!!this._rawModule.namespaced},i.prototype.addChild=function(t,e){this._children[t]=e},i.prototype.removeChild=function(t){delete this._children[t]},i.prototype.getChild=function(t){return this._children[t]},i.prototype.hasChild=function(t){return t in this._children},i.prototype.update=function(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)},i.prototype.forEachChild=function(t){n(this._children,t)},i.prototype.forEachGetter=function(t){this._rawModule.getters&&n(this._rawModule.getters,t)},i.prototype.forEachAction=function(t){this._rawModule.actions&&n(this._rawModule.actions,t)},i.prototype.forEachMutation=function(t){this._rawModule.mutations&&n(this._rawModule.mutations,t)},Object.defineProperties(i.prototype,s);var a=function(t){this.register([],t,!1)};a.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},a.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},a.prototype.update=function(t){!function t(e,n,r){if(n.update(r),r.modules)for(var o in r.modules){if(!n.getChild(o))return;t(e.concat(o),n.getChild(o),r.modules[o])}}([],this.root,t)},a.prototype.register=function(t,e,r){var o=this;void 0===r&&(r=!0);var s=new i(e,r);0===t.length?this.root=s:this.get(t.slice(0,-1)).addChild(t[t.length-1],s);e.modules&&n(e.modules,(function(e,n){o.register(t.concat(n),e,r)}))},a.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];e.getChild(n).runtime&&e.removeChild(n)},a.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return e.hasChild(n)};var c=function t(n){var r=this;void 0===n&&(n={}),"production"!==process.env.NODE_ENV&&(o("undefined"!=typeof Promise,"vuex requires a Promise polyfill in this browser."),o(this instanceof t,"store must be called with the new operator."));var i=n.plugins;void 0===i&&(i=[]);var s=n.strict;void 0===s&&(s=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new a(n),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null);var c=this,u=this.dispatch,f=this.commit;this.dispatch=function(t,e){return u.call(c,t,e)},this.commit=function(t,e,n){return f.call(c,t,e,n)},this.strict=s;var h=this._modules.root.state;l(this,h,[],this._modules.root),p(this,h),i.forEach((function(t){return t(r)})),(void 0===n.devtools||n.devtools)&&function(t){e&&(t._devtoolHook=e,e.emit("vuex:init",t),e.on("vuex:travel-to-state",(function(e){t.replaceState(e)})),t.subscribe((function(t,n){e.emit("vuex:mutation",t,n)}),{prepend:!0}),t.subscribeAction((function(t,n){e.emit("vuex:action",t,n)}),{prepend:!0}))}(this)},u={state:{configurable:!0}};function f(t,e,n){return e.indexOf(t)<0&&(n&&n.prepend?e.unshift(t):e.push(t)),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}}function h(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var n=t.state;l(t,n,[],t._modules.root,!0),p(t,n,e)}function p(e,r,o){var i=e._state;e.getters={},e._makeLocalGettersCache=Object.create(null);var s=e._wrappedGetters,a={};n(s,(function(n,r){a[r]=function(t,e){return function(){return t(e)}}(n,e),Object.defineProperty(e.getters,r,{get:function(){return t.computed((function(){return a[r]()})).value},enumerable:!0})})),e._state=t.reactive({data:r}),e.strict&&function(e){t.watch((function(){return e._state.data}),(function(){}),{deep:!0,flush:"sync"})}(e),i&&o&&e._withCommit((function(){i.data=null}))}function l(t,e,n,r,o){var i=!n.length,s=t._modules.getNamespace(n);if(r.namespaced&&(t._modulesNamespaceMap[s],t._modulesNamespaceMap[s]=r),!i&&!o){var a=d(e,n.slice(0,-1)),c=n[n.length-1];t._withCommit((function(){a[c]=r.state}))}var u=r.context=function(t,e,n){var r=""===e,o={dispatch:r?t.dispatch:function(n,r,o){var i=m(n,r,o),s=i.payload,a=i.options,c=i.type;return a&&a.root||(c=e+c),t.dispatch(c,s)},commit:r?t.commit:function(n,r,o){var i=m(n,r,o),s=i.payload,a=i.options,c=i.type;a&&a.root||(c=e+c),t.commit(c,s,a)}};return Object.defineProperties(o,{getters:{get:r?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},r=e.length;Object.keys(t.getters).forEach((function(o){if(o.slice(0,r)===e){var i=o.slice(r);Object.defineProperty(n,i,{get:function(){return t.getters[o]},enumerable:!0})}})),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return d(t.state,n)}}}),o}(t,s,n);r.forEachMutation((function(e,n){!function(t,e,n,r){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){n.call(t,r.state,e)}))}(t,s+n,e,u)})),r.forEachAction((function(e,n){var r=e.root?n:s+n,o=e.handler||e;!function(t,e,n,r){(t._actions[e]||(t._actions[e]=[])).push((function(e){var o,i=n.call(t,{dispatch:r.dispatch,commit:r.commit,getters:r.getters,state:r.state,rootGetters:t.getters,rootState:t.state},e);return(o=i)&&"function"==typeof o.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch((function(e){throw t._devtoolHook.emit("vuex:error",e),e})):i}))}(t,r,o,u)})),r.forEachGetter((function(e,n){!function(t,e,n,r){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(r.state,r.getters,t.state,t.getters)}}(t,s+n,e,u)})),r.forEachChild((function(r,i){l(t,e,n.concat(i),r,o)}))}function d(t,e){return e.reduce((function(t,e){return t[e]}),t)}function m(t,e,n){return r(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}c.prototype.install=function(t,e){t.provide(e||"store",this),t.config.globalProperties.$store=this},u.state.get=function(){return this._state.data},u.state.set=function(t){},c.prototype.commit=function(t,e,n){var r=this,o=m(t,e,n),i=o.type,s=o.payload,a={type:i,payload:s},c=this._mutations[i];c&&(this._withCommit((function(){c.forEach((function(t){t(s)}))})),this._subscribers.slice().forEach((function(t){return t(a,r.state)})))},c.prototype.dispatch=function(t,e){var n=this,r=m(t,e),o=r.type,i=r.payload,s={type:o,payload:i},a=this._actions[o];if(a){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(s,n.state)}))}catch(t){}var c=a.length>1?Promise.all(a.map((function(t){return t(i)}))):a[0](i);return new Promise((function(t,e){c.then((function(e){try{n._actionSubscribers.filter((function(t){return t.after})).forEach((function(t){return t.after(s,n.state)}))}catch(t){}t(e)}),(function(t){try{n._actionSubscribers.filter((function(t){return t.error})).forEach((function(e){return e.error(s,n.state,t)}))}catch(t){}e(t)}))}))}},c.prototype.subscribe=function(t,e){return f(t,this._subscribers,e)},c.prototype.subscribeAction=function(t,e){return f("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},c.prototype.watch=function(e,n,r){var o=this;return t.watch((function(){return e(o.state,o.getters)}),n,Object.assign({},r))},c.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._state.data=t}))},c.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),l(this,this.state,t,this._modules.get(t),n.preserveState),p(this,this.state)},c.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){delete d(e.state,t.slice(0,-1))[t[t.length-1]]})),h(this)},c.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},c.prototype.hotUpdate=function(t){this._modules.update(t),h(this,!0)},c.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(c.prototype,u);var v=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var r=O(this.$store,"mapState",t);if(!r)return;e=r.context.state,n=r.context.getters}return"function"==typeof o?o.call(this,e,n):e[o]},n[r].vuex=!0})),n})),_=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.commit;if(t){var i=O(this.$store,"mapMutations",t);if(!i)return;r=i.context.commit}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n})),y=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;o=t+o,n[r]=function(){if(!t||O(this.$store,"mapGetters",t))return this.$store.getters[o]},n[r].vuex=!0})),n})),g=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.dispatch;if(t){var i=O(this.$store,"mapActions",t);if(!i)return;r=i.context.dispatch}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n}));function b(t){return function(t){return Array.isArray(t)||r(t)}(t)?Array.isArray(t)?t.map((function(t){return{key:t,val:t}})):Object.keys(t).map((function(e){return{key:e,val:t[e]}})):[]}function w(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function O(t,e,n){return t._modulesNamespaceMap[n]}return{version:"4.0.0-beta.2",createStore:function(t){return new c(t)},Store:c,useStore:function(e){return void 0===e&&(e=null),t.inject(null!==e?e:"store")},mapState:v,mapMutations:_,mapGetters:y,mapActions:g,createNamespacedHelpers:function(t){return{mapState:v.bind(null,t),mapGetters:y.bind(null,t),mapMutations:_.bind(null,t),mapActions:g.bind(null,t)}}}}(Vue); | ||
var Vuex=function(t){"use strict";var e=("undefined"!=typeof window?window:"undefined"!=typeof global?global:{}).__VUE_DEVTOOLS_GLOBAL_HOOK__;function n(t,e){if(void 0===e&&(e=[]),null===t||"object"!=typeof t)return t;var r,o=(r=function(e){return e.original===t},e.filter(r)[0]);if(o)return o.copy;var i=Array.isArray(t)?[]:{};return e.push({original:t,copy:i}),Object.keys(t).forEach((function(r){i[r]=n(t[r],e)})),i}function r(t,e){Object.keys(t).forEach((function(n){return e(t[n],n)}))}function o(t){return null!==t&&"object"==typeof t}var i=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var n=t.state;this.state=("function"==typeof n?n():n)||{}},a={namespaced:{configurable:!0}};a.namespaced.get=function(){return!!this._rawModule.namespaced},i.prototype.addChild=function(t,e){this._children[t]=e},i.prototype.removeChild=function(t){delete this._children[t]},i.prototype.getChild=function(t){return this._children[t]},i.prototype.hasChild=function(t){return t in this._children},i.prototype.update=function(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)},i.prototype.forEachChild=function(t){r(this._children,t)},i.prototype.forEachGetter=function(t){this._rawModule.getters&&r(this._rawModule.getters,t)},i.prototype.forEachAction=function(t){this._rawModule.actions&&r(this._rawModule.actions,t)},i.prototype.forEachMutation=function(t){this._rawModule.mutations&&r(this._rawModule.mutations,t)},Object.defineProperties(i.prototype,a);var c=function(t){this.register([],t,!1)};c.prototype.get=function(t){return t.reduce((function(t,e){return t.getChild(e)}),this.root)},c.prototype.getNamespace=function(t){var e=this.root;return t.reduce((function(t,n){return t+((e=e.getChild(n)).namespaced?n+"/":"")}),"")},c.prototype.update=function(t){!function t(e,n,r){if(n.update(r),r.modules)for(var o in r.modules){if(!n.getChild(o))return;t(e.concat(o),n.getChild(o),r.modules[o])}}([],this.root,t)},c.prototype.register=function(t,e,n){var o=this;void 0===n&&(n=!0);var a=new i(e,n);0===t.length?this.root=a:this.get(t.slice(0,-1)).addChild(t[t.length-1],a);e.modules&&r(e.modules,(function(e,r){o.register(t.concat(r),e,n)}))},c.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];e.getChild(n).runtime&&e.removeChild(n)},c.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),n=t[t.length-1];return e.hasChild(n)};var s=function(t){var n=this;void 0===t&&(t={});var r=t.plugins;void 0===r&&(r=[]);var o=t.strict;void 0===o&&(o=!1),this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new c(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null);var i=this,a=this.dispatch,s=this.commit;this.dispatch=function(t,e){return a.call(i,t,e)},this.commit=function(t,e,n){return s.call(i,t,e,n)},this.strict=o;var u=this._modules.root.state;p(this,u,[],this._modules.root),h(this,u),r.forEach((function(t){return t(n)})),(void 0===t.devtools||t.devtools)&&function(t){e&&(t._devtoolHook=e,e.emit("vuex:init",t),e.on("vuex:travel-to-state",(function(e){t.replaceState(e)})),t.subscribe((function(t,n){e.emit("vuex:mutation",t,n)}),{prepend:!0}),t.subscribeAction((function(t,n){e.emit("vuex:action",t,n)}),{prepend:!0}))}(this)},u={state:{configurable:!0}};function f(t,e,n){return e.indexOf(t)<0&&(n&&n.prepend?e.unshift(t):e.push(t)),function(){var n=e.indexOf(t);n>-1&&e.splice(n,1)}}function l(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var n=t.state;p(t,n,[],t._modules.root,!0),h(t,n,e)}function h(e,n,o){var i=e._state;e.getters={},e._makeLocalGettersCache=Object.create(null);var a=e._wrappedGetters,c={};r(a,(function(n,r){c[r]=function(t,e){return function(){return t(e)}}(n,e),Object.defineProperty(e.getters,r,{get:function(){return t.computed((function(){return c[r]()})).value},enumerable:!0})})),e._state=t.reactive({data:n}),e.strict&&function(e){t.watch((function(){return e._state.data}),(function(){}),{deep:!0,flush:"sync"})}(e),i&&o&&e._withCommit((function(){i.data=null}))}function p(t,e,n,r,o){var i=!n.length,a=t._modules.getNamespace(n);if(r.namespaced&&(t._modulesNamespaceMap[a],t._modulesNamespaceMap[a]=r),!i&&!o){var c=d(e,n.slice(0,-1)),s=n[n.length-1];t._withCommit((function(){c[s]=r.state}))}var u=r.context=function(t,e,n){var r=""===e,o={dispatch:r?t.dispatch:function(n,r,o){var i=m(n,r,o),a=i.payload,c=i.options,s=i.type;return c&&c.root||(s=e+s),t.dispatch(s,a)},commit:r?t.commit:function(n,r,o){var i=m(n,r,o),a=i.payload,c=i.options,s=i.type;c&&c.root||(s=e+s),t.commit(s,a,c)}};return Object.defineProperties(o,{getters:{get:r?function(){return t.getters}:function(){return function(t,e){if(!t._makeLocalGettersCache[e]){var n={},r=e.length;Object.keys(t.getters).forEach((function(o){if(o.slice(0,r)===e){var i=o.slice(r);Object.defineProperty(n,i,{get:function(){return t.getters[o]},enumerable:!0})}})),t._makeLocalGettersCache[e]=n}return t._makeLocalGettersCache[e]}(t,e)}},state:{get:function(){return d(t.state,n)}}}),o}(t,a,n);r.forEachMutation((function(e,n){!function(t,e,n,r){(t._mutations[e]||(t._mutations[e]=[])).push((function(e){n.call(t,r.state,e)}))}(t,a+n,e,u)})),r.forEachAction((function(e,n){var r=e.root?n:a+n,o=e.handler||e;!function(t,e,n,r){(t._actions[e]||(t._actions[e]=[])).push((function(e){var o,i=n.call(t,{dispatch:r.dispatch,commit:r.commit,getters:r.getters,state:r.state,rootGetters:t.getters,rootState:t.state},e);return(o=i)&&"function"==typeof o.then||(i=Promise.resolve(i)),t._devtoolHook?i.catch((function(e){throw t._devtoolHook.emit("vuex:error",e),e})):i}))}(t,r,o,u)})),r.forEachGetter((function(e,n){!function(t,e,n,r){if(t._wrappedGetters[e])return;t._wrappedGetters[e]=function(t){return n(r.state,r.getters,t.state,t.getters)}}(t,a+n,e,u)})),r.forEachChild((function(r,i){p(t,e,n.concat(i),r,o)}))}function d(t,e){return e.reduce((function(t,e){return t[e]}),t)}function m(t,e,n){return o(t)&&t.type&&(n=e,e=t,t=t.type),{type:t,payload:e,options:n}}s.prototype.install=function(t,e){t.provide(e||"store",this),t.config.globalProperties.$store=this},u.state.get=function(){return this._state.data},u.state.set=function(t){},s.prototype.commit=function(t,e,n){var r=this,o=m(t,e,n),i=o.type,a=o.payload,c={type:i,payload:a},s=this._mutations[i];s&&(this._withCommit((function(){s.forEach((function(t){t(a)}))})),this._subscribers.slice().forEach((function(t){return t(c,r.state)})))},s.prototype.dispatch=function(t,e){var n=this,r=m(t,e),o=r.type,i=r.payload,a={type:o,payload:i},c=this._actions[o];if(c){try{this._actionSubscribers.slice().filter((function(t){return t.before})).forEach((function(t){return t.before(a,n.state)}))}catch(t){}var s=c.length>1?Promise.all(c.map((function(t){return t(i)}))):c[0](i);return new Promise((function(t,e){s.then((function(e){try{n._actionSubscribers.filter((function(t){return t.after})).forEach((function(t){return t.after(a,n.state)}))}catch(t){}t(e)}),(function(t){try{n._actionSubscribers.filter((function(t){return t.error})).forEach((function(e){return e.error(a,n.state,t)}))}catch(t){}e(t)}))}))}},s.prototype.subscribe=function(t,e){return f(t,this._subscribers,e)},s.prototype.subscribeAction=function(t,e){return f("function"==typeof t?{before:t}:t,this._actionSubscribers,e)},s.prototype.watch=function(e,n,r){var o=this;return t.watch((function(){return e(o.state,o.getters)}),n,Object.assign({},r))},s.prototype.replaceState=function(t){var e=this;this._withCommit((function(){e._state.data=t}))},s.prototype.registerModule=function(t,e,n){void 0===n&&(n={}),"string"==typeof t&&(t=[t]),this._modules.register(t,e),p(this,this.state,t,this._modules.get(t),n.preserveState),h(this,this.state)},s.prototype.unregisterModule=function(t){var e=this;"string"==typeof t&&(t=[t]),this._modules.unregister(t),this._withCommit((function(){delete d(e.state,t.slice(0,-1))[t[t.length-1]]})),l(this)},s.prototype.hasModule=function(t){return"string"==typeof t&&(t=[t]),this._modules.isRegistered(t)},s.prototype.hotUpdate=function(t){this._modules.update(t),l(this,!0)},s.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(s.prototype,u);var v=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){var e=this.$store.state,n=this.$store.getters;if(t){var r=M(this.$store,"mapState",t);if(!r)return;e=r.context.state,n=r.context.getters}return"function"==typeof o?o.call(this,e,n):e[o]},n[r].vuex=!0})),n})),g=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.commit;if(t){var i=M(this.$store,"mapMutations",t);if(!i)return;r=i.context.commit}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n})),y=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;o=t+o,n[r]=function(){if(!t||M(this.$store,"mapGetters",t))return this.$store.getters[o]},n[r].vuex=!0})),n})),_=w((function(t,e){var n={};return b(e).forEach((function(e){var r=e.key,o=e.val;n[r]=function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];var r=this.$store.dispatch;if(t){var i=M(this.$store,"mapActions",t);if(!i)return;r=i.context.dispatch}return"function"==typeof o?o.apply(this,[r].concat(e)):r.apply(this.$store,[o].concat(e))}})),n}));function b(t){return function(t){return Array.isArray(t)||o(t)}(t)?Array.isArray(t)?t.map((function(t){return{key:t,val:t}})):Object.keys(t).map((function(e){return{key:e,val:t[e]}})):[]}function w(t){return function(e,n){return"string"!=typeof e?(n=e,e=""):"/"!==e.charAt(e.length-1)&&(e+="/"),t(e,n)}}function M(t,e,n){return t._modulesNamespaceMap[n]}function O(t,e,n){var r=n?t.groupCollapsed:t.group;try{r.call(t,e)}catch(n){t.log(e)}}function C(t){try{t.groupEnd()}catch(e){t.log("—— log end ——")}}function E(){var t=new Date;return" @ "+j(t.getHours(),2)+":"+j(t.getMinutes(),2)+":"+j(t.getSeconds(),2)+"."+j(t.getMilliseconds(),3)}function j(t,e){return n="0",r=e-t.toString().length,new Array(r+1).join(n)+t;var n,r}return{version:"4.0.0-beta.3",createStore:function(t){return new s(t)},Store:s,useStore:function(e){return void 0===e&&(e=null),t.inject(null!==e?e:"store")},mapState:v,mapMutations:g,mapGetters:y,mapActions:_,createNamespacedHelpers:function(t){return{mapState:v.bind(null,t),mapGetters:y.bind(null,t),mapMutations:g.bind(null,t),mapActions:_.bind(null,t)}},createLogger:function(t){void 0===t&&(t={});var e=t.collapsed;void 0===e&&(e=!0);var r=t.filter;void 0===r&&(r=function(t,e,n){return!0});var o=t.transformer;void 0===o&&(o=function(t){return t});var i=t.mutationTransformer;void 0===i&&(i=function(t){return t});var a=t.actionFilter;void 0===a&&(a=function(t,e){return!0});var c=t.actionTransformer;void 0===c&&(c=function(t){return t});var s=t.logMutations;void 0===s&&(s=!0);var u=t.logActions;void 0===u&&(u=!0);var f=t.logger;return void 0===f&&(f=console),function(t){var l=n(t.state);void 0!==f&&(s&&t.subscribe((function(t,a){var c=n(a);if(r(t,l,c)){var s=E(),u=i(t),h="mutation "+t.type+s;O(f,h,e),f.log("%c prev state","color: #9E9E9E; font-weight: bold",o(l)),f.log("%c mutation","color: #03A9F4; font-weight: bold",u),f.log("%c next state","color: #4CAF50; font-weight: bold",o(c)),C(f)}l=c})),u&&t.subscribeAction((function(t,n){if(a(t,n)){var r=E(),o=c(t),i="action "+t.type+r;O(f,i,e),f.log("%c action","color: #03A9F4; font-weight: bold",o),C(f)}})))}}}}(Vue); |
{ | ||
"name": "vuex", | ||
"version": "4.0.0-beta.2", | ||
"version": "4.0.0-beta.3", | ||
"description": "state management for Vue.js", | ||
@@ -20,9 +20,7 @@ "main": "dist/vuex.cjs.js", | ||
"dev": "node examples/server.js", | ||
"build": "npm run build:main && npm run build:logger", | ||
"build:main": "node scripts/build-main.js", | ||
"build:logger": "node scripts/build-logger.js", | ||
"build": "node scripts/build.js", | ||
"lint": "eslint src test", | ||
"test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e", | ||
"test:unit": "jest --testPathIgnorePatterns test/e2e", | ||
"test:e2e": "node test/e2e/runner.js", | ||
"test:e2e": "start-server-and-test dev http://localhost:8080 'jest --testPathIgnorePatterns test/unit'", | ||
"test:ssr": "cross-env VUE_ENV=server jest --testPathIgnorePatterns test/e2e", | ||
@@ -62,6 +60,4 @@ "test:types": "tsc -p types/test", | ||
"chalk": "^4.0.0", | ||
"chromedriver": "^80.0.1", | ||
"conventional-changelog-cli": "^2.0.31", | ||
"cross-env": "^5.2.0", | ||
"cross-spawn": "^6.0.5", | ||
"css-loader": "^2.1.0", | ||
@@ -74,4 +70,3 @@ "enquirer": "^2.3.5", | ||
"jest": "^26.0.1", | ||
"nightwatch": "^1.3.1", | ||
"nightwatch-helpers": "^1.2.0", | ||
"puppeteer": "^4.0.0", | ||
"regenerator-runtime": "^0.13.5", | ||
@@ -81,2 +76,3 @@ "rollup": "^2.8.2", | ||
"semver": "^7.3.2", | ||
"start-server-and-test": "^1.11.0", | ||
"todomvc-app-css": "^2.1.0", | ||
@@ -83,0 +79,0 @@ "typescript": "^3.8.3", |
@@ -88,4 +88,12 @@ # Vuex 4 | ||
## TODOs as of 4.0.0-beta.1 | ||
### `createLogger` function is exported from the core module | ||
In Vuex 3, `createLogger` function was exported from `vuex/dist/logger` but it's now included in the core package. You should import the function directly from `vuex` package. | ||
```js | ||
import { createLogger } from 'vuex' | ||
``` | ||
## TODOs as of 4.0.0-beta.2 | ||
- Update docs |
@@ -7,4 +7,6 @@ import { App, WatchOptions, InjectionKey } from "vue"; | ||
import { mapState, mapMutations, mapGetters, mapActions, createNamespacedHelpers } from "./helpers"; | ||
import { createLogger } from "./logger"; | ||
export * from "./helpers"; | ||
export * from "./logger"; | ||
@@ -162,3 +164,4 @@ export declare class Store<S> { | ||
createNamespacedHelpers: typeof createNamespacedHelpers, | ||
createLogger: typeof createLogger | ||
}; | ||
export default _default; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
215887
37
5123
99
56
13