mount-observer 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MountObserver.js +7 -2
- package/MountObserver.ts +7 -2
- package/README.md +28 -0
- package/package.json +1 -1
- package/tests/test6.html +1 -7
package/MountObserver.js
CHANGED
|
@@ -12,7 +12,12 @@ export class MountObserver extends EventTarget {
|
|
|
12
12
|
constructor(init) {
|
|
13
13
|
super();
|
|
14
14
|
const { match, whereElementIntersectsWith, whereMediaMatches } = init;
|
|
15
|
-
|
|
15
|
+
let isComplex = false;
|
|
16
|
+
if (match !== undefined) {
|
|
17
|
+
const reducedMatch = match.replaceAll(':not(', '');
|
|
18
|
+
isComplex = reducedMatch.includes(' ') || reducedMatch.includes(':');
|
|
19
|
+
}
|
|
20
|
+
this.#isComplex = isComplex;
|
|
16
21
|
if (whereElementIntersectsWith || whereMediaMatches)
|
|
17
22
|
throw 'NI'; //not implemented
|
|
18
23
|
this.#mountInit = init;
|
|
@@ -58,7 +63,7 @@ export class MountObserver extends EventTarget {
|
|
|
58
63
|
const doDisconnect = this.#mountInit.do?.onDisconnect;
|
|
59
64
|
for (const mutationRecord of mutationRecords) {
|
|
60
65
|
const { addedNodes, type, removedNodes } = mutationRecord;
|
|
61
|
-
console.log(mutationRecord);
|
|
66
|
+
//console.log(mutationRecord);
|
|
62
67
|
const addedElements = Array.from(addedNodes).filter(x => x instanceof Element);
|
|
63
68
|
addedElements.forEach(x => elsToInspect.push(x));
|
|
64
69
|
if (type === 'attributes') {
|
package/MountObserver.ts
CHANGED
|
@@ -20,7 +20,12 @@ export class MountObserver extends EventTarget implements MountContext{
|
|
|
20
20
|
constructor(init: MountInit){
|
|
21
21
|
super();
|
|
22
22
|
const {match, whereElementIntersectsWith, whereMediaMatches} = init;
|
|
23
|
-
|
|
23
|
+
let isComplex = false;
|
|
24
|
+
if(match !== undefined){
|
|
25
|
+
const reducedMatch = match.replaceAll(':not(', '');
|
|
26
|
+
isComplex = reducedMatch.includes(' ') || reducedMatch.includes(':');
|
|
27
|
+
}
|
|
28
|
+
this.#isComplex = isComplex;
|
|
24
29
|
if(whereElementIntersectsWith || whereMediaMatches) throw 'NI'; //not implemented
|
|
25
30
|
this.#mountInit = init;
|
|
26
31
|
this.#abortController = new AbortController();
|
|
@@ -65,7 +70,7 @@ export class MountObserver extends EventTarget implements MountContext{
|
|
|
65
70
|
const doDisconnect = this.#mountInit.do?.onDisconnect;
|
|
66
71
|
for(const mutationRecord of mutationRecords){
|
|
67
72
|
const {addedNodes, type, removedNodes} = mutationRecord;
|
|
68
|
-
console.log(mutationRecord);
|
|
73
|
+
//console.log(mutationRecord);
|
|
69
74
|
const addedElements = Array.from(addedNodes).filter(x => x instanceof Element) as Array<Element>;
|
|
70
75
|
addedElements.forEach(x => elsToInspect.push(x));
|
|
71
76
|
if(type === 'attributes'){
|
package/README.md
CHANGED
|
@@ -183,6 +183,34 @@ If an element that is in "mounted" state according to a MountObserver instance i
|
|
|
183
183
|
|
|
184
184
|
Extra support is provided for monitoring attributes.
|
|
185
185
|
|
|
186
|
+
Example:
|
|
187
|
+
|
|
188
|
+
```html
|
|
189
|
+
<div id=div>
|
|
190
|
+
<span id=span></span>
|
|
191
|
+
</div>
|
|
192
|
+
<script type=module>
|
|
193
|
+
import {MountObserver} from '../MountObserver.js';
|
|
194
|
+
const mo = new MountObserver({
|
|
195
|
+
match: '#span',
|
|
196
|
+
attribMatches:[
|
|
197
|
+
{
|
|
198
|
+
names: ['test-1']
|
|
199
|
+
}
|
|
200
|
+
]
|
|
201
|
+
});
|
|
202
|
+
mo.addEventListener('attr-change', e => {
|
|
203
|
+
console.log(e);
|
|
204
|
+
});
|
|
205
|
+
mo.observe(div);
|
|
206
|
+
setTimeout(() => {
|
|
207
|
+
span.setAttribute('test-1', 'hello')
|
|
208
|
+
}, 1000);
|
|
209
|
+
</script>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
186
214
|
## Preemptive downloading
|
|
187
215
|
|
|
188
216
|
There are two significant steps to imports, each of which imposes a cost:
|
package/package.json
CHANGED