vue-async-computed
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -5,2 +5,3 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
- [v3.1.0](#v310) | ||
- [v3.0.1](#v301) | ||
@@ -18,2 +19,9 @@ - [v3.0.0](#v300) | ||
### v3.1.0 | ||
* Add option for setting a global default value | ||
* Improve test coverage | ||
* Async computed properties that return a non-promise value no longer cause | ||
an error to be thrown. Instead that value is automaticly promoted to a | ||
promise with `Promise.resolve`. | ||
### v3.0.1 | ||
@@ -20,0 +28,0 @@ * More test cases |
@@ -22,4 +22,4 @@ (function (global, factory) { | ||
var AsyncComputed = { | ||
install: function install(Vue, options) { | ||
options = options || {}; | ||
install: function install(Vue, pluginOptions) { | ||
pluginOptions = pluginOptions || {}; | ||
@@ -37,6 +37,3 @@ Vue.config.optionMergeStrategies.asyncComputed = Vue.config.optionMergeStrategies.computed; | ||
Object.keys(this.$options.asyncComputed || {}).forEach(function (key) { | ||
var fn = _this.$options.asyncComputed[key], | ||
get = typeof fn === 'function' ? fn : fn.get; | ||
_this.$options.computed[prefix + key] = get; | ||
_this.$options.computed[prefix + key] = getterFor(_this.$options.asyncComputed[key]); | ||
}); | ||
@@ -56,10 +53,3 @@ | ||
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; | ||
} | ||
_this2[key] = defaultFor.call(_this2, _this2.$options.asyncComputed[key], pluginOptions); | ||
}); | ||
@@ -71,2 +61,7 @@ | ||
var thisPromise = ++promiseId; | ||
if (!newPromise || !newPromise.then) { | ||
newPromise = Promise.resolve(newPromise); | ||
} | ||
newPromise.then(function (value) { | ||
@@ -78,7 +73,7 @@ if (thisPromise !== promiseId) return; | ||
if (options.errorHandler === false) return; | ||
if (pluginOptions.errorHandler === false) return; | ||
var handler = options.errorHandler === undefined ? console.error.bind(console, 'Error evaluating async computed property:') : options.errorHandler; | ||
var handler = pluginOptions.errorHandler === undefined ? console.error.bind(console, 'Error evaluating async computed property:') : pluginOptions.errorHandler; | ||
if (options.useRawError) { | ||
if (pluginOptions.useRawError) { | ||
handler(err); | ||
@@ -96,7 +91,38 @@ } else { | ||
function getterFor(fn) { | ||
if (typeof fn === 'function') return fn; | ||
var getter = fn.get; | ||
if (fn.watch) { | ||
getter = function getter() { | ||
fn.watch.call(this); | ||
return fn.get(this); | ||
}; | ||
} | ||
return getter; | ||
} | ||
function defaultFor(fn, pluginOptions) { | ||
var defaultValue = null; | ||
if ('default' in fn) { | ||
defaultValue = fn.default; | ||
} else if ('default' in pluginOptions) { | ||
defaultValue = pluginOptions.default; | ||
} | ||
if (typeof defaultValue === 'function') { | ||
return defaultValue.call(this); | ||
} else { | ||
return defaultValue; | ||
} | ||
} | ||
exports.default = AsyncComputed; | ||
// Auto install in dist mode | ||
/* istanbul ignore if */ | ||
if (typeof window !== 'undefined' && window.Vue) { | ||
// Auto install in dist mode | ||
window.Vue.use(AsyncComputed); | ||
@@ -103,0 +129,0 @@ } |
{ | ||
"name": "vue-async-computed", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"description": "Async computed properties for Vue", | ||
@@ -50,24 +50,24 @@ "main": "dist/index.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.23.0", | ||
"babel-core": "^6.23.1", | ||
"babel-eslint": "^7.0.0", | ||
"babel-istanbul": "^0.12.1", | ||
"babel-cli": "^6.24.1", | ||
"babel-core": "^6.24.1", | ||
"babel-eslint": "^7.2.3", | ||
"babel-istanbul": "^0.12.2", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-plugin-rename-umd-globals": "^1.0.0", | ||
"babel-plugin-transform-es2015-modules-umd": "^6.23.0", | ||
"babel-preset-es2015": "^6.6.0", | ||
"coveralls": "^2.11.16", | ||
"babel-plugin-transform-es2015-modules-umd": "^6.24.1", | ||
"babel-preset-es2015": "^6.24.1", | ||
"coveralls": "^2.13.1", | ||
"dependency-check": "^2.8.0", | ||
"doctoc": "^1.0.0", | ||
"eslint": "^3.15.0", | ||
"doctoc": "^1.3.0", | ||
"eslint": "^3.19.0", | ||
"eslint-config-standard": "^6.0.0", | ||
"eslint-plugin-promise": "^3.4.2", | ||
"eslint-plugin-standard": "^2.0.0", | ||
"eslint-plugin-promise": "^3.5.0", | ||
"eslint-plugin-standard": "^2.3.1", | ||
"estraverse-fb": "^1.3.1", | ||
"rimraf": "^2.6.0", | ||
"rimraf": "^2.6.1", | ||
"tap-spec": "^4.1.1", | ||
"tape": "^4.5.1", | ||
"vue": "^2.1.10", | ||
"vue": "^2.3.2", | ||
"watch": "^1.0.2" | ||
} | ||
} |
@@ -35,4 +35,6 @@ <big><h1 align="center">vue-async-computed</h1></big> | ||
With this plugin, you can have have computed properties in Vue that are computed asynchronously. | ||
**This plugin is now Vue 2.0 compatible!** | ||
With this plugin, you can have computed properties in Vue that are computed asynchronously. | ||
Without using this plugin, you can't do this: | ||
@@ -104,3 +106,3 @@ | ||
--> | ||
<script src="https://unpkg.com/vue-async-computed@2.2.1"></script> | ||
<script src="https://unpkg.com/vue-async-computed@3.1.0"></script> | ||
```` | ||
@@ -225,4 +227,12 @@ | ||
## Options | ||
You can also set a custom global default value in the options passed to `Vue.use`: | ||
````javascript | ||
Vue.use(AsyncComputed, { | ||
default: 'Global default value' | ||
}) | ||
```` | ||
## Error handling | ||
By default, in case of a rejected promise in an async computed property, vue-async-computed will take care of logging the error for you. | ||
@@ -229,0 +239,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
16764
100
282