Skip to content

Commit

Permalink
realese: v3.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed Apr 25, 2020
1 parent e2b9974 commit b1568a5
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 71 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# [3.3.0](https://github.com/vuejs/vuex/compare/v3.2.0...v3.3.0) (2020-04-25)


### Bug Fixes

* Prepend devtool handler ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0)), closes [vuejs/vue-devtools#678](https://github.com/vuejs/vue-devtools/issues/678)
* **types:** Add `devtools` to store options type ([#1478](https://github.com/vuejs/vuex/issues/1478)) ([38c11dc](https://github.com/vuejs/vuex/commit/38c11dcbaea7d7e661a1623cabb5aef7c6e47ba7))


### Features

* Add `prepend` option for `subscribe` and `subscribeAction` ([#1358](https://github.com/vuejs/vuex/issues/1358)) ([a39d076](https://github.com/vuejs/vuex/commit/a39d0767e4041cdd5cf8050774106c01d39024e0))
* **logger:** `createLogger` can optionally log actions ([#987](https://github.com/vuejs/vuex/issues/987)) ([18be128](https://github.com/vuejs/vuex/commit/18be128ad933d1fca6da05c060f7664ce0c819ae))



# [3.2.0](https://github.com/vuejs/vuex/compare/v3.1.3...v3.2.0) (2020-04-19)


Expand Down
92 changes: 62 additions & 30 deletions dist/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,81 @@
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);

store.subscribe(function (mutation, state) {
if (typeof logger === 'undefined') {
return
}
var nextState = deepCopy(state);

if (filter(mutation, prevState, nextState)) {
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);
var message = "mutation " + (mutation.type) + formattedTime;
var startMessage = collapsed
? logger.groupCollapsed
: logger.group;

// render
try {
startMessage.call(logger, message);
} catch (e) {
console.log(message);
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);
}

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));
prevState = nextState;
});
}

try {
logger.groupEnd();
} catch (e) {
logger.log('—— log end ——');
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);
}
}
});
}
}
}

prevState = nextState;
});
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)
}
Expand Down
24 changes: 15 additions & 9 deletions dist/vuex.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v3.2.0
* vuex v3.3.0
* (c) 2020 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -61,7 +61,11 @@ function devtoolPlugin (store) {

store.subscribe(function (mutation, state) {
devtoolHook.emit('vuex:mutation', mutation, state);
});
}, { prepend: true });

store.subscribeAction(function (action, state) {
devtoolHook.emit('vuex:action', action, state);
}, { prepend: true });
}

/**
Expand Down Expand Up @@ -469,13 +473,13 @@ Store.prototype.dispatch = function dispatch (_type, _payload) {
})
};

Store.prototype.subscribe = function subscribe (fn) {
return genericSubscribe(fn, this._subscribers)
Store.prototype.subscribe = function subscribe (fn, options) {
return genericSubscribe(fn, this._subscribers, options)
};

Store.prototype.subscribeAction = function subscribeAction (fn) {
Store.prototype.subscribeAction = function subscribeAction (fn, options) {
var subs = typeof fn === 'function' ? { before: fn } : fn;
return genericSubscribe(subs, this._actionSubscribers)
return genericSubscribe(subs, this._actionSubscribers, options)
};

Store.prototype.watch = function watch (getter, cb, options) {
Expand Down Expand Up @@ -552,9 +556,11 @@ Store.prototype._withCommit = function _withCommit (fn) {

Object.defineProperties( Store.prototype, prototypeAccessors$1 );

function genericSubscribe (fn, subs) {
function genericSubscribe (fn, subs, options) {
if (subs.indexOf(fn) < 0) {
subs.push(fn);
options && options.prepend
? subs.unshift(fn)
: subs.push(fn);
}
return function () {
var i = subs.indexOf(fn);
Expand Down Expand Up @@ -1062,7 +1068,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index = {
Store: Store,
install: install,
version: '3.2.0',
version: '3.3.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
24 changes: 15 additions & 9 deletions dist/vuex.esm.browser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v3.2.0
* vuex v3.3.0
* (c) 2020 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -57,7 +57,11 @@ function devtoolPlugin (store) {

store.subscribe((mutation, state) => {
devtoolHook.emit('vuex:mutation', mutation, state);
});
}, { prepend: true });

store.subscribeAction((action, state) => {
devtoolHook.emit('vuex:action', action, state);
}, { prepend: true });
}

/**
Expand Down Expand Up @@ -455,13 +459,13 @@ class Store {
})
}

subscribe (fn) {
return genericSubscribe(fn, this._subscribers)
subscribe (fn, options) {
return genericSubscribe(fn, this._subscribers, options)
}

subscribeAction (fn) {
subscribeAction (fn, options) {
const subs = typeof fn === 'function' ? { before: fn } : fn;
return genericSubscribe(subs, this._actionSubscribers)
return genericSubscribe(subs, this._actionSubscribers, options)
}

watch (getter, cb, options) {
Expand Down Expand Up @@ -529,9 +533,11 @@ class Store {
}
}

function genericSubscribe (fn, subs) {
function genericSubscribe (fn, subs, options) {
if (subs.indexOf(fn) < 0) {
subs.push(fn);
options && options.prepend
? subs.unshift(fn)
: subs.push(fn);
}
return () => {
const i = subs.indexOf(fn);
Expand Down Expand Up @@ -1019,7 +1025,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index_esm = {
Store,
install,
version: '3.2.0',
version: '3.3.0',
mapState,
mapMutations,
mapGetters,
Expand Down
4 changes: 2 additions & 2 deletions dist/vuex.esm.browser.min.js

Large diffs are not rendered by default.

24 changes: 15 additions & 9 deletions dist/vuex.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v3.2.0
* vuex v3.3.0
* (c) 2020 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -59,7 +59,11 @@ function devtoolPlugin (store) {

store.subscribe(function (mutation, state) {
devtoolHook.emit('vuex:mutation', mutation, state);
});
}, { prepend: true });

store.subscribeAction(function (action, state) {
devtoolHook.emit('vuex:action', action, state);
}, { prepend: true });
}

/**
Expand Down Expand Up @@ -467,13 +471,13 @@ Store.prototype.dispatch = function dispatch (_type, _payload) {
})
};

Store.prototype.subscribe = function subscribe (fn) {
return genericSubscribe(fn, this._subscribers)
Store.prototype.subscribe = function subscribe (fn, options) {
return genericSubscribe(fn, this._subscribers, options)
};

Store.prototype.subscribeAction = function subscribeAction (fn) {
Store.prototype.subscribeAction = function subscribeAction (fn, options) {
var subs = typeof fn === 'function' ? { before: fn } : fn;
return genericSubscribe(subs, this._actionSubscribers)
return genericSubscribe(subs, this._actionSubscribers, options)
};

Store.prototype.watch = function watch (getter, cb, options) {
Expand Down Expand Up @@ -550,9 +554,11 @@ Store.prototype._withCommit = function _withCommit (fn) {

Object.defineProperties( Store.prototype, prototypeAccessors$1 );

function genericSubscribe (fn, subs) {
function genericSubscribe (fn, subs, options) {
if (subs.indexOf(fn) < 0) {
subs.push(fn);
options && options.prepend
? subs.unshift(fn)
: subs.push(fn);
}
return function () {
var i = subs.indexOf(fn);
Expand Down Expand Up @@ -1060,7 +1066,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index_esm = {
Store: Store,
install: install,
version: '3.2.0',
version: '3.3.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
24 changes: 15 additions & 9 deletions dist/vuex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v3.2.0
* vuex v3.3.0
* (c) 2020 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -65,7 +65,11 @@

store.subscribe(function (mutation, state) {
devtoolHook.emit('vuex:mutation', mutation, state);
});
}, { prepend: true });

store.subscribeAction(function (action, state) {
devtoolHook.emit('vuex:action', action, state);
}, { prepend: true });
}

/**
Expand Down Expand Up @@ -472,13 +476,13 @@
})
};

Store.prototype.subscribe = function subscribe (fn) {
return genericSubscribe(fn, this._subscribers)
Store.prototype.subscribe = function subscribe (fn, options) {
return genericSubscribe(fn, this._subscribers, options)
};

Store.prototype.subscribeAction = function subscribeAction (fn) {
Store.prototype.subscribeAction = function subscribeAction (fn, options) {
var subs = typeof fn === 'function' ? { before: fn } : fn;
return genericSubscribe(subs, this._actionSubscribers)
return genericSubscribe(subs, this._actionSubscribers, options)
};

Store.prototype.watch = function watch (getter, cb, options) {
Expand Down Expand Up @@ -555,9 +559,11 @@

Object.defineProperties( Store.prototype, prototypeAccessors$1 );

function genericSubscribe (fn, subs) {
function genericSubscribe (fn, subs, options) {
if (subs.indexOf(fn) < 0) {
subs.push(fn);
options && options.prepend
? subs.unshift(fn)
: subs.push(fn);
}
return function () {
var i = subs.indexOf(fn);
Expand Down Expand Up @@ -1065,7 +1071,7 @@
var index = {
Store: Store,
install: install,
version: '3.2.0',
version: '3.3.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
Loading

0 comments on commit b1568a5

Please sign in to comment.