Skip to content

Commit

Permalink
[docs] using vuepress (vuejs#1277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinjiang authored and yyx990803 committed May 21, 2018
1 parent d1a1d01 commit 2a91153
Show file tree
Hide file tree
Showing 164 changed files with 8,314 additions and 3,052 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
node_modules
TODO.md
lib
docs/_book
docs/.vuepress/dist
examples/**/build.js
types/typings
types/test/*.js
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
Empty file added docs/.vuepress/_redirects
Empty file.
104 changes: 104 additions & 0 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
module.exports = {
locales: {
'/': {
lang: 'en-US',
title: 'Vuex',
description: 'Centralized State Management for Vue.js'
},
'/zh/': {
lang: 'zh-CN',
title: 'Vuex',
description: 'Vue.js 的中心化状态管理方案'
}
},
serviceWorker: true,
theme: 'vue',
themeConfig: {
repo: 'vuejs/vuex',
docsDir: 'docs',
locales: {
'/': {
label: 'English',
selectText: 'Languages',
editLinkText: 'Edit this page on GitHub',
nav: [
{
text: 'Getting Started',
link: '/getting-started'
},
{
text: 'API Reference',
link: '/api'
},
{
text: 'Release Notes',
link: 'https://github.com/vuejs/vuex/releases'
}
],
sidebar: [
'/installation',
'/',
'/getting-started',
{
title: 'Core Concepts',
collapsable: false,
children: [
'/state',
'/getters',
'/mutations',
'/actions',
'/modules'
]
},
'/structure',
'/plugins',
'/strict',
'/forms',
'/testing',
'/hot-reload'
]
},
'/zh/': {
label: '简体中文',
selectText: '选择语言',
editLinkText: '在 GitHub 上编辑此页',
nav: [
{
text: '指南',
link: '/zh/getting-started'
},
{
text: 'API 参考',
link: '/zh/api'
},
{
text: '更新记录',
link: 'https://github.com/vuejs/vuex/releases'
}
],
sidebar: [
'/zh/installation',
'/zh/',
'/zh/getting-started',
{
title: '核心概念',
collapsable: false,
children: [
'/zh/state',
'/zh/getters',
'/zh/mutations',
'/zh/actions',
'/zh/modules'
]
},
'/zh/structure',
'/zh/plugins',
'/zh/strict',
'/zh/forms',
'/zh/testing',
'/zh/hot-reload'
]
}
}
}
}
File renamed without changes
File renamed without changes
4 changes: 2 additions & 2 deletions docs/en/intro.md → docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ It is a self-contained app with the following parts:
This is an extremely simple representation of the concept of "one-way data flow":

<p style="text-align: center; margin: 2em">
<img style="width:100%;max-width:450px;" src="./images/flow.png">
<img style="width:100%;max-width:450px;" src="/flow.png">
</p>

However, the simplicity quickly breaks down when we have **multiple components that share common state**:
Expand All @@ -52,7 +52,7 @@ In addition, by defining and separating the concepts involved in state managemen

This is the basic idea behind Vuex, inspired by [Flux](https://facebook.github.io/flux/docs/overview.html), [Redux](http://redux.js.org/) and [The Elm Architecture](https://guide.elm-lang.org/architecture/). Unlike the other patterns, Vuex is also a library implementation tailored specifically for Vue.js to take advantage of its granular reactivity system for efficient updates.

![vuex](./images/vuex.png)
![vuex](/vuex.png)

### When Should I Use It?

Expand Down
File renamed without changes.
263 changes: 263 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
---
sidebar: auto
---

# API Reference

## Vuex.Store

``` js
import Vuex from 'vuex'

const store = new Vuex.Store({ ...options })
```

## Vuex.Store Constructor Options

### state

- type: `Object | Function`

The root state object for the Vuex store. [Details](state.md)

If you pass a function that returns an object, the returned object is used as the root state. This is useful when you want to reuse the state object especially for module reuse. [Details](modules.md#module-reuse)

### mutations

- type: `{ [type: string]: Function }`

Register mutations on the store. The handler function always receives `state` as the first argument (will be module local state if defined in a module), and receives a second `payload` argument if there is one.

[Details](mutations.md)

### actions

- type: `{ [type: string]: Function }`

Register actions on the store. The handler function receives a `context` object that exposes the following properties:

``` js
{
state, // same as `store.state`, or local state if in modules
rootState, // same as `store.state`, only in modules
commit, // same as `store.commit`
dispatch, // same as `store.dispatch`
getters, // same as `store.getters`, or local getters if in modules
rootGetters // same as `store.getters`, only in modules
}
```

And also receives a second `payload` argument if there is one.

[Details](actions.md)

### getters

- type: `{ [key: string]: Function }`

Register getters on the store. The getter function receives the following arguments:

```
state, // will be module local state if defined in a module.
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)

### modules

- type: `Object`

An object containing sub modules to be merged into the store, in the shape of:

``` js
{
key: {
state,
namespaced?,
mutations?,
actions?,
getters?,
modules?
},
...
}
```
Each module can contain `state` and `mutations` similar to the root options. A module's state will be attached to the store's root state using the module's key. A module's mutations and getters will only receives the module's local state as the first argument instead of the root state, and module actions' `context.state` will also point to the local state.
[Details](modules.md)
### plugins
- type: `Array<Function>`
An array of plugin functions to be applied to the store. The plugin simply receives the store as the only argument and can either listen to mutations (for outbound data persistence, logging, or debugging) or dispatch mutations (for inbound data e.g. websockets or observables).
[Details](plugins.md)
### strict
- type: `Boolean`
- default: `false`
Force the Vuex store into strict mode. In strict mode any mutations to Vuex state outside of mutation handlers will throw an Error.
[Details](strict.md)
## Vuex.Store Instance Properties
### state
- type: `Object`
The root state. Read only.
### getters
- type: `Object`
Exposes registered getters. Read only.
## Vuex.Store Instance Methods
### commit
- `commit(type: string, payload?: any, options?: Object)`
- `commit(mutation: Object, options?: Object)`
Commit a mutation. `options` can have `root: true` that allows to commit root mutations in [namespaced modules](modules.md#namespacing). [Details](mutations.md)
### dispatch
- `dispatch(type: string, payload?: any, options?: Object)`
- `dispatch(action: Object, options?: Object)`
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
- `replaceState(state: Object)`
Replace the store's root state. Use this only for state hydration / time-travel purposes.
### watch
- `watch(fn: Function, callback: Function, options?: Object): Function`
Reactively watch `fn`'s return value, and call the callback when the value changes. `fn` receives the store's state as the first argument, and getters as the second argument. Accepts an optional options object that takes the same options as Vue's `vm.$watch` method.
To stop watching, call the returned unwatch function.
### subscribe
- `subscribe(handler: Function): Function`
Subscribe to store mutations. The `handler` is called after every mutation and receives the mutation descriptor and post-mutation state as arguments:
``` js
store.subscribe((mutation, state) => {
console.log(mutation.type)
console.log(mutation.payload)
})
```
To stop subscribing, call the returned unsubscribe function.
Most commonly used in plugins. [Details](plugins.md)
### subscribeAction
- `subscribeAction(handler: Function): Function`
> New in 2.5.0
Subscribe to store actions. The `handler` is called for every dispatched action and receives the action descriptor and current store state as arguments:
``` js
store.subscribeAction((action, state) => {
console.log(action.type)
console.log(action.payload)
})
```
To stop subscribing, call the returned unsubscribe function.
Most commonly used in plugins. [Details](plugins.md)
### registerModule
- `registerModule(path: string | Array<string>, module: Module, options?: Object)`
Register a dynamic module. [Details](modules.md#dynamic-module-registration)
`options` can have `preserveState: true` that allows to preserve the previous state. Useful with Server Side Rendering.
### unregisterModule
- `unregisterModule(path: string | Array<string>)`
Unregister a dynamic module. [Details](modules.md#dynamic-module-registration)
### hotUpdate
- `hotUpdate(newOptions: Object)`
Hot swap new actions and mutations. [Details](hot-reload.md)
## Component Binding Helpers
### mapState
- `mapState(namespace?: string, map: Array<string> | Object<string | function>): Object`

Create component computed options that return the sub tree of the Vuex store. [Details](state.md#the-mapstate-helper)

The first argument can optionally be a namespace string. [Details](modules.md#binding-helpers-with-namespace)

The second object argument's members can be a function. `function(state: any)`

### mapGetters

- `mapGetters(namespace?: string, map: Array<string> | Object<string>): Object`

Create component computed options that return the evaluated value of a getter. [Details](getters.md#the-mapgetters-helper)

The first argument can optionally be a namespace string. [Details](modules.md#binding-helpers-with-namespace)

### mapActions

- `mapActions(namespace?: string, map: Array<string> | Object<string | function>): Object`

Create component methods options that dispatch an action. [Details](actions.md#dispatching-actions-in-components)

The first argument can optionally be a namespace string. [Details](modules.md#binding-helpers-with-namespace)

The second object argument's members can be a function. `function(dispatch: function, ...args: any[])`

### mapMutations

- `mapMutations(namespace?: string, map: Array<string> | Object<string | function>): Object`

Create component methods options that commit a mutation. [Details](mutations.md#committing-mutations-in-components)

The first argument can optionally be a namespace string. [Details](modules.md#binding-helpers-with-namespace)

 The second object argument's members can be a function. `function(commit: function, ...args: any[])`

### createNamespacedHelpers

- `createNamespacedHelpers(namespace: string): Object`

Create namespaced component binding helpers. The returned object contains `mapState`, `mapGetters`, `mapActions` and `mapMutations` that are bound with the given namespace. [Details](modules.md#binding-helpers-with-namespace)
File renamed without changes.
Loading

0 comments on commit 2a91153

Please sign in to comment.