vue-async-computed
Advanced tools
Comparing version 2.2.1 to 3.0.0
@@ -5,2 +5,3 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
- [v3.0.0](#v300) | ||
- [v2.1.1](#v211) | ||
@@ -16,2 +17,6 @@ - [v2.1.0](#v210) | ||
### v3.0.0 | ||
* Pass the raw error to the error handler when passed the `useRawError` option. | ||
* Allow default values to be given as functions. | ||
### v2.1.1 | ||
@@ -18,0 +23,0 @@ * Automatic installation when used in a script tag. |
@@ -32,3 +32,2 @@ (function (global, factory) { | ||
var optionData = this.$options.data; | ||
var newData = {}; | ||
@@ -38,8 +37,6 @@ if (!this.$options.computed) this.$options.computed = {}; | ||
Object.keys(this.$options.asyncComputed || {}).forEach(function (key) { | ||
var fn = _this.$options.asyncComputed[key]; | ||
var get = typeof fn === 'function' ? fn : fn.get, | ||
def = typeof fn.default === 'undefined' ? null : fn.default; | ||
var fn = _this.$options.asyncComputed[key], | ||
get = typeof fn === 'function' ? fn : fn.get; | ||
_this.$options.computed[prefix + key] = get; | ||
newData[key] = def; | ||
}); | ||
@@ -49,4 +46,4 @@ | ||
var data = (typeof optionData === 'function' ? optionData.call(this) : optionData) || {}; | ||
Object.keys(newData).forEach(function (key) { | ||
data[key] = newData[key]; | ||
Object.keys(this.$options.asyncComputed || {}).forEach(function (key) { | ||
data[key] = null; | ||
}); | ||
@@ -60,2 +57,13 @@ return data; | ||
Object.keys(this.$options.asyncComputed || {}).forEach(function (key) { | ||
var fn = _this2.$options.asyncComputed[key], | ||
def = typeof fn.default === 'undefined' ? null : fn.default; | ||
if (typeof def === 'function') { | ||
_this2[key] = def.call(_this2); | ||
} else { | ||
_this2[key] = def; | ||
} | ||
}); | ||
Object.keys(this.$options.asyncComputed || {}).forEach(function (key) { | ||
var promiseId = 0; | ||
@@ -74,3 +82,7 @@ _this2.$watch(prefix + key, function (newPromise) { | ||
handler(err.stack); | ||
if (options.useRawError) { | ||
handler(err); | ||
} else { | ||
handler(err.stack); | ||
} | ||
}); | ||
@@ -77,0 +89,0 @@ }, { immediate: true }); |
{ | ||
"name": "vue-async-computed", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"description": "Async computed properties for Vue", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -203,2 +203,24 @@ <big><h1 align="center">vue-async-computed</h1></big> | ||
You can instead define the default value as a function, in order to depend on | ||
props or on data: | ||
````js | ||
new Vue({ | ||
data: { | ||
postId: 1 | ||
}, | ||
asyncComputed: { | ||
blogPostContent: { | ||
get () { | ||
return Vue.http.get('/post/' + this.postId) | ||
.then(response => response.data.postContent) | ||
}, | ||
default () { | ||
return 'Loading post ' + this.postId | ||
} | ||
} | ||
} | ||
} | ||
```` | ||
## Options | ||
@@ -208,3 +230,4 @@ | ||
If you want to use a custom logging function, the plugin takes an `errorHandler` option, which should be the function you want called with the error information. | ||
If you want to use a custom logging function, the plugin takes an `errorHandler` option, which should be the function you want called with the error information. By default, it will be called with the error's stack trace as an argument, but if you want the raw error itself you can set the | ||
`useRawError` option to `true`. | ||
@@ -215,11 +238,22 @@ For example: | ||
Vue.use(AsyncComputed, { | ||
errorHandler (msg) { | ||
errorHandler (stack) { | ||
console.log('Hey, an error!') | ||
console.log('---') | ||
console.log(msg) | ||
console.log(stack) | ||
} | ||
) | ||
// Or with `useRawError`: | ||
Vue.use(AsyncComputed, { | ||
useRawError: true, | ||
errorHandler (err) { | ||
console.log('An error occurred!') | ||
console.log('The error message was: ' + err.msg) | ||
console.log('And the stack trace was:') | ||
console.log(err.stack) | ||
} | ||
) | ||
```` | ||
You can pass `false` in order to silently ignore rejected promises. | ||
You can pass `false` as the `errorHandler` in order to silently ignore rejected promises. | ||
@@ -226,0 +260,0 @@ ## License |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15670
80
274