mount-observer 0.0.4 → 0.0.5
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 +2 -2
- package/README.md +18 -6
- package/package.json +1 -1
- package/types.d.ts +6 -6
package/MountObserver.js
CHANGED
|
@@ -230,8 +230,8 @@ export class MountObserver extends EventTarget {
|
|
|
230
230
|
const els = Array.from(within.querySelectorAll(this.#selector));
|
|
231
231
|
this.#filterAndMount(els, false);
|
|
232
232
|
}
|
|
233
|
-
unobserve() {
|
|
234
|
-
|
|
233
|
+
unobserve(within) {
|
|
234
|
+
//mutationObserverLookup
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
package/README.md
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
[](https://bundlephobia.com/result?p=mount-observer)
|
|
4
4
|
<img src="http://img.badgesize.io/https://cdn.jsdelivr.net/npm/mount-observer?compression=gzip">
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
# The MountObserver api.
|
|
7
8
|
|
|
8
9
|
Author: Bruce B. Anderson
|
|
9
10
|
|
|
10
11
|
Issues / pr's / polyfill: [mount-observer](https://github.com/bahrus/mount-observer)
|
|
11
12
|
|
|
12
|
-
Last Update: 2023-11-
|
|
13
|
+
Last Update: 2023-11-23
|
|
13
14
|
|
|
14
15
|
## Benefits of this API
|
|
15
16
|
|
|
@@ -133,13 +134,16 @@ const observer = new MountObserver({
|
|
|
133
134
|
},
|
|
134
135
|
onDismount: ...,
|
|
135
136
|
onDisconnect: ...,
|
|
137
|
+
onOutsideRootNode: ...,
|
|
136
138
|
onReconnect: ...,
|
|
137
|
-
onReconfirm:
|
|
139
|
+
onReconfirm: ...,
|
|
138
140
|
onOutOfScope: ...,
|
|
139
141
|
}
|
|
140
142
|
})
|
|
141
143
|
```
|
|
142
144
|
|
|
145
|
+
Callbacks like we see above are useful for tight coupling, and probably are unmatched in terms of performance. However, since these rules may be of interest to multiple parties, it is usesful to also provide the ability for multiple parties to subscribe to these css rules. This can be done via:
|
|
146
|
+
|
|
143
147
|
## Subscribing
|
|
144
148
|
|
|
145
149
|
Subscribing can be done via:
|
|
@@ -178,11 +182,11 @@ The moment a MountObserver instance's "observe" method is called (passing in a r
|
|
|
178
182
|
|
|
179
183
|
If an element that is in "mounted" state according to a MountObserver instance is moved from one parent DOM element to another:
|
|
180
184
|
|
|
181
|
-
1) "disconnect" event is dispatched from the MountObserver instance the moment the element is disconnected from the DOM fragment.
|
|
185
|
+
1) "disconnect" event is dispatched from the MountObserver instance the moment the mounted element is disconnected from the DOM fragment.
|
|
182
186
|
2) If/when the element is added somewhere else in the DOM tree, the mountObserver instance will dispatch event "reconnect", regardless of where. [Note: can't polyfill this very easily]
|
|
183
|
-
3) If the element is added outside the rootNode being observed, the mountObserver instance will dispatch event "outside-root-node", and the MountObserver instance will relinquish any further responsibility for this element. Ideally this would also be dispatched when the platform garbage collects the element as well after all hard references are relinquished.
|
|
184
|
-
4) If the new place it was added remains within the original rootNode and remains
|
|
185
|
-
5) If the element no longer satisfies the criteria of the MountObserver instance, the MountObserver instance will dispatch event "dismount".
|
|
187
|
+
3) If the mounted element is added outside the rootNode being observed, the mountObserver instance will dispatch event "outside-root-node", and the MountObserver instance will relinquish any further responsibility for this element. Ideally this would also be dispatched when the platform garbage collects the element as well after all hard references are relinquished.
|
|
188
|
+
4) If the new place it was added remains within the original rootNode and remains mounted, the MountObserver instance dispatches event "reconfirmed".
|
|
189
|
+
5) If the element no longer satisfies the criteria of the MountObserver instance, the MountObserver instance will dispatch event "dismount".
|
|
186
190
|
|
|
187
191
|
## Special support for observable attributes
|
|
188
192
|
|
|
@@ -206,6 +210,14 @@ Example:
|
|
|
206
210
|
});
|
|
207
211
|
mo.addEventListener('attr-change', e => {
|
|
208
212
|
console.log(e);
|
|
213
|
+
// {
|
|
214
|
+
// attrChangeInfo:{
|
|
215
|
+
// name: 'test-1',
|
|
216
|
+
// oldValue: null,
|
|
217
|
+
// newValue: 'hello'
|
|
218
|
+
// idx: 0,
|
|
219
|
+
// }
|
|
220
|
+
// }
|
|
209
221
|
});
|
|
210
222
|
mo.observe(div);
|
|
211
223
|
setTimeout(() => {
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -7,11 +7,11 @@ export interface MountInit{
|
|
|
7
7
|
readonly whereSatisfies?: PipelineProcessor<boolean>,
|
|
8
8
|
readonly import?: ImportString | [ImportString, ImportAssertions] | PipelineProcessor,
|
|
9
9
|
readonly do?: {
|
|
10
|
-
readonly onMount
|
|
11
|
-
readonly onDismount
|
|
12
|
-
readonly onDisconnect
|
|
13
|
-
readonly onReconfirmed
|
|
14
|
-
readonly onOutsideRootNode
|
|
10
|
+
readonly onMount?: PipelineProcessor,
|
|
11
|
+
readonly onDismount?: PipelineProcessor,
|
|
12
|
+
readonly onDisconnect?: PipelineProcessor,
|
|
13
|
+
readonly onReconfirmed?: PipelineProcessor,
|
|
14
|
+
readonly onOutsideRootNode?: PipelineProcessor,
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
}
|
|
@@ -32,7 +32,7 @@ export interface MountContext {
|
|
|
32
32
|
// readonly mountedRefs: WeakRef<Element>[],
|
|
33
33
|
// readonly dismountedRefs: WeakRef<Element>[],
|
|
34
34
|
observe(within: Node): void;
|
|
35
|
-
unobserve(): void;
|
|
35
|
+
unobserve(within: Node): void;
|
|
36
36
|
module?: any;
|
|
37
37
|
}
|
|
38
38
|
|