Skip to content

Commit f0747cf

Browse files
Partial rewrite for Vue 2.0 compatibility
1 parent 3f7b443 commit f0747cf

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
33
# Changelog
44

5+
- [2.0.0-rc1](#200-rc1)
56
- [v1.4.0](#v140)
67
- [v1.2.0](#v120)
78
- [v1.1.0](#v110)
89
- [v1.0.0](#v100)
910

1011
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1112

13+
### 2.0.0-rc1
14+
* Supports the Vue 2.0 release candidate.
15+
* Note that this itself is an alpha version, which might not work if Vue's internals change again before the final release of Vue 2.0. Use with caution.
16+
1217
### v1.4.0
1318
* Add CommonJS support
1419

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
"url": "https://github.com/foxbenjaminfox/vue-async-computed/issues"
4444
},
4545
"homepage": "https://github.com/foxbenjaminfox/vue-async-computed#readme",
46+
"peerDependencies": {
47+
"vue": "^2.0.0-rc.4"
48+
},
4649
"devDependencies": {
4750
"babel-cli": "^6.6.5",
4851
"babel-core": "^6.7.7",
@@ -61,7 +64,7 @@
6164
"rimraf": "^2.5.2",
6265
"tap-spec": "^4.1.1",
6366
"tape": "^4.5.1",
64-
"vue": "^1.0.20",
67+
"vue": "^2.0.0-rc.4",
6568
"watch": "^0.17.1"
6669
}
6770
}

src/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,29 @@ export default {
99
.asyncComputed = Vue.config.optionMergeStrategies.computed
1010

1111
Vue.mixin({
12-
created () {
12+
beforeCreate () {
13+
const optionData = this.$options.data
14+
const newData = {}
15+
16+
if (!this.$options.computed) this.$options.computed = {}
17+
1318
Object.keys(this.$options.asyncComputed || {}).forEach(key => {
1419
const fn = this.$options.asyncComputed[key]
15-
if (!this.$options.computed) this.$options.computed = {}
16-
Vue.set(this.$options.computed, prefix + key, fn)
17-
Vue.set(this, key, null)
20+
this.$options.computed[prefix + key] = fn
21+
newData[key] = null
1822
})
1923

20-
this._initComputed()
21-
24+
this.$options.data = function vueAsyncComputedInjectedDataFn () {
25+
const data = (
26+
(typeof optionData === 'function')
27+
? optionData.call(this)
28+
: optionData
29+
) || {}
30+
Object.keys(newData).forEach(key => { data[key] = newData[key] })
31+
return data
32+
}
33+
},
34+
created () {
2235
Object.keys(this.$options.asyncComputed || {}).forEach(key => {
2336
let promiseId = 0
2437
this.$watch(prefix + key, newPromise => {

0 commit comments

Comments
 (0)