-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-observant.js
149 lines (139 loc) · 4.38 KB
/
be-observant.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// @ts-check
import { BE } from 'be-enhanced/BE.js';
import { propInfo, resolved, rejected } from 'be-enhanced/cc.js';
import { dispatchEvent as de } from 'trans-render/positractions/dispatchEvent.js';
/** @import {BEConfig, IEnhancement, BEAllProps} from './ts-refs/be-enhanced/types.d.ts' */
/** @import {Actions, PAP, AP, BAP, ObservingParameters} from './ts-refs/be-observant/types' */
/** @import {Specifier} from './ts-refs/trans-render/dss/types' */
/** @import {AbsorbingObject} from './ts-refs/trans-render/asmr/types.d.ts' */
/**
* @implements {Actions}
*
*/
class BeObservant extends BE {
de = de;
/**
* @type {BEConfig<BAP, Actions & IEnhancement, any>}
*/
static config = {
propDefaults: {
didInferring: false,
},
propInfo: {
...propInfo,
parsedStatements: {},
customHandlers: {},
ws: {},
},
actions: {
noAttrs: {
ifNoneOf: ['parsedStatements']
},
seek: {
ifAllOf: ['didInferring', 'parsedStatements']
},
infer: {
ifAllOf: ['parsedStatements'],
ifNoneOf: ['didInferring']
}
},
positractions: [
resolved, rejected,
{
do: 'warn',
ifAllOf: ['rawStatements'],
pass: ['`The following statements could not be parsed.`', 'rawStatements']
}
]
}
warn = console.warn;
/**
*
* @param {BAP} self
*/
async infer(self){
const {parsedStatements, enhancedElement} = self;
//do any pre processing here, if applicable
//if no scenario presents itself, remove this linked action
return /** @type {PAP} */({
didInferring: true,
});
}
/**
*
* @param {BAP} self
*/
async noAttrs(self){
const {enhancedElement} = self;
const {stdProp} = await import('trans-render/asmr/stdProp.js');
/**
* @type {Specifier}
*/
const specifier = {
s: '/',
elS: '*',
dss: '^',
scopeS: '[itemscope]',
rec: true,
rnf: true,
prop: stdProp(enhancedElement),
host: true
}
/**
* @type {ObservingParameters}
*/
const parsedStatement = {
remoteSpecifiers: [specifier],
aggKey: '&&'
};
return /** @type {PAP} */({
didInferring: true,
parsedStatements: [parsedStatement]
});
}
/**
*
* @param {BAP} self
*/
async seek(self){
const {parsedStatements, enhancedElement} = self;
const {find} = await import('trans-render/dss/find.js');
const {ASMR} = await import('trans-render/asmr/asmr.js');
const {ASMRHandler} = await import('./ASMRHandler.js');
const {customHandlers} = self;
for(const statement of parsedStatements){
/**
* @type {{[key: string]: AbsorbingObject}}
*/
const propToAO = {};
const {remoteSpecifiers, localPropToSet, aggKey} = statement;
for(const remoteSpecifier of remoteSpecifiers){
const remoteEl = await find(enhancedElement, remoteSpecifier);
if(!(remoteEl instanceof Element)) throw 404;
const {prop} = remoteSpecifier;
if(prop === undefined) throw 'NI';
let remoteProp;
const {s} = remoteSpecifier;
switch(s){
case '/':
case '-':
remoteProp = prop;
break;
}
const ao = await ASMR.getAO(remoteEl, {
evt: remoteSpecifier.evt || 'input',
selfIsVal: remoteSpecifier.path === '$0',
propToAbsorb: remoteProp,
});
propToAO[prop] = ao;
}
const so = await ASMR.getSO(enhancedElement, {valueProp: localPropToSet});
//TODO: store asmrh for cleanup purposes
const asmrh = new ASMRHandler(self, aggKey, so, propToAO);
}
return /** @type {PAP} */({
});
}
}
await BeObservant.bootUp();
export {BeObservant}