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
43 lines (37 loc) · 986 Bytes
/
cache.js
File metadata and controls
43 lines (37 loc) · 986 Bytes
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
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 getPropCacheMixin (propName, proxyPropName) {
return {
data () {
return { [proxyPropName]: {} }
},
watch: {
[propName]: {
immediate: true,
handler (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])
}
}
}
}
}
}
}