Skip to content

Commit 111f52d

Browse files
committed
0.5.0
1 parent 7a1eb52 commit 111f52d

File tree

3 files changed

+36
-87
lines changed

3 files changed

+36
-87
lines changed

dist/vuex.js

Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Vuex v0.4.2
2+
* Vuex v0.5.0
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -92,71 +92,25 @@
9292
}
9393
}
9494

95+
var hook = typeof window !== 'undefined' && window.__VUE_DEVTOOLS_GLOBAL_HOOK__;
96+
9597
var devtoolMiddleware = {
96-
onInit: function onInit(state) {
97-
// TODO
98+
onInit: function onInit(state, store) {
99+
if (!hook) return;
100+
hook.emit('vuex:init', store);
101+
hook.on('vuex:travel-to-state', function (targetState) {
102+
var currentState = store._vm._data;
103+
Object.keys(targetState).forEach(function (key) {
104+
currentState[key] = targetState[key];
105+
});
106+
});
98107
},
99108
onMutation: function onMutation(mutation, state) {
100-
// TODO
109+
if (!hook) return;
110+
hook.emit('vuex:mutation', mutation, state);
101111
}
102112
};
103113

104-
// Credits: borrowed code from fcomb/redux-logger
105-
106-
function createLogger() {
107-
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
108-
109-
var _ref$collapsed = _ref.collapsed;
110-
var collapsed = _ref$collapsed === undefined ? true : _ref$collapsed;
111-
var _ref$transformer = _ref.transformer;
112-
var transformer = _ref$transformer === undefined ? function (state) {
113-
return state;
114-
} : _ref$transformer;
115-
var _ref$mutationTransfor = _ref.mutationTransformer;
116-
var mutationTransformer = _ref$mutationTransfor === undefined ? function (mut) {
117-
return mut;
118-
} : _ref$mutationTransfor;
119-
120-
return {
121-
snapshot: true,
122-
onMutation: function onMutation(mutation, nextState, prevState) {
123-
if (typeof console === 'undefined') {
124-
return;
125-
}
126-
var time = new Date();
127-
var formattedTime = ' @ ' + pad(time.getHours(), 2) + ':' + pad(time.getMinutes(), 2) + ':' + pad(time.getSeconds(), 2) + '.' + pad(time.getMilliseconds(), 3);
128-
var formattedMutation = mutationTransformer(mutation);
129-
var message = 'mutation ' + mutation.type + formattedTime;
130-
var startMessage = collapsed ? console.groupCollapsed : console.group;
131-
132-
// render
133-
try {
134-
startMessage.call(console, message);
135-
} catch (e) {
136-
console.log(message);
137-
}
138-
139-
console.log('%c prev state', 'color: #9E9E9E; font-weight: bold', prevState);
140-
console.log('%c mutation', 'color: #03A9F4; font-weight: bold', formattedMutation);
141-
console.log('%c next state', 'color: #4CAF50; font-weight: bold', nextState);
142-
143-
try {
144-
console.groupEnd();
145-
} catch (e) {
146-
console.log('—— log end ——');
147-
}
148-
}
149-
};
150-
}
151-
152-
function repeat(str, times) {
153-
return new Array(times + 1).join(str);
154-
}
155-
156-
function pad(num, maxLength) {
157-
return repeat('0', maxLength - num.toString().length) + num;
158-
}
159-
160114
// export install function
161115
function override (Vue) {
162116
var _init = Vue.prototype._init;
@@ -255,9 +209,14 @@
255209
dispatch.apply(_this, args);
256210
};
257211
// use a Vue instance to store the state tree
212+
// suppress warnings just in case the user has added
213+
// some funky global mixins
214+
var silent = Vue.config.silent;
215+
Vue.config.silent = true;
258216
this._vm = new Vue({
259217
data: state
260218
});
219+
Vue.config.silent = silent;
261220
this._setupModuleState(state, modules);
262221
this._setupModuleMutations(modules);
263222
this._setupMiddlewares(middlewares, state);
@@ -285,6 +244,8 @@
285244
*/
286245

287246
value: function dispatch(type) {
247+
var _this2 = this;
248+
288249
for (var _len2 = arguments.length, payload = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
289250
payload[_key2 - 1] = arguments[_key2];
290251
}
@@ -313,9 +274,9 @@
313274
this._middlewares.forEach(function (m) {
314275
if (m.onMutation) {
315276
if (m.snapshot) {
316-
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot);
277+
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this2);
317278
} else {
318-
m.onMutation({ type: type, payload: payload }, state);
279+
m.onMutation({ type: type, payload: payload }, state, _this2);
319280
}
320281
}
321282
});
@@ -337,10 +298,10 @@
337298
}, {
338299
key: 'watch',
339300
value: function watch(expOrFn, cb, options) {
340-
var _this2 = this;
301+
var _this3 = this;
341302

342303
return this._vm.$watch(function () {
343-
return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
304+
return typeof expOrFn === 'function' ? expOrFn(_this3.state) : _this3._vm.$get(expOrFn);
344305
}, cb, options);
345306
}
346307

@@ -364,20 +325,6 @@
364325
this._setupModuleMutations(modules || this._modules);
365326
}
366327

367-
/**
368-
* Replace entire state tree.
369-
*/
370-
371-
}, {
372-
key: 'replaceState',
373-
value: function replaceState(newState) {
374-
var state = this._vm._data;
375-
var clone = deepClone(newState);
376-
Object.keys(clone).forEach(function (key) {
377-
state[key] = clone[key];
378-
});
379-
}
380-
381328
/**
382329
* Attach sub state tree of each module to the root tree.
383330
*
@@ -391,7 +338,7 @@
391338
var setPath = Vue.parsers.path.setPath;
392339

393340
Object.keys(modules).forEach(function (key) {
394-
setPath(state, key, modules[key].state);
341+
setPath(state, key, modules[key].state || {});
395342
});
396343
}
397344

@@ -411,6 +358,7 @@
411358
var allMutations = [this._rootMutations];
412359
Object.keys(modules).forEach(function (key) {
413360
var module = modules[key];
361+
if (!module || !module.mutations) return;
414362
// bind mutations to sub state tree
415363
var mutations = {};
416364
Object.keys(module.mutations).forEach(function (name) {
@@ -440,7 +388,7 @@
440388
}, {
441389
key: '_setupMutationCheck',
442390
value: function _setupMutationCheck() {
443-
var _this3 = this;
391+
var _this4 = this;
444392

445393
// a hack to get the watcher constructor from older versions of Vue
446394
// mainly because the public $watch method does not allow sync
@@ -452,7 +400,7 @@
452400
unwatch();
453401
/* eslint-disable no-new */
454402
new Watcher(this._vm, '$data', function () {
455-
if (!_this3._dispatching) {
403+
if (!_this4._dispatching) {
456404
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
457405
}
458406
}, { deep: true, sync: true });
@@ -473,6 +421,8 @@
473421
}, {
474422
key: '_setupMiddlewares',
475423
value: function _setupMiddlewares(middlewares, state) {
424+
var _this5 = this;
425+
476426
this._middlewares = [devtoolMiddleware].concat(middlewares);
477427
this._needSnapshots = middlewares.some(function (m) {
478428
return m.snapshot;
@@ -484,7 +434,7 @@
484434
// call init hooks
485435
this._middlewares.forEach(function (m) {
486436
if (m.onInit) {
487-
m.onInit(m.snapshot ? initialSnapshot : state);
437+
m.onInit(m.snapshot ? initialSnapshot : state, _this5);
488438
}
489439
});
490440
}
@@ -507,8 +457,7 @@
507457

508458
var index = {
509459
Store: Store,
510-
install: install,
511-
createLogger: createLogger
460+
install: install
512461
};
513462

514463
return index;

dist/vuex.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuex",
3-
"version": "0.4.2",
3+
"version": "0.5.0",
44
"description": "state management for Vue.js",
55
"main": "dist/vuex.js",
66
"files": [

0 commit comments

Comments
 (0)