-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxytest.js
41 lines (33 loc) · 859 Bytes
/
proxytest.js
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
/**
* The Object Proxy is a proxy for the data object in a collection.
*/
class ObjectProxy extends Proxy {
constructor(original, persistenceAdapter) {
this.persistenceAdapter = persistenceAdapter;
this.dataContainer = {};
super(original, {
get: (target, name, receiver) => {
return this.dataContainer[name] ? this.dataContainer[name] : this.persistenceAdapter.getObject(name);
},
set: (target, name, value) => {
this.dataContainer[name] = value.toUpperCase();
}
});
}
get length(){
return this.persistenceAdapter.getObjectCount();
}
}
class PersistenceAdapter {
static getObjectCount(){
return 5;
}
static getObject(identifier){
return "blubb" + identifier;
}
}
let pa = new PersistenceAdapter();
let op = new ObjectProxy({}, pa);
console.log(op['test']);
op['test'] = "neuerTest";
console.log(op['test']);