vue-async-methods
Advanced tools
Comparing version 0.7.3 to 0.7.4
42
index.js
@@ -9,2 +9,24 @@ 'use strict' | ||
function isEmpty(val) { | ||
if (Array.isArray(val)) { | ||
return val.length === 0 | ||
} else if (typeof val === 'object' && val !== null) { | ||
return Object.keys(val).length === 0 | ||
} else if (val === null) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
function isFunction(func) { | ||
return typeof func === 'function' | ||
} | ||
function createComputed(self, key) { | ||
return function() { | ||
return self[key].resolvedWith | ||
} | ||
} | ||
module.exports = { | ||
@@ -18,18 +40,2 @@ install: function(Vue, options) { | ||
function isEmpty(val) { | ||
if (Array.isArray(val)) { | ||
return val.length === 0 | ||
} else if (typeof val === 'object' && val !== null) { | ||
return Object.keys(val).length === 0 | ||
} else if (val === null) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
function isFunction(func) { | ||
return typeof func === 'function' | ||
} | ||
function wrapMethod(func, vm, funcName) { | ||
@@ -182,5 +188,3 @@ function wrapped() { | ||
this.$options.computed[computedName] = function() { | ||
return self[key].resolvedWith | ||
} | ||
this.$options.computed[computedName] = createComputed(self, key) | ||
} | ||
@@ -187,0 +191,0 @@ } |
{ | ||
"name": "vue-async-methods", | ||
"version": "0.7.3", | ||
"version": "0.7.4", | ||
"description": "Vue async methods support", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -5,2 +5,6 @@ # vue-async-methods [![Build Status](https://travis-ci.org/mokkabonna/vue-async-methods.svg?branch=master)](https://travis-ci.org/mokkabonna/vue-async-methods) | ||
Gives you utility methods for your promise based methods for use in the view. Also catch errors in the view. | ||
[Demo](https://jsfiddle.net/nyz4ahys/4/) | ||
## Install | ||
@@ -24,3 +28,3 @@ | ||
default `false`, if true: creates computeds that proxies fetchArticles.resolvedWith | ||
default `false`, if true: creates computeds that proxies `fetchArticles.resolvedWith` to `articles` | ||
@@ -30,5 +34,6 @@ #### getComputedName(vm, methodName) | ||
A function that should return the name of the desired computed if createComputed is `true` | ||
default | ||
default: | ||
```js | ||
// turns "fetchArticles", "getArticle" or "loadArticle" into "article" computed | ||
// turns "fetchArticles", "getArticles" or "loadArticles" into "articles" computed | ||
function (vm, methodName) { | ||
@@ -42,2 +47,4 @@ var withoutPrefix = methodName.replace(/^(fetch|get|load)/, '') | ||
default: `null` | ||
All error raised by the methods will be passed to the onError handler, enabling you to implement | ||
@@ -82,13 +89,10 @@ global error handling, logging, etc. | ||
<div v-if="fetchArticles.isResolved"> | ||
<div v-if="fetchArticles.resolvedWithSomething"> | ||
<ul> | ||
<li v-for="article in articles"> | ||
{{article.name}} | ||
</li> | ||
</ul> | ||
</div> | ||
<div v-if="fetchArticles.resolvedWithEmpty"> | ||
Empty list returned | ||
</div> | ||
<ul v-if="fetchArticles.resolvedWithSomething"> | ||
<li v-for="article in articles"> | ||
{{article.name}} | ||
</li> | ||
</ul> | ||
<div v-if="fetchArticles.resolvedWithEmpty"> | ||
There are no articles. | ||
</div> | ||
@@ -98,3 +102,3 @@ | ||
<div v-if="fetchArticles.rejectedWith"> | ||
Could not load data due to an error. Details: {{fetchData.rejectedWith.message}} | ||
Could not load articles due to an error. Details: {{fetchArticles.rejectedWith.message}} | ||
</div> | ||
@@ -104,4 +108,8 @@ </catch-async-error> | ||
## Contributing | ||
Create tests for new functionality and follow the eslint rules. | ||
## License | ||
MIT © [Martin Hansen](http://martinhansen.com) |
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
10329
162
109