Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuejs/vuex
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.6.2
Choose a base ref
...
head repository: vuejs/vuex
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.6.3
Choose a head ref
Loading
Showing with 3,763 additions and 299 deletions.
  1. +2 −2 README.md
  2. +1 −1 circle.yml
  3. +99 −41 dist/vuex.js
  4. +2 −2 dist/vuex.min.js
  5. +2 −0 docs/LANGS.md
  6. +1 −0 docs/en/SUMMARY.md
  7. +32 −1 docs/en/api.md
  8. +10 −1 docs/en/getting-started.md
  9. +5 −5 docs/en/middlewares.md
  10. +54 −0 docs/en/mutations.md
  11. +2 −2 docs/en/state.md
  12. +266 −0 docs/en/tutorial.md
  13. BIN docs/en/tutorial/result.png
  14. BIN docs/en/tutorial/vuex_flow.png
  15. +1 −0 docs/it/README.md
  16. +18 −0 docs/it/SUMMARY.md
  17. +133 −0 docs/it/actions.md
  18. +94 −0 docs/it/api.md
  19. +1 −0 docs/it/book.json
  20. +89 −0 docs/it/data-flow.md
  21. +41 −0 docs/it/forms.md
  22. +54 −0 docs/it/getting-started.md
  23. +45 −0 docs/it/hot-reload.md
  24. +13 −0 docs/it/intro.md
  25. +83 −0 docs/it/middlewares.md
  26. +135 −0 docs/it/mutations.md
  27. +159 −0 docs/it/state.md
  28. +25 −0 docs/it/strict.md
  29. +136 −0 docs/it/structure.md
  30. +166 −0 docs/it/testing.md
  31. BIN docs/it/vuex.png
  32. +1 −0 docs/pt/README.md
  33. +19 −0 docs/pt/SUMMARY.md
  34. +134 −0 docs/pt/actions.md
  35. +94 −0 docs/pt/api.md
  36. +1 −0 docs/pt/book.json
  37. +89 −0 docs/pt/data-flow.md
  38. +41 −0 docs/pt/forms.md
  39. +53 −0 docs/pt/getting-started.md
  40. +44 −0 docs/pt/hot-reload.md
  41. +13 −0 docs/pt/intro.md
  42. +82 −0 docs/pt/middlewares.md
  43. +134 −0 docs/pt/mutations.md
  44. +156 −0 docs/pt/state.md
  45. +25 −0 docs/pt/strict.md
  46. +136 −0 docs/pt/structure.md
  47. +167 −0 docs/pt/testing.md
  48. +266 −0 docs/pt/tutorial.md
  49. BIN docs/pt/tutorial/result.png
  50. BIN docs/pt/tutorial/vuex_flow.png
  51. BIN docs/pt/vuex.png
  52. +1 −0 docs/zh-cn/SUMMARY.md
  53. +90 −91 docs/zh-cn/actions.md
  54. +27 −26 docs/zh-cn/api.md
  55. +34 −38 docs/zh-cn/data-flow.md
  56. +40 −3 docs/zh-cn/mutations.md
  57. +52 −1 docs/zh-cn/quickstart.md
  58. +126 −22 docs/zh-cn/state.md
  59. +55 −29 docs/zh-cn/testing.md
  60. +20 −0 index.d.ts
  61. +3 −1 package.json
  62. +38 −21 src/index.js
  63. +51 −8 src/override.js
  64. +90 −4 test/unit/test.js
  65. +12 −0 tsconfig.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
<img width="700px" src="https://raw.githubusercontent.com/vuejs/vuex/master/docs/en/vuex.png">
</p>

- [Documentation](http://vuex.vuejs.org/)
- [Documentation](http://vuejs.github.io/vuex/)
- [Great introduction and explanation by @skyronic](http://skyronic.com/2016/01/03/vuex-basics-tutorial/) (using outdated 0.3.0 API, but still worth a read!)
- [Vuex introduction video - James Browne from London Vue.js Meetup #1](https://www.youtube.com/watch?v=l1KHL-TX3qs)

@@ -34,4 +34,4 @@ See [npm scripts](https://github.com/vuejs/vuex/blob/master/package.json#L11-L15
- Reactive
- Single State Tree
- Hot Reloading
- Time Travel (with upcoming vue-devtools support)
- Time Travel (with [vue-devtools](https://github.com/vuejs/vue-devtools) support)
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
machine:
node:
version: 4
version: 5
140 changes: 99 additions & 41 deletions dist/vuex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Vuex v0.6.2
* Vuex v0.6.3
* (c) 2016 Evan You
* Released under the MIT License.
*/
@@ -158,6 +158,10 @@
_init.call(this, options);
};

/**
* Vuex init hook, injected into each instances init hooks list.
*/

function vuexInit() {
var options = this.$options;
var store = options.store;
@@ -194,27 +198,55 @@
if (actions) {
options.methods = options.methods || {};
for (var _key in actions) {
options.methods[_key] = makeBoundAction(actions[_key], this.$store);
options.methods[_key] = makeBoundAction(this.$store, actions[_key], _key);
}
}
}
}

/**
* Setter for all getter properties.
*/

function setter() {
throw new Error('vuex getter properties are read-only.');
}

/**
* Define a Vuex getter on an instance.
*
* @param {Vue} vm
* @param {String} key
* @param {Function} getter
*/

function defineVuexGetter(vm, key, getter) {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
});
if (typeof getter !== 'function') {
console.warn('[vuex] Getter bound to key \'vuex.getters.' + key + '\' is not a function.');
} else {
Object.defineProperty(vm, key, {
enumerable: true,
configurable: true,
get: makeComputedGetter(vm.$store, getter),
set: setter
});
}
}

/**
* Make a computed getter, using the same caching mechanism of computed
* properties. In addition, it is cached on the raw getter function using
* the store's unique cache id. This makes the same getter shared
* across all components use the same underlying watcher, and makes
* the getter evaluated only once during every flush.
*
* @param {Store} store
* @param {Function} getter
*/

function makeComputedGetter(store, getter) {
var id = store._getterCacheId;

// cached
if (getter[id]) {
return getter[id];
@@ -238,7 +270,18 @@
return computedGetter;
}

function makeBoundAction(action, store) {
/**
* Make a bound-to-store version of a raw action function.
*
* @param {Store} store
* @param {Function} action
* @param {String} key
*/

function makeBoundAction(store, action, key) {
if (typeof action !== 'function') {
console.warn('[vuex] Action bound to key \'vuex.actions.' + key + '\' is not a function.');
}
return function vuexBoundAction() {
for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) {
args[_key2] = arguments[_key2];
@@ -344,22 +387,19 @@
*/

value: function dispatch(type) {
var _this2 = this;

for (var _len2 = arguments.length, payload = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
payload[_key2 - 1] = arguments[_key2];
}

var silent = false;
// compatibility for object actions, e.g. FSA
if ((typeof type === 'undefined' ? 'undefined' : babelHelpers.typeof(type)) === 'object' && type.type && arguments.length === 1) {
payload = [type];
payload = [type.payload];
if (type.silent) silent = true;
type = type.type;
}
var mutation = this._mutations[type];
var prevSnapshot = this._prevSnapshot;
var state = this.state;
var snapshot = void 0,
clonedPayload = void 0;
if (mutation) {
this._dispatching = true;
// apply the mutation
@@ -371,20 +411,7 @@
mutation.apply(undefined, [state].concat(babelHelpers.toConsumableArray(payload)));
}
this._dispatching = false;
// invoke middlewares
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state);
clonedPayload = deepClone(payload);
}
this._middlewares.forEach(function (m) {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this2);
} else {
m.onMutation({ type: type, payload: payload }, state, _this2);
}
}
});
if (!silent) this._applyMiddlewares(type, payload);
} else {
console.warn('[vuex] Unknown mutation: ' + type);
}
@@ -403,10 +430,10 @@
}, {
key: 'watch',
value: function watch(expOrFn, cb, options) {
var _this3 = this;
var _this2 = this;

return this._vm.$watch(function () {
return typeof expOrFn === 'function' ? expOrFn(_this3.state) : _this3._vm.$get(expOrFn);
return typeof expOrFn === 'function' ? expOrFn(_this2.state) : _this2._vm.$get(expOrFn);
}, cb, options);
}

@@ -440,10 +467,8 @@
}, {
key: '_setupModuleState',
value: function _setupModuleState(state, modules) {
var setPath = Vue.parsers.path.setPath;

Object.keys(modules).forEach(function (key) {
setPath(state, key, modules[key].state || {});
Vue.set(state, key, modules[key].state || {});
});
}

@@ -458,8 +483,6 @@
key: '_setupModuleMutations',
value: function _setupModuleMutations(updatedModules) {
var modules = this._modules;
var getPath = Vue.parsers.path.getPath;

var allMutations = [this._rootMutations];
Object.keys(updatedModules).forEach(function (key) {
modules[key] = updatedModules[key];
@@ -476,7 +499,7 @@
args[_key3 - 1] = arguments[_key3];
}

original.apply(undefined, [getPath(state, key)].concat(args));
original.apply(undefined, [state[key]].concat(args));
};
});
allMutations.push(mutations);
@@ -496,12 +519,12 @@
}, {
key: '_setupMutationCheck',
value: function _setupMutationCheck() {
var _this4 = this;
var _this3 = this;

var Watcher = getWatcher(this._vm);
/* eslint-disable no-new */
new Watcher(this._vm, '$data', function () {
if (!_this4._dispatching) {
if (!_this3._dispatching) {
throw new Error('[vuex] Do not mutate vuex store state outside mutation handlers.');
}
}, { deep: true, sync: true });
@@ -522,7 +545,7 @@
}, {
key: '_setupMiddlewares',
value: function _setupMiddlewares(middlewares, state) {
var _this5 = this;
var _this4 = this;

this._middlewares = [devtoolMiddleware].concat(middlewares);
this._needSnapshots = middlewares.some(function (m) {
@@ -535,7 +558,38 @@
// call init hooks
this._middlewares.forEach(function (m) {
if (m.onInit) {
m.onInit(m.snapshot ? initialSnapshot : state, _this5);
m.onInit(m.snapshot ? initialSnapshot : state, _this4);
}
});
}

/**
* Apply the middlewares on a given mutation.
*
* @param {String} type
* @param {Array} payload
*/

}, {
key: '_applyMiddlewares',
value: function _applyMiddlewares(type, payload) {
var _this5 = this;

var state = this.state;
var prevSnapshot = this._prevSnapshot;
var snapshot = void 0,
clonedPayload = void 0;
if (this._needSnapshots) {
snapshot = this._prevSnapshot = deepClone(state);
clonedPayload = deepClone(payload);
}
this._middlewares.forEach(function (m) {
if (m.onMutation) {
if (m.snapshot) {
m.onMutation({ type: type, payload: clonedPayload }, snapshot, prevSnapshot, _this5);
} else {
m.onMutation({ type: type, payload: payload }, state, _this5);
}
}
});
}
@@ -552,6 +606,10 @@
}();

function install(_Vue) {
if (Vue) {
console.warn('[vuex] already installed. Vue.use(Vuex) should be called only once.');
return;
}
Vue = _Vue;
override(Vue);
}
Loading