Skip to content

Commit 7c35cd4

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into working
2 parents b693198 + 8a4e485 commit 7c35cd4

27 files changed

+470
-106
lines changed

build/build.main.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const zlib = require('zlib')
4+
const uglify = require('uglify-js')
5+
const rollup = require('rollup')
6+
const configs = require('./configs')
7+
8+
if (!fs.existsSync('dist')) {
9+
fs.mkdirSync('dist')
10+
}
11+
12+
build(Object.keys(configs).map(key => configs[key]))
13+
14+
function build (builds) {
15+
let built = 0
16+
const total = builds.length
17+
const next = () => {
18+
buildEntry(builds[built]).then(() => {
19+
built++
20+
if (built < total) {
21+
next()
22+
}
23+
}).catch(logError)
24+
}
25+
26+
next()
27+
}
28+
29+
function buildEntry (config) {
30+
const isProd = /min\.js$/.test(config.dest)
31+
return rollup.rollup(config).then(bundle => {
32+
const code = bundle.generate(config).code
33+
if (isProd) {
34+
var minified = (config.banner ? config.banner + '\n' : '') + uglify.minify(code, {
35+
fromString: true,
36+
output: {
37+
/* eslint-disable camelcase */
38+
screw_ie8: true,
39+
ascii_only: true
40+
/* eslint-enable camelcase */
41+
}
42+
}).code
43+
return write(config.dest, minified, true)
44+
} else {
45+
return write(config.dest, code)
46+
}
47+
})
48+
}
49+
50+
function write (dest, code, zip) {
51+
return new Promise((resolve, reject) => {
52+
function report (extra) {
53+
console.log(blue(path.relative(process.cwd(), dest)) + ' ' + getSize(code) + (extra || ''))
54+
resolve()
55+
}
56+
57+
fs.writeFile(dest, code, err => {
58+
if (err) return reject(err)
59+
if (zip) {
60+
zlib.gzip(code, (err, zipped) => {
61+
if (err) return reject(err)
62+
report(' (gzipped: ' + getSize(zipped) + ')')
63+
})
64+
} else {
65+
report()
66+
}
67+
})
68+
})
69+
}
70+
71+
function getSize (code) {
72+
return (code.length / 1024).toFixed(2) + 'kb'
73+
}
74+
75+
function logError (e) {
76+
console.log(e)
77+
}
78+
79+
function blue (str) {
80+
return '\x1b[1m\x1b[34m' + str + '\x1b[39m\x1b[22m'
81+
}

build/configs.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const path = require('path')
2+
const buble = require('rollup-plugin-buble')
3+
const replace = require('rollup-plugin-replace')
4+
const version = process.env.VERSION || require('../package.json').version
5+
const banner =
6+
`/**
7+
* vuex v${version}
8+
* (c) ${new Date().getFullYear()} Evan You
9+
* @license MIT
10+
*/`
11+
12+
const resolve = _path => path.resolve(__dirname, '../', _path)
13+
14+
const configs = {
15+
umdDev: {
16+
entry: resolve('src/index.js'),
17+
dest: resolve('dist/vuex.js'),
18+
format: 'umd',
19+
env: 'development'
20+
},
21+
umdProd: {
22+
entry: resolve('src/index.js'),
23+
dest: resolve('dist/vuex.min.js'),
24+
format: 'umd',
25+
env: 'production'
26+
},
27+
commonjs: {
28+
entry: resolve('src/index.js'),
29+
dest: resolve('dist/vuex.common.js'),
30+
format: 'cjs'
31+
},
32+
esm: {
33+
entry: resolve('src/index.esm.js'),
34+
dest: resolve('dist/vuex.esm.js'),
35+
format: 'es'
36+
}
37+
}
38+
39+
function genConfig (opts) {
40+
const config = {
41+
entry: opts.entry,
42+
dest: opts.dest,
43+
format: opts.format,
44+
banner,
45+
moduleName: 'Vuex',
46+
plugins: [
47+
replace({
48+
__VERSION__: version
49+
}),
50+
buble()
51+
]
52+
}
53+
54+
if (opts.env) {
55+
config.plugins.unshift(replace({
56+
'process.env.NODE_ENV': JSON.stringify(opts.env)
57+
}))
58+
}
59+
60+
return config
61+
}
62+
63+
function mapValues (obj, fn) {
64+
const res = {}
65+
Object.keys(obj).forEach(key => {
66+
res[key] = fn(obj[key], key)
67+
})
68+
return res
69+
}
70+
71+
module.exports = mapValues(configs, genConfig)

build/rollup.config.js

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

build/rollup.dev.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./configs').commonjs

docs/en/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const Counter = {
6161
When a component needs to make use of multiple store state properties or getters, declaring all these computed properties can get repetitive and verbose. To deal with this we can make use of the `mapState` helper which generates computed getter functions for us to help us save some keystrokes:
6262

6363
``` js
64-
// in standalone builds helpers are exposed as Vuex.mapState
64+
// in full builds helpers are exposed as Vuex.mapState
6565
import { mapState } from 'vuex'
6666

6767
export default {

docs/en/testing.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ const testAction = (action, payload, state, expectedMutations, done) => {
9292
// mock commit
9393
const commit = (type, payload) => {
9494
const mutation = expectedMutations[count]
95-
expect(mutation.type).to.equal(type)
96-
if (payload) {
97-
expect(mutation.payload).to.deep.equal(payload)
95+
96+
try {
97+
expect(mutation.type).to.equal(type)
98+
if (payload) {
99+
expect(mutation.payload).to.deep.equal(payload)
100+
}
101+
} catch (error) {
102+
done(error)
98103
}
104+
99105
count++
100106
if (count >= expectedMutations.length) {
101107
done()

docs/fr/testing.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ const testAction = (action, args, state, expectedMutations, done) => {
9292
// mock commit
9393
const commit = (type, payload) => {
9494
const mutation = expectedMutations[count]
95-
expect(mutation.type).to.equal(type)
96-
if (payload) {
97-
expect(mutation.payload).to.deep.equal(payload)
95+
96+
try {
97+
expect(mutation.type).to.equal(type)
98+
if (payload) {
99+
expect(mutation.payload).to.deep.equal(payload)
100+
}
101+
} catch (error) {
102+
done(error)
98103
}
104+
99105
count++
100106
if (count >= expectedMutations.length) {
101107
done()

docs/ja/api.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@ const store = new Vuex.Store({ ...options })
5252

5353
```
5454
state, // モジュール内で定義されていればモジュールのローカルステート
55-
getters, // store.getters と同じ
56-
rootState // store.state と同じ
55+
getters // store.getters と同じ
56+
```
57+
58+
モジュールで定義されたときの仕様
59+
60+
```
61+
state, // モジュールで定義された場合、モジュールのローカルステート
62+
getters, // 現在のモジュールのモジュールのローカルゲッター
63+
rootState, // グローバルステート
64+
rootGetters // 全てのゲッター
5765
```
5866

5967
登録されたゲッターは `store.getters` 上に公開されます。
@@ -117,13 +125,13 @@ const store = new Vuex.Store({ ...options })
117125

118126
### Vuex.Store インスタンスメソッド
119127

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

122-
ミューテーションをコミットします。[詳細](mutations.md)
130+
ミューテーションをコミットします。`options` は[名前空間付きモジュール](modules.md#名前空間)で root なミューテーションにコミットできる `root: true` を持つことできます。[詳細](mutations.md)
123131

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

126-
アクションをディスパッチします。すべてのトリガーされたアクションハンドラを解決するPromiseを返します。[詳細](actions.md)
134+
アクションをディスパッチします。`options` は[名前空間付きモジュール](modules.md#名前空間)で root なアクションにディスパッチできる `root: true` を持つことできます。 すべてのトリガーされたアクションハンドラを解決するPromiseを返します。[詳細](actions.md)
127135

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

docs/ja/modules.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,25 @@ store.registerModule(['nested', 'myModule'], {
243243
動的なモジュール登録があることで、他の Vue プラグインが、モジュールをアプリケーションのストアに付属させることで、状態の管理に Vuex を活用できることができます。例えば [`vuex-router-sync`](https://github.com/vuejs/vuex-router-sync) ライブラリは、動的に付属させたモジュール内部でアプリケーションのルーティングのステートを管理することで vue-router と vuex を統合しています。
244244

245245
`store.unregisterModule(moduleName)` を呼び出せば、動的に登録したモジュールを削除できます。ただしストア作成(store creation)の際に宣言された、静的なモジュールはこのメソッドで削除できないことに注意してください。
246+
247+
### モジュールの再利用
248+
249+
時どき、モジュールの複数インスタンスを作成する必要があるかもしれません。例えば:
250+
251+
- 同じモジュールを使用する複数のストアを作成する;
252+
- 同じストアに同じモジュールを複数回登録する
253+
254+
モジュールの状態を宣言するために単純なオブジェクトを使用すると、その状態オブジェクトは参照によって共有され、変更時にクロスストア/モジュールの状態汚染を引き起こします。
255+
256+
これは、実際には Vue コンポーネント内部の `data` と全く同じ問題です。従って解決策も同じです。モジュールの状態を宣言するために関数を使用してください (2.3.0 以降でサポートされます):
257+
258+
``` js
259+
const MyReusableModule = {
260+
state () {
261+
return {
262+
foo: 'bar'
263+
}
264+
},
265+
// ミューテーション、アクション、ゲッター...
266+
}
267+
```

docs/ja/mutations.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ export default {
165165
// ...
166166
methods: {
167167
...mapMutations([
168-
'increment' // this.increment() を this.$store.commit('increment') にマッピングする
168+
'increment', // this.increment() を this.$store.commit('increment') にマッピングする
169+
170+
// mapMutations はペイロードサポートする:
171+
'incrementBy' // this.incrementBy(amount) を this.$store.commit('incrementBy', amount) にマッピングする
169172
]),
170173
...mapMutations({
171174
add: 'increment' // this.add() を this.$store.commit('increment') にマッピングする

docs/ja/plugins.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ const store = new Vuex.Store({
103103
const logger = createLogger({
104104
collapsed: false, // ログ出力されたミューテーションを自動で展開します
105105
filter (mutation, stateBefore, stateAfter) {
106+
// ミューテーションを記録する必要がある場合は、true を返します
106107
// returns true if a mutation should be logged
107-
// `mutation` is a { type, payload }
108+
// `mutation` { type, payload } です
108109
return mutation.type !== "aBlacklistedMutation"
109110
},
110111
transformer (state) {

docs/ja/state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const Counter = {
6060
コンポーネントが複数のストアのステートプロパティやゲッターを必要としているとき、これらすべてにおいて、算出プロパティを宣言することは繰り返しで冗長です。これに対処するため、算出ゲッター関数を生成し、いくつかのキーストロークを節約するのに役立つ `mapState` ヘルパーを使うことができます:
6161

6262
```js
63-
// スタンドアローンビルドでは、ヘルパーは Vuex.mapState として公開されています
63+
// 完全ビルドでは、ヘルパーは Vuex.mapState として公開されています
6464
import { mapState } from 'vuex'
6565

6666
export default {

docs/ja/testing.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,16 @@ const testAction = (action, payload, state, expectedMutations, done) => {
9191
// コミットをモックする
9292
const commit = (type, payload) => {
9393
const mutation = expectedMutations[count]
94-
expect(mutation.type).to.equal(type)
95-
if (payload) {
96-
expect(mutation.payload).to.deep.equal(payload)
94+
95+
try {
96+
expect(mutation.type).to.equal(type)
97+
if (payload) {
98+
expect(mutation.payload).to.deep.equal(payload)
99+
}
100+
} catch (error) {
101+
done(error)
97102
}
103+
98104
count++
99105
if (count >= expectedMutations.length) {
100106
done()

docs/kr/testing.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ const testAction = (action, payload, state, expectedMutations, done) => {
9292
// 모의 커밋
9393
const commit = (type, payload) => {
9494
const mutation = expectedMutations[count]
95-
expect(mutation.type).to.equal(type)
96-
if (payload) {
97-
expect(mutation.payload).to.deep.equal(payload)
95+
96+
try {
97+
expect(mutation.type).to.equal(type)
98+
if (payload) {
99+
expect(mutation.payload).to.deep.equal(payload)
100+
}
101+
} catch (error) {
102+
done(error)
98103
}
104+
99105
count++
100106
if (count >= expectedMutations.length) {
101107
done()

docs/ru/testing.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,16 @@ const testAction = (action, payload, state, expectedMutations, done) => {
9292
// поддельная функция вызова мутаций
9393
const commit = (type, payload) => {
9494
const mutation = expectedMutations[count]
95-
expect(mutation.type).to.equal(type)
96-
if (payload) {
97-
expect(mutation.payload).to.deep.equal(payload)
95+
96+
try {
97+
expect(mutation.type).to.equal(type)
98+
if (payload) {
99+
expect(mutation.payload).to.deep.equal(payload)
100+
}
101+
} catch (error) {
102+
done(error)
98103
}
104+
99105
count++
100106
if (count >= expectedMutations.length) {
101107
done()

0 commit comments

Comments
 (0)