-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-scoped.js
83 lines (83 loc) · 2.48 KB
/
be-scoped.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { config as beCnfg } from 'be-enhanced/config.js';
import { BE } from 'be-enhanced/BE.js';
import { PropertyBag } from 'trans-render/lib/PropertyBag.js';
class BeScoped extends BE {
static config = {
propDefaults: {
attached: true,
},
propInfo: {
...beCnfg.propInfo,
assign: {},
scope: {},
},
actions: {
hydrate: {
ifAllOf: ['attached']
},
onAssign: {
ifAllOf: ['assign', 'resolved']
}
}
};
async hydrate(self) {
const { assign, enhancedElement } = self;
if (assign instanceof Object) {
delete assign.scope;
}
//const {CtxNav} = await import('trans-render/lib/CtxNav.js');
//const nav = new CtxNav(enhancedElement);
const pg = new PropertyBag();
const scope = pg.proxy;
//const scope = nav.beScoped;
if (assign instanceof Object) {
this.#skipInitAssign = true;
Object.assign(scope, assign);
}
return {
scope,
//nav,
resolved: true,
};
}
#skipInitAssign = false;
onAssign(self) {
if (this.#skipInitAssign) {
this.#skipInitAssign = false;
return;
}
const { assign, scope } = self;
Object.assign(scope, assign);
}
#previousTS = new Map();
setKeyVal(key, val, tsKey = 'timestamp') {
switch (typeof val) {
case 'object':
if (Array.isArray(val)) {
throw 'NI';
}
const ts = val[tsKey];
if (ts !== undefined) {
if (this.#previousTS.has(key) && this.#previousTS.get(key) === ts)
return;
this.#previousTS.set(key, ts);
}
if (!val._isPropagating) {
//const {PropertyBag} = await import('trans-render/lib/PropertyBag.js');
const pg = new PropertyBag();
const proxy = pg.proxy;
Object.assign(proxy, val);
this.scope[key] = val;
}
else {
Object.assign(this.scope[key], val);
}
break;
default: {
this.scope[key] = val;
}
}
}
}
await BeScoped.bootUp();
export { BeScoped };