Skip to content

Commit 9624f31

Browse files
committed
update for 2.0
1 parent 8d11d11 commit 9624f31

File tree

11 files changed

+45
-52
lines changed

11 files changed

+45
-52
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
}

examples/chat/components/MessageSection.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div class="message-section">
33
<h3 class="message-thread-heading">{{ thread.name }}</h3>
4-
<ul class="message-list" v-el:list>
4+
<ul class="message-list" ref="list">
55
<message
6-
v-for="message in messages | orderBy 'timestamp'"
6+
v-for="message in sortedMessages"
77
track-by="id"
88
:message="message">
99
</message>
@@ -28,10 +28,17 @@ export default {
2828
sendMessage
2929
}
3030
},
31+
computed: {
32+
sortedMessages () {
33+
return this.messages
34+
.slice()
35+
.sort((a, b) => a.timestamp - b.timestamp)
36+
}
37+
},
3138
watch: {
3239
'thread.lastMessage': function () {
3340
this.$nextTick(() => {
34-
const ul = this.$els.list
41+
const ul = this.$refs.list
3542
ul.scrollTop = ul.scrollHeight
3643
})
3744
}

examples/chat/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<link href="http://fonts.googleapis.com/css?family=Muli" rel="stylesheet" type="text/css">
77
</head>
88
<body>
9-
<app></app>
9+
<div id="app"></div>
1010
<script src="build.js"></script>
1111
</body>
1212
</html>

examples/chat/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Vue.filter('time', timestamp => {
1111
})
1212

1313
new Vue({
14-
el: 'body',
14+
el: '#app',
1515
store,
16-
components: { App }
16+
render: h => h(App)
1717
})
1818

1919
getAllMessages(store)

examples/counter/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<title>vuex counter example</title>
66
</head>
77
<body>
8-
<counter></counter>
8+
<div id="app"></div>
99
<script src="build.js"></script>
1010
</body>
1111
</html>

examples/counter/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Counter from './Counter.vue'
33
import store from './store'
44

55
new Vue({
6-
el: 'body',
6+
el: '#app',
77
store,
8-
components: { Counter }
8+
render: h => h(Counter)
99
})

package.json

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vuex",
3-
"version": "0.6.3",
3+
"version": "0.7.0",
44
"description": "state management for Vue.js",
55
"main": "dist/vuex.js",
66
"files": [
@@ -46,22 +46,17 @@
4646
"chai": "^3.4.1",
4747
"css-loader": "^0.23.1",
4848
"eslint": "^2.2.0",
49-
"eslint-config-standard": "^5.1.0",
50-
"eslint-plugin-promise": "^1.0.8",
51-
"eslint-plugin-standard": "^1.3.2",
49+
"eslint-config-vue": "^1.0.0",
5250
"function-bind": "^1.1.0",
5351
"mocha": "^2.3.4",
54-
"rollup": "^0.25.4",
52+
"rollup": "^0.32.0",
5553
"rollup-plugin-babel": "^2.4.0",
5654
"sinon": "^1.17.3",
5755
"sinon-chai": "^2.8.0",
5856
"todomvc-app-css": "^2.0.3",
5957
"uglify-js": "^2.6.2",
60-
"vue": "^1.0.17",
61-
"vue-hot-reload-api": "^1.2.1",
62-
"vue-html-loader": "^1.0.0",
63-
"vue-loader": "^8.2.0",
64-
"vue-style-loader": "^1.0.0",
58+
"vue": "^2.0.0-alpha.5",
59+
"vue-loader": "^9.0.1",
6560
"webpack": "^1.12.8",
6661
"webpack-dev-server": "^1.12.1"
6762
}

src/index.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class Store {
4343
const silent = Vue.config.silent
4444
Vue.config.silent = true
4545
this._vm = new Vue({
46-
data: state
46+
data: {
47+
state
48+
}
4749
})
4850
Vue.config.silent = silent
4951
this._setupModuleState(state, modules)
@@ -63,7 +65,7 @@ class Store {
6365
*/
6466

6567
get state () {
66-
return this._vm._data
68+
return this._vm.state
6769
}
6870

6971
set state (v) {
@@ -106,17 +108,17 @@ class Store {
106108
* Same API as Vue's $watch, except when watching a function,
107109
* the function gets the state as the first argument.
108110
*
109-
* @param {String|Function} expOrFn
111+
* @param {Function} fn
110112
* @param {Function} cb
111113
* @param {Object} [options]
112114
*/
113115

114-
watch (expOrFn, cb, options) {
115-
return this._vm.$watch(() => {
116-
return typeof expOrFn === 'function'
117-
? expOrFn(this.state)
118-
: this._vm.$get(expOrFn)
119-
}, cb, options)
116+
watch (fn, cb, options) {
117+
if (typeof fn !== 'function') {
118+
console.error('Vuex store.watch only accepts function.')
119+
return
120+
}
121+
return this._vm.$watch(() => fn(this.state), cb, options)
120122
}
121123

122124
/**
@@ -186,7 +188,7 @@ class Store {
186188
_setupMutationCheck () {
187189
const Watcher = getWatcher(this._vm)
188190
/* eslint-disable no-new */
189-
new Watcher(this._vm, '$data', () => {
191+
new Watcher(this._vm, 'state', () => {
190192
if (!this._dispatching) {
191193
throw new Error(
192194
'[vuex] Do not mutate vuex store state outside mutation handlers.'

src/override.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import { getWatcher, getDep } from './util'
22

33
export default function (Vue) {
4-
// override init and inject vuex init procedure
5-
const _init = Vue.prototype._init
6-
Vue.prototype._init = function (options = {}) {
7-
options.init = options.init
8-
? [vuexInit].concat(options.init)
9-
: vuexInit
10-
_init.call(this, options)
11-
}
4+
Vue.mixin({ init })
125

136
/**
147
* Vuex init hook, injected into each instances init hooks list.
158
*/
169

17-
function vuexInit () {
10+
function init () {
1811
const options = this.$options
1912
const { store, vuex } = options
2013
// store injection
@@ -31,7 +24,8 @@ export default function (Vue) {
3124
'provide the store option in your root component.'
3225
)
3326
}
34-
let { state, getters, actions } = vuex
27+
const { state, actions } = vuex
28+
let { getters } = vuex
3529
// handle deprecated state option
3630
if (state && !getters) {
3731
console.warn(
@@ -43,14 +37,14 @@ export default function (Vue) {
4337
// getters
4438
if (getters) {
4539
options.computed = options.computed || {}
46-
for (let key in getters) {
40+
for (const key in getters) {
4741
defineVuexGetter(this, key, getters[key])
4842
}
4943
}
5044
// actions
5145
if (actions) {
5246
options.methods = options.methods || {}
53-
for (let key in actions) {
47+
for (const key in actions) {
5448
options.methods[key] = makeBoundAction(this.$store, actions[key], key)
5549
}
5650
}
@@ -109,7 +103,7 @@ export default function (Vue) {
109103
const Dep = getDep(vm)
110104
const watcher = new Watcher(
111105
vm,
112-
state => getter(state),
106+
vm => getter(vm.state),
113107
null,
114108
{ lazy: true }
115109
)

src/util.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ export function deepClone (obj) {
5656
let Watcher
5757
export function getWatcher (vm) {
5858
if (!Watcher) {
59-
const unwatch = vm.$watch('__vuex__', a => a)
59+
const noop = function () {}
60+
const unwatch = vm.$watch(noop, noop)
6061
Watcher = vm._watchers[0].constructor
6162
unwatch()
6263
}

0 commit comments

Comments
 (0)