Skip to content

Commit 2f1035a

Browse files
committed
Merge branch 'next'
2 parents fb833b0 + 71e6f53 commit 2f1035a

File tree

27 files changed

+160
-130
lines changed

27 files changed

+160
-130
lines changed

.eslintrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"extends": "standard",
3-
"rules": {
4-
"arrow-parens": [2, "as-needed"]
5-
}
2+
"root": true,
3+
"extends": "vue"
64
}

build/bind.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

dist/vuex.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* Vuex v0.6.3
2+
* Vuex v0.8.2
33
* (c) 2016 Evan You
44
* Released under the MIT License.
55
*/
@@ -9,20 +9,19 @@
99
(global.Vuex = factory());
1010
}(this, function () { 'use strict';
1111

12-
var babelHelpers = {};
13-
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
12+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
1413
return typeof obj;
1514
} : function (obj) {
1615
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
1716
};
1817

19-
babelHelpers.classCallCheck = function (instance, Constructor) {
18+
var classCallCheck = function (instance, Constructor) {
2019
if (!(instance instanceof Constructor)) {
2120
throw new TypeError("Cannot call a class as a function");
2221
}
2322
};
2423

25-
babelHelpers.createClass = function () {
24+
var createClass = function () {
2625
function defineProperties(target, props) {
2726
for (var i = 0; i < props.length; i++) {
2827
var descriptor = props[i];
@@ -40,7 +39,7 @@
4039
};
4140
}();
4241

43-
babelHelpers.toConsumableArray = function (arr) {
42+
var toConsumableArray = function (arr) {
4443
if (Array.isArray(arr)) {
4544
for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
4645

@@ -50,8 +49,6 @@
5049
}
5150
};
5251

53-
babelHelpers;
54-
5552
/**
5653
* Merge an array of objects into one.
5754
*
@@ -89,7 +86,7 @@
8986
function deepClone(obj) {
9087
if (Array.isArray(obj)) {
9188
return obj.map(deepClone);
92-
} else if (obj && (typeof obj === 'undefined' ? 'undefined' : babelHelpers.typeof(obj)) === 'object') {
89+
} else if (obj && (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object') {
9390
var cloned = {};
9491
var keys = Object.keys(obj);
9592
for (var i = 0, l = keys.length; i < l; i++) {
@@ -110,9 +107,8 @@
110107
var Watcher = void 0;
111108
function getWatcher(vm) {
112109
if (!Watcher) {
113-
var unwatch = vm.$watch('__vuex__', function (a) {
114-
return a;
115-
});
110+
var noop = function noop() {};
111+
var unwatch = vm.$watch(noop, noop);
116112
Watcher = vm._watchers[0].constructor;
117113
unwatch();
118114
}
@@ -134,11 +130,8 @@
134130
if (!hook) return;
135131
hook.emit('vuex:init', store);
136132
hook.on('vuex:travel-to-state', function (targetState) {
137-
var currentState = store._vm._data;
138133
store._dispatching = true;
139-
Object.keys(targetState).forEach(function (key) {
140-
currentState[key] = targetState[key];
141-
});
134+
store._vm.state = targetState;
142135
store._dispatching = false;
143136
});
144137
},
@@ -149,14 +142,24 @@
149142
};
150143

151144
function override (Vue) {
152-
// override init and inject vuex init procedure
153-
var _init = Vue.prototype._init;
154-
Vue.prototype._init = function () {
155-
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
145+
var version = Number(Vue.version.split('.')[0]);
156146

157-
options.init = options.init ? [vuexInit].concat(options.init) : vuexInit;
158-
_init.call(this, options);
159-
};
147+
if (version >= 2) {
148+
var usesInit = Vue.config._lifecycleHooks.indexOf('init') > -1;
149+
Vue.mixin(usesInit ? { init: vuexInit } : { beforeCreate: vuexInit });
150+
} else {
151+
(function () {
152+
// override init and inject vuex init procedure
153+
// for 1.x backwards compatibility.
154+
var _init = Vue.prototype._init;
155+
Vue.prototype._init = function () {
156+
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
157+
158+
options.init = options.init ? [vuexInit].concat(options.init) : vuexInit;
159+
_init.call(this, options);
160+
};
161+
})();
162+
}
160163

161164
/**
162165
* Vuex init hook, injected into each instances init hooks list.
@@ -179,8 +182,8 @@
179182
console.warn('[vuex] store not injected. make sure to ' + 'provide the store option in your root component.');
180183
}
181184
var state = vuex.state;
182-
var getters = vuex.getters;
183185
var actions = vuex.actions;
186+
var getters = vuex.getters;
184187
// handle deprecated state option
185188

186189
if (state && !getters) {
@@ -254,8 +257,8 @@
254257
var vm = store._vm;
255258
var Watcher = getWatcher(vm);
256259
var Dep = getDep(vm);
257-
var watcher = new Watcher(vm, function (state) {
258-
return getter(state);
260+
var watcher = new Watcher(vm, function (vm) {
261+
return getter(vm.state);
259262
}, null, { lazy: true });
260263
var computedGetter = function computedGetter() {
261264
if (watcher.dirty) {
@@ -333,7 +336,7 @@
333336
var middlewares = _ref$middlewares === undefined ? [] : _ref$middlewares;
334337
var _ref$strict = _ref.strict;
335338
var strict = _ref$strict === undefined ? false : _ref$strict;
336-
babelHelpers.classCallCheck(this, Store);
339+
classCallCheck(this, Store);
337340

338341
this._getterCacheId = 'vuex_store_' + uid++;
339342
this._dispatching = false;
@@ -357,7 +360,9 @@
357360
var silent = Vue.config.silent;
358361
Vue.config.silent = true;
359362
this._vm = new Vue({
360-
data: state
363+
data: {
364+
state: state
365+
}
361366
});
362367
Vue.config.silent = silent;
363368
this._setupModuleState(state, modules);
@@ -376,7 +381,7 @@
376381
* @return {Object}
377382
*/
378383

379-
babelHelpers.createClass(Store, [{
384+
createClass(Store, [{
380385
key: 'dispatch',
381386

382387

@@ -393,7 +398,7 @@
393398

394399
var silent = false;
395400
// compatibility for object actions, e.g. FSA
396-
if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) {
401+
if ((typeof type === 'undefined' ? 'undefined' : _typeof(type)) === 'object' && type.type && arguments.length === 1) {
397402
payload = [type.payload];
398403
if (type.silent) silent = true;
399404
type = type.type;
@@ -405,10 +410,10 @@
405410
// apply the mutation
406411
if (Array.isArray(mutation)) {
407412
mutation.forEach(function (m) {
408-
return m.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
413+
return m.apply(undefined, [state].concat(toConsumableArray(payload)));
409414
});
410415
} else {
411-
mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
416+
mutation.apply(undefined, [state].concat(toConsumableArray(payload)));
412417
}
413418
this._dispatching = false;
414419
if (!silent) this._applyMiddlewares(type, payload);
@@ -422,18 +427,22 @@
422427
* Same API as Vue's $watch, except when watching a function,
423428
* the function gets the state as the first argument.
424429
*
425-
* @param {String|Function} expOrFn
430+
* @param {Function} fn
426431
* @param {Function} cb
427432
* @param {Object} [options]
428433
*/
429434

430435
}, {
431436
key: 'watch',
432-
value: function watch(expOrFn, cb, options) {
437+
value: function watch(fn, cb, options) {
433438
var _this2 = this;
434439

440+
if (typeof fn !== 'function') {
441+
console.error('Vuex store.watch only accepts function.');
442+
return;
443+
}
435444
return this._vm.$watch(function () {
436-
return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
445+
return fn(_this2.state);
437446
}, cb, options);
438447
}
439448

@@ -523,7 +532,7 @@
523532

524533
var Watcher = getWatcher(this._vm);
525534
/* eslint-disable no-new */
526-
new Watcher(this._vm, '$data', function () {
535+
new Watcher(this._vm, 'state', function () {
527536
if (!_this3._dispatching) {
528537
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
529538
}
@@ -596,7 +605,7 @@
596605
}, {
597606
key: 'state',
598607
get: function get() {
599-
return this._vm._data;
608+
return this._vm.state;
600609
},
601610
set: function set(v) {
602611
throw new Error('[vuex] Vuex root state is read only.');
@@ -619,14 +628,9 @@
619628
install(window.Vue);
620629
}
621630

622-
function createLogger() {
623-
console.warn('[vuex] Vuex.createLogger has been deprecated.' + 'Use `import createLogger from \'vuex/logger\' instead.');
624-
}
625-
626631
var index = {
627632
Store: Store,
628-
install: install,
629-
createLogger: createLogger
633+
install: install
630634
};
631635

632636
return index;

0 commit comments

Comments
 (0)