-
Notifications
You must be signed in to change notification settings - Fork 0
/
be-scoped.ts
92 lines (85 loc) · 2.82 KB
/
be-scoped.ts
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
84
85
86
87
88
89
90
91
92
import {config as beCnfg} from 'be-enhanced/config.js';
import {BE, BEConfig} from 'be-enhanced/BE.js';
import {Actions, AllProps, AP, PAP, ProPAP} from './types';
import { Positractions, PropInfo } from 'trans-render/froop/types';
import {IEnhancement, BEAllProps} from 'trans-render/be/types';
import {PropertyBag} from 'trans-render/lib/PropertyBag.js';
class BeScoped extends BE implements Actions{
static override config: BEConfig<AllProps & BEAllProps, Actions & IEnhancement, any> = {
propDefaults:{
attached: true,
},
propInfo:{
...beCnfg.propInfo,
assign:{},
scope: {},
},
actions:{
hydrate:{
ifAllOf: ['attached']
},
onAssign: {
ifAllOf: ['assign', 'resolved']
}
}
};
async hydrate(self: this): ProPAP {
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,
} as PAP;
}
#skipInitAssign = false;
onAssign(self: this){
if(this.#skipInitAssign){
this.#skipInitAssign = false;
return;
}
const {assign, scope} = self;
Object.assign(scope, assign);
}
#previousTS = new Map<string, string | number>();
setKeyVal(key: string, val: any, 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);
(<any>this.scope)[key] = val;
}else{
Object.assign((<any>this.scope)[key], val);
}
break;
default:{
(<any>this.scope)[key] = val;
}
}
}
}
await BeScoped.bootUp();
interface BeScoped extends AP{}
export {BeScoped}