vue-async-computed
Advanced tools
Comparing version 3.5.1 to 3.5.2
@@ -5,2 +5,3 @@ <!-- START doctoc generated TOC please keep comment here to allow auto update --> | ||
- [v3.5.2](#v352) | ||
- [v3.5.1](#v351) | ||
@@ -27,2 +28,5 @@ - [v3.5.0](#v350) | ||
### v3.5.2 | ||
* Point to a pre-transpiled version of the library as the `module` field in package.json. | ||
### v3.5.1 | ||
@@ -29,0 +33,0 @@ * [#54](https://github.com/foxbenjaminfox/vue-async-computed/pull/54): Fix the missing execution context during recomputations triggered through the `.update` method in `$asyncComputed`. |
@@ -1,13 +0,13 @@ | ||
function isComputedLazy (item) { | ||
return item.hasOwnProperty('lazy') && item.lazy | ||
function isComputedLazy(item) { | ||
return item.hasOwnProperty('lazy') && item.lazy; | ||
} | ||
function isLazyActive (vm, key) { | ||
return vm[lazyActivePrefix + key] | ||
function isLazyActive(vm, key) { | ||
return vm[lazyActivePrefix + key]; | ||
} | ||
const lazyActivePrefix = 'async_computed$lazy_active$', | ||
lazyDataPrefix = 'async_computed$lazy_data$'; | ||
var lazyActivePrefix = 'async_computed$lazy_active$', | ||
lazyDataPrefix = 'async_computed$lazy_data$'; | ||
function initLazy (data, key) { | ||
function initLazy(data, key) { | ||
data[lazyActivePrefix + key] = false; | ||
@@ -17,75 +17,75 @@ data[lazyDataPrefix + key] = null; | ||
function makeLazyComputed (key) { | ||
function makeLazyComputed(key) { | ||
return { | ||
get () { | ||
get: function get() { | ||
this[lazyActivePrefix + key] = true; | ||
return this[lazyDataPrefix + key] | ||
return this[lazyDataPrefix + key]; | ||
}, | ||
set (value) { | ||
set: function set(value) { | ||
this[lazyDataPrefix + key] = value; | ||
} | ||
} | ||
}; | ||
} | ||
function silentSetLazy (vm, key, value) { | ||
function silentSetLazy(vm, key, value) { | ||
vm[lazyDataPrefix + key] = value; | ||
} | ||
function silentGetLazy (vm, key) { | ||
return vm[lazyDataPrefix + key] | ||
function silentGetLazy(vm, key) { | ||
return vm[lazyDataPrefix + key]; | ||
} | ||
const prefix = '_async_computed$'; | ||
const DidNotUpdate = typeof Symbol === 'function' ? Symbol('did-not-update') : {}; | ||
var prefix = '_async_computed$'; | ||
var DidNotUpdate = typeof Symbol === 'function' ? Symbol('did-not-update') : {}; | ||
const AsyncComputed = { | ||
install (Vue, pluginOptions) { | ||
var AsyncComputed = { | ||
install: function install(Vue, pluginOptions) { | ||
pluginOptions = pluginOptions || {}; | ||
Vue.config | ||
.optionMergeStrategies | ||
.asyncComputed = Vue.config.optionMergeStrategies.computed; | ||
Vue.config.optionMergeStrategies.asyncComputed = Vue.config.optionMergeStrategies.computed; | ||
Vue.mixin({ | ||
data () { | ||
data: function data() { | ||
return { | ||
_asyncComputed: {}, | ||
} | ||
_asyncComputed: {} | ||
}; | ||
}, | ||
beforeCreate () { | ||
const optionData = this.$options.data; | ||
const asyncComputed = this.$options.asyncComputed || {}; | ||
beforeCreate: function beforeCreate() { | ||
var _this = this; | ||
var optionData = this.$options.data; | ||
var asyncComputed = this.$options.asyncComputed || {}; | ||
if (!this.$options.computed) this.$options.computed = {}; | ||
this.$options.computed.$asyncComputed = () => this.$data._asyncComputed; | ||
this.$options.computed.$asyncComputed = function () { | ||
return _this.$data._asyncComputed; | ||
}; | ||
if (!Object.keys(asyncComputed).length) return | ||
if (!Object.keys(asyncComputed).length) return; | ||
for (const key in asyncComputed) { | ||
const getter = getterFn(key, this.$options.asyncComputed[key]); | ||
for (var key in asyncComputed) { | ||
var getter = getterFn(key, this.$options.asyncComputed[key]); | ||
this.$options.computed[prefix + key] = getter; | ||
} | ||
this.$options.data = function vueAsyncComputedInjectedDataFn () { | ||
const data = ( | ||
(typeof optionData === 'function') | ||
? optionData.call(this) | ||
: optionData | ||
) || {}; | ||
for (const key in asyncComputed) { | ||
const item = this.$options.asyncComputed[key]; | ||
this.$options.data = function vueAsyncComputedInjectedDataFn() { | ||
var data = (typeof optionData === 'function' ? optionData.call(this) : optionData) || {}; | ||
for (var _key in asyncComputed) { | ||
var item = this.$options.asyncComputed[_key]; | ||
if (isComputedLazy(item)) { | ||
initLazy(data, key); | ||
this.$options.computed[key] = makeLazyComputed(key); | ||
initLazy(data, _key); | ||
this.$options.computed[_key] = makeLazyComputed(_key); | ||
} else { | ||
data[key] = null; | ||
data[_key] = null; | ||
} | ||
} | ||
return data | ||
return data; | ||
}; | ||
}, | ||
created () { | ||
for (const key in this.$options.asyncComputed || {}) { | ||
const item = this.$options.asyncComputed[key], | ||
value = generateDefault.call(this, item, pluginOptions); | ||
created: function created() { | ||
var _this2 = this; | ||
for (var key in this.$options.asyncComputed || {}) { | ||
var item = this.$options.asyncComputed[key], | ||
value = generateDefault.call(this, item, pluginOptions); | ||
if (isComputedLazy(item)) { | ||
@@ -98,9 +98,9 @@ silentSetLazy(this, key, value); | ||
for (const key in this.$options.asyncComputed || {}) { | ||
let promiseId = 0; | ||
const watcher = newPromise => { | ||
const thisPromise = ++promiseId; | ||
var _loop = function _loop(_key2) { | ||
var promiseId = 0; | ||
var watcher = function watcher(newPromise) { | ||
var thisPromise = ++promiseId; | ||
if (newPromise === DidNotUpdate) { | ||
return | ||
return; | ||
} | ||
@@ -111,18 +111,16 @@ | ||
} | ||
setAsyncState(this, key, 'updating'); | ||
setAsyncState(_this2, _key2, 'updating'); | ||
newPromise.then(value => { | ||
if (thisPromise !== promiseId) return | ||
setAsyncState(this, key, 'success'); | ||
this[key] = value; | ||
}).catch(err => { | ||
if (thisPromise !== promiseId) return | ||
newPromise.then(function (value) { | ||
if (thisPromise !== promiseId) return; | ||
setAsyncState(_this2, _key2, 'success'); | ||
_this2[_key2] = value; | ||
}).catch(function (err) { | ||
if (thisPromise !== promiseId) return; | ||
setAsyncState(this, key, 'error'); | ||
Vue.set(this.$data._asyncComputed[key], 'exception', err); | ||
if (pluginOptions.errorHandler === false) return | ||
setAsyncState(_this2, _key2, 'error'); | ||
Vue.set(_this2.$data._asyncComputed[_key2], 'exception', err); | ||
if (pluginOptions.errorHandler === false) return; | ||
const handler = (pluginOptions.errorHandler === undefined) | ||
? console.error.bind(console, 'Error evaluating async computed property:') | ||
: pluginOptions.errorHandler; | ||
var handler = pluginOptions.errorHandler === undefined ? console.error.bind(console, 'Error evaluating async computed property:') : pluginOptions.errorHandler; | ||
@@ -136,10 +134,14 @@ if (pluginOptions.useRawError) { | ||
}; | ||
Vue.set(this.$data._asyncComputed, key, { | ||
Vue.set(_this2.$data._asyncComputed, _key2, { | ||
exception: null, | ||
update: () => { | ||
watcher(getterOnly(this.$options.asyncComputed[key]).apply(this)); | ||
update: function update() { | ||
watcher(getterOnly(_this2.$options.asyncComputed[_key2]).apply(_this2)); | ||
} | ||
}); | ||
setAsyncState(this, key, 'updating'); | ||
this.$watch(prefix + key, watcher, { immediate: true }); | ||
setAsyncState(_this2, _key2, 'updating'); | ||
_this2.$watch(prefix + _key2, watcher, { immediate: true }); | ||
}; | ||
for (var _key2 in this.$options.asyncComputed || {}) { | ||
_loop(_key2); | ||
} | ||
@@ -151,3 +153,3 @@ } | ||
function setAsyncState (vm, stateObject, state) { | ||
function setAsyncState(vm, stateObject, state) { | ||
vm.$set(vm.$data._asyncComputed[stateObject], 'state', state); | ||
@@ -159,18 +161,18 @@ vm.$set(vm.$data._asyncComputed[stateObject], 'updating', state === 'updating'); | ||
function getterOnly (fn) { | ||
if (typeof fn === 'function') return fn | ||
function getterOnly(fn) { | ||
if (typeof fn === 'function') return fn; | ||
return fn.get | ||
return fn.get; | ||
} | ||
function getterFn (key, fn) { | ||
if (typeof fn === 'function') return fn | ||
function getterFn(key, fn) { | ||
if (typeof fn === 'function') return fn; | ||
let getter = fn.get; | ||
var getter = fn.get; | ||
if (fn.hasOwnProperty('watch')) { | ||
const previousGetter = getter; | ||
getter = function getter () { | ||
var previousGetter = getter; | ||
getter = function getter() { | ||
fn.watch.call(this); | ||
return previousGetter.call(this) | ||
return previousGetter.call(this); | ||
}; | ||
@@ -180,8 +182,8 @@ } | ||
if (fn.hasOwnProperty('shouldUpdate')) { | ||
const previousGetter = getter; | ||
getter = function getter () { | ||
var _previousGetter = getter; | ||
getter = function getter() { | ||
if (fn.shouldUpdate.call(this)) { | ||
return previousGetter.call(this) | ||
return _previousGetter.call(this); | ||
} | ||
return DidNotUpdate | ||
return DidNotUpdate; | ||
}; | ||
@@ -191,16 +193,16 @@ } | ||
if (isComputedLazy(fn)) { | ||
const nonLazy = getter; | ||
getter = function lazyGetter () { | ||
var nonLazy = getter; | ||
getter = function lazyGetter() { | ||
if (isLazyActive(this, key)) { | ||
return nonLazy.call(this) | ||
return nonLazy.call(this); | ||
} else { | ||
return silentGetLazy(this, key) | ||
return silentGetLazy(this, key); | ||
} | ||
}; | ||
} | ||
return getter | ||
return getter; | ||
} | ||
function generateDefault (fn, pluginOptions) { | ||
let defaultValue = null; | ||
function generateDefault(fn, pluginOptions) { | ||
var defaultValue = null; | ||
@@ -214,5 +216,5 @@ if ('default' in fn) { | ||
if (typeof defaultValue === 'function') { | ||
return defaultValue.call(this) | ||
return defaultValue.call(this); | ||
} else { | ||
return defaultValue | ||
return defaultValue; | ||
} | ||
@@ -219,0 +221,0 @@ } |
{ | ||
"name": "vue-async-computed", | ||
"version": "3.5.1", | ||
"version": "3.5.2", | ||
"description": "Async computed properties for Vue", | ||
@@ -18,6 +18,9 @@ "main": "dist/vue-async-computed.js", | ||
"prebuild": "npm run check -s && npm run clean -s && mkdirp dist", | ||
"build": "npm run rollup-esm -s && npm run rollup-umd -s && npm run babel -s", | ||
"rollup-esm": "rollup src/index.js --output.format esm --name AsyncComputed --output.file dist/vue-async-computed.esm.js", | ||
"build": "npm run rollup -s && npm run babel -s", | ||
"rollup-esm": "rollup src/index.js --output.format esm --name AsyncComputed --output.file dist/vue-async-computed.esm.esnext.js", | ||
"rollup-umd": "rollup src/index.js --output.format umd --name AsyncComputed --output.file dist/vue-async-computed.esnext.js", | ||
"babel": "babel --optional runtime dist/vue-async-computed.esnext.js --out-file dist/vue-async-computed.js", | ||
"rollup": "npm run rollup-umd -s && npm run rollup-esm -s", | ||
"babel-umd": "babel --optional runtime dist/vue-async-computed.esnext.js --out-file dist/vue-async-computed.js", | ||
"babel-esm": "babel --optional runtime dist/vue-async-computed.esm.esnext.js --out-file dist/vue-async-computed.esm.js", | ||
"babel": "npm run babel-umd -s && npm run babel-esm -s", | ||
"postbuild": "npm run test -s", | ||
@@ -24,0 +27,0 @@ "coverage": "node_modules/.bin/babel-node node_modules/.bin/babel-istanbul cover test/index.js", |
@@ -105,3 +105,3 @@ <big><h1 align="center">vue-async-computed</h1></big> | ||
--> | ||
<script src="https://unpkg.com/vue-async-computed@3.5.1"></script> | ||
<script src="https://unpkg.com/vue-async-computed@3.5.2"></script> | ||
``` | ||
@@ -108,0 +108,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
46565
8
746