chore(xo-server/decorateWith): use fn wrappers as method decorator
This commit is contained in:
parent
b50e3aec5f
commit
317a020841
14
packages/xo-server/src/_decorateWith.js
Normal file
14
packages/xo-server/src/_decorateWith.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Creates a decorator from a function wrapper.
|
||||
//
|
||||
// For instance, allows using Lodash's functions as decorators:
|
||||
//
|
||||
// ```js
|
||||
// @decorateWith(lodash.debounce, 150)
|
||||
// myMethod() {
|
||||
// // body
|
||||
// }
|
||||
// ```
|
||||
export const decorateWith = (fn, ...args) => (target, name, descriptor) => ({
|
||||
...descriptor,
|
||||
value: fn(descriptor.value, ...args),
|
||||
})
|
@ -52,8 +52,3 @@ export const debounceWithKey = (fn, delay, keyFn = defaultKeyFn) => {
|
||||
return promise
|
||||
}
|
||||
}
|
||||
|
||||
debounceWithKey.decorate = (...params) => (target, name, descriptor) => ({
|
||||
...descriptor,
|
||||
value: debounceWithKey(descriptor.value, ...params),
|
||||
})
|
||||
|
@ -5,6 +5,7 @@ import { filter, find, pickBy, some } from 'lodash'
|
||||
|
||||
import ensureArray from '../../_ensureArray'
|
||||
import { debounceWithKey } from '../../_pDebounceWithKey'
|
||||
import { decorateWith } from '../../_decorateWith'
|
||||
import { forEach, mapFilter, mapToArray, parseXml } from '../../utils'
|
||||
|
||||
import { extractOpaqueRef, useUpdateSystem } from '../utils'
|
||||
@ -55,7 +56,7 @@ const listMissingPatches = debounceWithKey(
|
||||
export default {
|
||||
// raw { uuid: patch } map translated from updates.xensource.com/XenServer/updates.xml
|
||||
// FIXME: should be static
|
||||
@debounceWithKey.decorate(24 * 60 * 60 * 1000, function() {
|
||||
@decorateWith(debounceWithKey, 24 * 60 * 60 * 1000, function() {
|
||||
return this
|
||||
})
|
||||
async _getXenUpdates() {
|
||||
|
Loading…
Reference in New Issue
Block a user