forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.js
More file actions
56 lines (46 loc) · 1.19 KB
/
cache.js
File metadata and controls
56 lines (46 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { isSSR } from '../plugins/Platform.js'
export default function cache (vm, key, obj) {
if (isSSR === true) return obj
const k = `__qcache_${key}`
return vm[k] === void 0
? (vm[k] = obj)
: vm[k]
}
export function cacheWithFn (vm, key, fn) {
if (isSSR === true) return fn()
const k = `__qcache_${key}`
return vm[k] === void 0
? (vm[k] = fn())
: vm[k]
}
export function getPropCacheMixin (propName, proxyPropName) {
return {
data () {
const target = {}
const source = this[propName]
for (const prop in source) {
target[prop] = source[prop]
}
return { [proxyPropName]: target }
},
watch: {
[propName] (newObj, oldObj) {
const target = this[proxyPropName]
if (oldObj !== void 0) {
// we first delete obsolete events
for (const prop in oldObj) {
if (newObj[prop] === void 0) {
this.$delete(target, prop)
}
}
}
for (const prop in newObj) {
// we then update changed events
if (target[prop] !== newObj[prop]) {
this.$set(target, prop, newObj[prop])
}
}
}
}
}
}