forked from nullstack/nullstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.js
More file actions
28 lines (23 loc) · 738 Bytes
/
context.js
File metadata and controls
28 lines (23 loc) · 738 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
import client from './client';
import deserialize from '../shared/deserialize';
import {generateObjectProxy} from './objectProxyHandler';
const context = {};
const memory = deserialize(JSON.stringify(window.context));
for(const key of Object.keys(memory)) {
context[key] = generateObjectProxy(key, memory[key]);
}
const contextProxyHandler = {
set(target, name, value) {
context[name] = generateObjectProxy(name, value);
client.update();
return true;
},
get(target, name) {
if(name === '_isProxy') return true;
return target[name] === undefined ? context[name] : target[name];
}
}
export function generateContext(temporary) {
return new Proxy(temporary, contextProxyHandler);
}
export default context;