Skip to content

Commit

Permalink
[build] 2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Oct 11, 2017
1 parent 35ebfcf commit a81ab98
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 80 deletions.
19 changes: 10 additions & 9 deletions dist/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ function createLogger (ref) {
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 logger = ref.logger; if ( logger === void 0 ) logger = console;

return function (store) {
var prevState = deepCopy(store.state);

store.subscribe(function (mutation, state) {
if (typeof console === 'undefined') {
if (typeof logger === 'undefined') {
return
}
var nextState = deepCopy(state);
Expand All @@ -82,24 +83,24 @@ function createLogger (ref) {
var formattedMutation = mutationTransformer(mutation);
var message = "mutation " + (mutation.type) + formattedTime;
var startMessage = collapsed
? console.groupCollapsed
: console.group;
? logger.groupCollapsed
: logger.group;

// render
try {
startMessage.call(console, message);
startMessage.call(logger, message);
} catch (e) {
console.log(message);
}

console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', transformer(prevState));
console.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation);
console.log('%c next state', 'color: #4CAF50; font-weight: bold', transformer(nextState));
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));

try {
console.groupEnd();
logger.groupEnd();
} catch (e) {
console.log('—— log end ——');
logger.log('—— log end ——');
}
}

Expand Down
81 changes: 58 additions & 23 deletions dist/vuex.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v2.4.1
* vuex v2.5.0
* (c) 2017 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -246,26 +246,44 @@ function update (path, targetModule, newModule) {
}
}

var functionAssert = {
assert: function (value) { return typeof value === 'function'; },
expected: 'function'
};

var objectAssert = {
assert: function (value) { return typeof value === 'function' ||
(typeof value === 'object' && typeof value.handler === 'function'); },
expected: 'function or object with "handler" function'
};

var assertTypes = {
getters: functionAssert,
mutations: functionAssert,
actions: objectAssert
};

function assertRawModule (path, rawModule) {
['getters', 'actions', 'mutations'].forEach(function (key) {
Object.keys(assertTypes).forEach(function (key) {
if (!rawModule[key]) { return }

var assertOptions = assertTypes[key];

forEachValue(rawModule[key], function (value, type) {
assert(
typeof value === 'function',
makeAssertionMessage(path, key, type, value)
assertOptions.assert(value),
makeAssertionMessage(path, key, type, value, assertOptions.expected)
);
});
});
}

function makeAssertionMessage (path, key, type, value) {
var buf = key + " should be function but \"" + key + "." + type + "\"";
function makeAssertionMessage (path, key, type, value, expected) {
var buf = key + " should be " + expected + " but \"" + key + "." + type + "\"";
if (path.length > 0) {
buf += " in module \"" + (path.join('.')) + "\"";
}
buf += " is " + (JSON.stringify(value)) + ".";

return buf
}

Expand Down Expand Up @@ -293,12 +311,13 @@ var Store = function Store (options) {

var state = options.state; if ( state === void 0 ) state = {};
if (typeof state === 'function') {
state = state();
state = state() || {};
}

// store internal state
this._committing = false;
this._actions = Object.create(null);
this._actionSubscribers = [];
this._mutations = Object.create(null);
this._wrappedGetters = Object.create(null);
this._modules = new ModuleCollection(options);
Expand Down Expand Up @@ -386,34 +405,35 @@ Store.prototype.commit = function commit (_type, _payload, _options) {
};

Store.prototype.dispatch = function dispatch (_type, _payload) {
var this$1 = this;

// check object-style dispatch
var ref = unifyObjectStyle(_type, _payload);
var type = ref.type;
var payload = ref.payload;

var action = { type: type, payload: payload };
var entry = this._actions[type];
if (!entry) {
if (process.env.NODE_ENV !== 'production') {
console.error(("[vuex] unknown action type: " + type));
}
return
}

this._actionSubscribers.forEach(function (sub) { return sub(action, this$1.state); });

return entry.length > 1
? Promise.all(entry.map(function (handler) { return handler(payload); }))
: entry[0](payload)
};

Store.prototype.subscribe = 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);
}
}
return genericSubscribe(fn, this._subscribers)
};

Store.prototype.subscribeAction = function subscribeAction (fn) {
return genericSubscribe(fn, this._actionSubscribers)
};

Store.prototype.watch = function watch (getter, cb, options) {
Expand All @@ -433,7 +453,9 @@ Store.prototype.replaceState = function replaceState (state) {
});
};

Store.prototype.registerModule = function registerModule (path, rawModule) {
Store.prototype.registerModule = function registerModule (path, rawModule, options) {
if ( options === void 0 ) options = {};

if (typeof path === 'string') { path = [path]; }

if (process.env.NODE_ENV !== 'production') {
Expand All @@ -442,7 +464,7 @@ Store.prototype.registerModule = function registerModule (path, rawModule) {
}

this._modules.register(path, rawModule);
installModule(this, this.state, path, this._modules.get(path));
installModule(this, this.state, path, this._modules.get(path), options.preserveState);
// reset store to update getters...
resetStoreVM(this, this.state);
};
Expand Down Expand Up @@ -478,6 +500,18 @@ Store.prototype._withCommit = function _withCommit (fn) {

Object.defineProperties( Store.prototype, prototypeAccessors );

function genericSubscribe (fn, subs) {
if (subs.indexOf(fn) < 0) {
subs.push(fn);
}
return function () {
var i = subs.indexOf(fn);
if (i > -1) {
subs.splice(i, 1);
}
}
}

function resetStore (store, hot) {
store._actions = Object.create(null);
store._mutations = Object.create(null);
Expand Down Expand Up @@ -562,8 +596,9 @@ function installModule (store, rootState, path, module, hot) {
});

module.forEachAction(function (action, key) {
var namespacedType = namespace + key;
registerAction(store, namespacedType, action, local);
var type = action.root ? key : namespace + key;
var handler = action.handler || action;
registerAction(store, type, handler, local);
});

module.forEachGetter(function (getter, key) {
Expand Down Expand Up @@ -886,7 +921,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index = {
Store: Store,
install: install,
version: '2.4.1',
version: '2.5.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
Loading

0 comments on commit a81ab98

Please sign in to comment.