vue-async-methods
Advanced tools
Comparing version 0.5.0 to 0.6.0
29
index.js
@@ -65,6 +65,6 @@ 'use strict' | ||
if (isFunction(options.onError)) { | ||
options.onError(err, vm, funcName, args) | ||
} else { | ||
throw err | ||
options.onError(err, vm[funcName].handleErrorInView, vm, funcName, args) | ||
} | ||
throw err | ||
}) | ||
@@ -93,6 +93,6 @@ | ||
if (isFunction(options.onError)) { | ||
options.onError(err, vm, funcName, args) | ||
} else { | ||
reject(err) | ||
options.onError(err, vm[funcName].handleErrorInView, vm, funcName, args) | ||
} | ||
reject(err) | ||
}) | ||
@@ -108,3 +108,8 @@ | ||
Vue.component('catch-async-error', { | ||
props: ['promise'], | ||
props: { | ||
method: { | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
render: function(h) { | ||
@@ -129,3 +134,3 @@ if (!this.error || !this.$slots || !this.$slots.default) return null | ||
created() { | ||
if (this.promise) { | ||
if (this.method.promise) { | ||
this.catchError() | ||
@@ -135,3 +140,3 @@ } | ||
watch: { | ||
promise: 'catchError' | ||
'method.promise': 'catchError' | ||
}, | ||
@@ -142,5 +147,4 @@ methods: { | ||
this.promise.catch((err) => { | ||
this.method.promise.catch((err) => { | ||
this.error = err | ||
this.showError = true | ||
}) | ||
@@ -164,3 +168,4 @@ } | ||
resolvedWithEmpty: false, | ||
rejectedWith: null | ||
rejectedWith: null, | ||
handleErrorInView: false | ||
}) | ||
@@ -167,0 +172,0 @@ |
{ | ||
"name": "vue-async-methods", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "Vue async methods support", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -25,3 +25,3 @@ # vue-async-methods [![Build Status](https://travis-ci.org/mokkabonna/vue-async-methods.svg?branch=master)](https://travis-ci.org/mokkabonna/vue-async-methods) | ||
#### getComputedName | ||
#### getComputedName(vm, methodName) | ||
@@ -32,4 +32,4 @@ A function that should return the name of the desired computed if createComputed is `true` | ||
// turns "fetchArticles", "getArticle" or "loadArticle" into "article" computed | ||
function (vm, funcName) { | ||
var withoutPrefix = funcName.replace(/^(fetch|get|load)/, '') | ||
function (vm, methodName) { | ||
var withoutPrefix = methodName.replace(/^(fetch|get|load)/, '') | ||
return withoutPrefix.slice(0, 1).toLowerCase() + withoutPrefix.slice(1) | ||
@@ -39,2 +39,7 @@ } | ||
#### onError(err, handledInView, vm, methodName, args) | ||
All error raised by the methods will be passed to the onError handler, enabling you to implement | ||
global error handling, logging, etc. | ||
Now you can define async methods on your vm: | ||
@@ -68,3 +73,5 @@ | ||
It also registers a component called `catch-async-error` that enables you to catch errors in the view instead of in the code. | ||
```html | ||
@@ -88,7 +95,7 @@ <button type="button" @click="fetchArticles.execute">Load data</button> | ||
<div v-if="fetchArticles.isRejected"> | ||
<catch-async-error :method="fetchArticles"> | ||
<div v-if="fetchArticles.rejectedWith"> | ||
Could not load data due to an error. Details: {{fetchData.rejectedWith.message}} | ||
</div> | ||
</div> | ||
</catch-async-error> | ||
``` | ||
@@ -95,0 +102,0 @@ |
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
10029
156
101