Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upstream merge #27

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
IMPORTANT: Please use the following link to create a new issue:

https://new-issue.vuejs.org/?repo=vuejs/vuex

If your issue was not created using the app above, it will be closed immediately.
-->
1 change: 1 addition & 0 deletions dist/logger.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Payload, Plugin } from "../types/index";

export interface LoggerOption<S> {
collapsed?: boolean;
filter?: <P extends Payload>(mutation: P, stateBefore: S, stateAfter: S) => boolean;
transformer?: (state: S) => any;
mutationTransformer?: <P extends Payload>(mutation: P) => any;
}
Expand Down
14 changes: 6 additions & 8 deletions dist/vuex.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v2.2.1
* vuex v2.3.0
* (c) 2017 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -100,13 +100,11 @@ var Module = function Module (rawModule, runtime) {
this.runtime = runtime;
this._children = Object.create(null);
this._rawModule = rawModule;
var rawState = rawModule.state;
this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
};

var prototypeAccessors$1 = { state: {},namespaced: {} };

prototypeAccessors$1.state.get = function () {
return this._rawModule.state || {}
};
var prototypeAccessors$1 = { namespaced: {} };

prototypeAccessors$1.namespaced.get = function () {
return !!this._rawModule.namespaced
Expand Down Expand Up @@ -470,7 +468,7 @@ function installModule (store, rootState, path, module, hot) {
var namespace = store._modules.getNamespace(path);

// register in namespace map
if (namespace) {
if (module.namespaced) {
store._modulesNamespaceMap[namespace] = module;
}

Expand Down Expand Up @@ -793,7 +791,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index_esm = {
Store: Store,
install: install,
version: '2.2.1',
version: '2.3.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
14 changes: 6 additions & 8 deletions dist/vuex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* vuex v2.2.1
* vuex v2.3.0
* (c) 2017 Evan You
* @license MIT
*/
Expand Down Expand Up @@ -106,13 +106,11 @@ var Module = function Module (rawModule, runtime) {
this.runtime = runtime;
this._children = Object.create(null);
this._rawModule = rawModule;
var rawState = rawModule.state;
this.state = (typeof rawState === 'function' ? rawState() : rawState) || {};
};

var prototypeAccessors$1 = { state: {},namespaced: {} };

prototypeAccessors$1.state.get = function () {
return this._rawModule.state || {}
};
var prototypeAccessors$1 = { namespaced: {} };

prototypeAccessors$1.namespaced.get = function () {
return !!this._rawModule.namespaced
Expand Down Expand Up @@ -476,7 +474,7 @@ function installModule (store, rootState, path, module, hot) {
var namespace = store._modules.getNamespace(path);

// register in namespace map
if (namespace) {
if (module.namespaced) {
store._modulesNamespaceMap[namespace] = module;
}

Expand Down Expand Up @@ -799,7 +797,7 @@ function getModuleByNamespace (store, helper, namespace) {
var index = {
Store: Store,
install: install,
version: '2.2.1',
version: '2.3.0',
mapState: mapState,
mapMutations: mapMutations,
mapGetters: mapGetters,
Expand Down
4 changes: 2 additions & 2 deletions dist/vuex.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/en/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Vuex

<!--email_off-->
> Note: This is docs for [email protected].
<!--/email_off-->

- [Looking for 1.0 Docs?](https://github.com/vuejs/vuex/tree/1.0/docs)
- [Release Notes](https://github.com/vuejs/vuex/releases)
Expand Down
21 changes: 15 additions & 6 deletions docs/en/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ const store = new Vuex.Store({ ...options })

```
state, // will be module local state if defined in a module.
getters, // same as store.getters
rootState // same as store.state
getters // same as store.getters
```

Specific when defined in a module

```
state, // will be module local state if defined in a module.
getters, // module local getters of the current module
rootState, // global state
rootGetters // all getters
```

Registered getters are exposed on `store.getters`.

[Details](getters.md)
Expand Down Expand Up @@ -116,13 +125,13 @@ const store = new Vuex.Store({ ...options })

### Vuex.Store Instance Methods

- **`commit(type: string, payload?: any) | commit(mutation: Object)`**
- **`commit(type: string, payload?: any, options?: Object) | commit(mutation: Object, options?: Object)`**

Commit a mutation. [Details](mutations.md)
Commit a mutation. `options` can have `root: true` that allows to commit root mutations in [namespaced modules](modules.md#namespacing). [Details](mutations.md)

- **`dispatch(type: string, payload?: any) | dispatch(action: Object)`**
- **`dispatch(type: string, payload?: any, options?: Object) | dispatch(action: Object, options?: Object)`**

Dispatch an action. Returns a Promise that resolves all triggered action handlers. [Details](actions.md)
Dispatch an action. `options` can have `root: true` that allows to dispatch root actions in [namespaced modules](modules.md#namespacing). Returns a Promise that resolves all triggered action handlers. [Details](actions.md)

- **`replaceState(state: Object)`**

Expand Down
2 changes: 1 addition & 1 deletion docs/en/getters.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ You can also pass arguments to getters by returning a function. This is particul
getters: {
// ...
getTodoById: (state, getters) => (id) => {
return getters.todos.find(todo => todo.id === id)
return state.todos.find(todo => todo.id === id)
}
}
```
Expand Down
24 changes: 23 additions & 1 deletion docs/en/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ store.state.b // -> moduleB's state

### Module Local State

Inside a module's mutations and getters, The first argument received will be **the module's local state**.
Inside a module's mutations and getters, the first argument received will be **the module's local state**.

``` js
const moduleA = {
Expand Down Expand Up @@ -243,3 +243,25 @@ The module's state will be exposed as `store.state.myModule` and `store.state.ne
Dynamic module registration makes it possible for other Vue plugins to also leverage Vuex for state management by attaching a module to the application's store. For example, the [`vuex-router-sync`](https://github.com/vuejs/vuex-router-sync) library integrates vue-router with vuex by managing the application's route state in a dynamically attached module.

You can also remove a dynamically registered module with `store.unregisterModule(moduleName)`. Note you cannot remove static modules (declared at store creation) with this method.

### Module Reuse

Sometimes we may need to create multiple instances of a module, for example:

- Creating multiple stores that uses the same module;
- Register the same module multiple times in the same store.

If we use a plain object to declare the state of the module, then that state object will be shared by reference and cause cross store/module state pollution when it's mutated.

This is actually the exact same problem with `data` inside Vue components. So the solution is also the same - use a function for declaring module state (supported in 2.3.0+):

``` js
const MyReusableModule = {
state () {
return {
foo: 'bar'
}
},
// mutations, actions, getters...
}
```
5 changes: 4 additions & 1 deletion docs/en/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ export default {
// ...
methods: {
...mapMutations([
'increment' // map this.increment() to this.$store.commit('increment')
'increment', // map this.increment() to this.$store.commit('increment')

// mapMutations also supports payloads:
'incrementBy' // this.incrementBy(amount) maps to this.$store.commit('incrementBy', amount)
]),
...mapMutations({
add: 'increment' // map this.add() to this.$store.commit('increment')
Expand Down
5 changes: 5 additions & 0 deletions docs/en/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ The `createLogger` function takes a few options:
``` js
const logger = createLogger({
collapsed: false, // auto-expand logged mutations
filter (mutation, stateBefore, stateAfter) {
// returns true if a mutation should be logged
// `mutation` is a { type, payload }
return mutation.type !== "aBlacklistedMutation"
},
transformer (state) {
// transform the state before logging it.
// for example return only a specific sub-tree
Expand Down
2 changes: 1 addition & 1 deletion docs/en/strict.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ In strict mode, whenever Vuex state is mutated outside of mutation handlers, an

### Development vs. Production

**Do not enable strict mode when deploying for production!** Strict mode runs a deep watch on the state tree for detecting inappropriate mutations - make sure to turn it off in production to avoid the performance cost.
**Do not enable strict mode when deploying for production!** Strict mode runs a synchronous deep watcher on the state tree for detecting inappropriate mutations, and it can be quite expensive when you make large amount of mutations to the state. Make sure to turn it off in production to avoid the performance cost.

Similar to plugins, we can let the build tools handle that:

Expand Down
2 changes: 1 addition & 1 deletion docs/en/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ module.exports = {
loaders: [
{
test: /\.js$/,
loader: 'babel',
loader: 'babel-loader',
exclude: /node_modules/
}
]
Expand Down
2 changes: 2 additions & 0 deletions docs/fr/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Vuex

<!--email_off-->
> Note : Ceci est la documentation pour [email protected].
<!--/email_off-->

- [Vous cherchez la documentation de la v1.0 ?](https://github.com/vuejs/vuex/tree/1.0/docs)
- [Release Notes](https://github.com/vuejs/vuex/releases)
Expand Down
2 changes: 1 addition & 1 deletion docs/fr/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ Utiliser le state du store dans un composant implique simplement de retourner le

Voici un exemple de la [plus basique app Vuex de compteur](https://jsfiddle.net/n9jmu5v7/341/).

Ensuite, nous allons examiner chaque concept de base plus en détails, et commençon avec le [State](state.md).
Ensuite, nous allons examiner chaque concept de base plus en détails, et commençons avec le [State](state.md).
6 changes: 3 additions & 3 deletions docs/fr/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ store.commit({
})
```

Lors de l'utlisation de l'object-style commit, l'objet entier sera fournit comme payload aux handlers de mutation, donc le handler reste inchangé :
Lors de l'utlisation de l'object-style commit, l'objet entier sera fourni comme payload aux handlers de mutation, donc le handler reste inchangé :

``` js
mutations: {
Expand All @@ -79,7 +79,7 @@ mutations: {

Puisqu'un state de store de Vuex est rendu réactif par Vue, lorsque nous mutons le state, les composants Vue observant ce state seront automatiquement mis à jour. Cela signifie également que les mutations Vuex sont sujettes aux mêmes inconvénients que lorsqu'on travaille avec Vue :

1. Initialisez de préférences le state initial de votre state avec tous les champs désirés auparavant.
1. Initialisez de préférence le state initial de votre state avec tous les champs désirés auparavant.

2. Lorsque vous ajoutez de nouvelles propriétés à un Object, vous devriez soit :

Expand Down Expand Up @@ -157,7 +157,7 @@ export default {

### En avant vers les actions

L'asynchronisme combiné à la mutation du state peut rendre votre program très difficile à comprendre. Par exemple, lorsque vous appelez deux méthodes avec toutes les deux des callbacks asynchrones qui changent le state, comment savez-vous quand elles sont appelées et quel callback est appelé en premier ? C'est exactement la raison pour laquelle nous voulons séparer les deux concepts. Avec Vuex, **les mutations sont des transactions synchrones** :
L'asynchronisme combiné à la mutation du state peut rendre votre programme très difficile à comprendre. Par exemple, lorsque vous appelez deux méthodes avec toutes les deux des callbacks asynchrones qui changent le state, comment savez-vous quand elles sont appelées et quel callback est appelé en premier ? C'est exactement la raison pour laquelle nous voulons séparer les deux concepts. Avec Vuex, **les mutations sont des transactions synchrones** :

``` js
store.commit('increment')
Expand Down
5 changes: 5 additions & 0 deletions docs/fr/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ La fonction `createLogger` prend quelques options :
``` js
const logger = createLogger({
collapsed: false, // auto-expand logged mutations
filter (mutation, stateBefore, stateAfter) {
// returns true if a mutation should be logged
// `mutation` is a { type, payload }
return mutation.type !== "aBlacklistedMutation"
},
transformer (state) {
// transform the state before logging it.
// for example return only a specific sub-tree
Expand Down
2 changes: 1 addition & 1 deletion docs/fr/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ computed: {
}
```

### Les composants peuvent toujours avec un state local
### Les composants peuvent toujours avoir un state local

Utiliser Vuex ne signifie pas que vous devez mettre **tout** votre state dans Vuex. Bien que le fait de mettre plus de state dans Vuex rende vos mutations de state plus explicites et plus debuggables, parfois il peut aussi rendre le code plus verbeux et indirect. Si une partie de state appartient directement à un seul composant, il est parfaitement sain de la laisser dans le state local. Assurez vous de prendre en compte les avantages et inconvénients d'une telle décision afin de vous adaptez le mieux aux besoins de votre application.
4 changes: 2 additions & 2 deletions docs/fr/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Les parties principales que l'on veut couvrir par des tests unitaires en Vuex so

### Tester les mutations

Les mutations sont très simples à tester, parce que ce sont juste des fonctions qui se passent complètement sur leurs arguments. Une astuce est que si vous utilisez les modules ES2015 et mettez vos mutations dans votre fichier `store.js`, en plus de l'export par défaut, vous pouvez également vos mutations avec un export nommé :
Les mutations sont très simples à tester, puisque ce sont de simples fonctions qui se basent uniquement sur leurs arguments. Une astuce est que si vous utilisez les modules ES2015 et mettez vos mutations dans votre fichier `store.js`, en plus de l'export par défaut, vous pouvez également exporter vos mutations avec un export nommé :

``` js
const state = { ... }
Expand Down Expand Up @@ -189,7 +189,7 @@ module.exports = {
loaders: [
{
test: /\.js$/,
loader: 'babel',
loader: 'babel-loader',
exclude: /node_modules/
}
]
Expand Down
2 changes: 2 additions & 0 deletions docs/ja/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Vuex

<!--email_off-->
> 注意: これは [email protected] のドキュメントです
<!--/email_off-->

- [1.0のドキュメントをお探しですか?](https://github.com/vuejs/vuex/tree/1.0/docs/ja)
- [リリースノート](https://github.com/vuejs/vuex/releases)
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/getters.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ computed: {
getters: {
// ...
getTodoById: (state, getters) => (id) => {
return getters.todos.find(todo => todo.id === id)
return state.todos.find(todo => todo.id === id)
}
}
```
Expand Down
5 changes: 5 additions & 0 deletions docs/ja/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ const store = new Vuex.Store({
``` js
const logger = createLogger({
collapsed: false, // ログ出力されたミューテーションを自動で展開します
filter (mutation, stateBefore, stateAfter) {
// returns true if a mutation should be logged
// `mutation` is a { type, payload }
return mutation.type !== "aBlacklistedMutation"
},
transformer (state) {
// ロギングの前に、状態を変換します
// 例えば、特定のサブツリーのみを返します
Expand Down
4 changes: 2 additions & 2 deletions docs/ja/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ computed: mapState([

```js
computed: {
localComputed () { /* ... */ }.
localComputed () { /* ... */ },
// オブジェクトスプレット演算子で、外のオブジェクトとこのオブジェクトを混ぜる
...mapState({
// ...
Expand All @@ -103,4 +103,4 @@ computed: {

### コンポーネントはまだローカルステートを持つことできる

Vuex を使うということは、**全て**の状態を Vuex の中に置くべき、というわけではありません。多くの状態を Vuex に置くことで、状態の変更がさらに明示的、デバッグ可能になりますが、ときにはコードを冗長でまわりくどいものにします。状態の一部がひとつのコンポーネントだけに属している場合は、それをローカルの状態として残しておくとよいでしょう。あなたは、トレードオフを考慮した上で、あなたのアプリの開発ニーズに合った決定をすべきです。
Vuex を使うということは、**全て**の状態を Vuex の中に置くべき、というわけではありません。多くの状態を Vuex に置くことで、状態の変更がさらに明示的、デバッグ可能になりますが、ときにはコードを冗長でまわりくどいものにします。状態の一部がひとつのコンポーネントだけに属している場合は、それをローカルの状態として残しておくとよいでしょう。あなたは、トレードオフを考慮した上で、あなたのアプリの開発ニーズに合った決定をすべきです。
2 changes: 1 addition & 1 deletion docs/ja/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ module.exports = {
loaders: [
{
test: /\.js$/,
loader: 'babel',
loader: 'babel-loader',
exclude: /node_modules/
}
]
Expand Down
2 changes: 2 additions & 0 deletions docs/kr/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Vuex

<!--email_off-->
> 참고: 이 문서는 [email protected] 을 기준으로 합니다.
<!--/email_off-->

- [1.0 버전 문서를 보려면?](https://github.com/vuejs/vuex/tree/1.0/docs)
- [릴리즈 노트](https://github.com/vuejs/vuex/releases)
Expand Down
2 changes: 1 addition & 1 deletion docs/kr/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ new Vue({

Vuex는 공유된 상태 관리를 처리하는 데 유용하지만, 개념에 대한 이해와 시작하는 비용도 함께 듭니다. 그것은 단기간과 장기간 생산성 간의 기회비용이 있습니다.

대규모 SPA를 구축하지 않고 Vuex로 바로 뛰어 들었다면, 시간이 오래 걸리고 힘든일일 것입니다. 이것은 일반 적인 일입니다. 앱이 단순하다면 Vuex없이는 괜찮을 것입니다. 간단한 [글로벌 이벤트 버스](http://vuejs.org/guide/components.html#Non-Parent-Child-Communication)만 있으면됩니다. 그러나 중대형 규모의 SPA를 구축하는 경우 Vue컴포넌트 외부의 상태를 보다 잘 처리할 수 있는 방법을 생각하게 될 가능성이 있으며 Vuex는 자연스럽게 선택할 수 있는 단계가 될 것입니다. Redux의 저자인 Dan Abramov의 좋은 인용이 있습니다.
대규모 SPA를 구축하지 않고 Vuex로 바로 뛰어 들었다면, 시간이 오래 걸리고 힘든일일 것입니다. 이것은 일반 적인 일입니다. 앱이 단순하다면 Vuex없이는 괜찮을 것입니다. 간단한 [글로벌 이벤트 버스](https://kr.vuejs.org/v2/guide/components.html#비-부모-자식간-통신)만 있으면됩니다. 그러나 중대형 규모의 SPA를 구축하는 경우 Vue컴포넌트 외부의 상태를 보다 잘 처리할 수 있는 방법을 생각하게 될 가능성이 있으며 Vuex는 자연스럽게 선택할 수 있는 단계가 될 것입니다. Redux의 저자인 Dan Abramov의 좋은 인용이 있습니다.

> Flux 라이브러리는 안경과 같습니다. 필요할 때 알아볼 수 있습니다.
5 changes: 5 additions & 0 deletions docs/kr/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ const store = new Vuex.Store({
``` js
const logger = createLogger({
collapsed: false, // 로그를 가지는 변이 자동 확장
filter (mutation, stateBefore, stateAfter) {
// returns true if a mutation should be logged
// `mutation` is a { type, payload }
return mutation.type !== "aBlacklistedMutation"
},
transformer (state) {
// 로깅하기전 상태를 변이 하십시오.
// 예를 들어 특정 하위 트리만 반환합니다.
Expand Down
Loading