mount-observer 0.0.17 → 0.0.18

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 CHANGED
@@ -190,7 +190,6 @@ export class MountObserver extends EventTarget {
190
190
  const alreadyMounted = await this.#filterAndDismount();
191
191
  const mount = this.#mountInit.do?.mount;
192
192
  const { import: imp } = this.#mountInit;
193
- const fullListOfAttrs = this.#fullListOfAttrs;
194
193
  for (const match of matching) {
195
194
  if (alreadyMounted.has(match))
196
195
  continue;
@@ -220,25 +219,36 @@ export class MountObserver extends EventTarget {
220
219
  });
221
220
  }
222
221
  this.dispatchEvent(new MountEvent(match, initializing));
223
- if (fullListOfAttrs !== undefined) {
224
- const attrParts = this.#attrParts;
225
- const attrChangeInfos = [];
226
- for (let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++) {
227
- const name = fullListOfAttrs[idx];
228
- const oldValue = null;
229
- const newValue = match.getAttribute(name);
230
- const parts = attrParts[idx];
231
- attrChangeInfos.push({
232
- idx,
233
- newValue,
234
- oldValue,
235
- parts
236
- });
222
+ //should we automatically call readAttrs?
223
+ //the thinking is it might make more sense to call that after mounting
224
+ this.#mountedList?.push(new WeakRef(match));
225
+ }
226
+ }
227
+ readAttrs(match, branchIndexes) {
228
+ const fullListOfAttrs = this.#fullListOfAttrs;
229
+ const attrChangeInfos = [];
230
+ if (fullListOfAttrs !== undefined) {
231
+ const attrParts = this.#attrParts;
232
+ for (let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++) {
233
+ const parts = attrParts[idx];
234
+ const { branchIdx } = parts;
235
+ if (branchIndexes !== undefined) {
236
+ if (!branchIndexes.has(branchIdx))
237
+ continue;
237
238
  }
238
- this.dispatchEvent(new AttrChangeEvent(match, attrChangeInfos));
239
+ const name = fullListOfAttrs[idx];
240
+ const oldValue = null;
241
+ const newValue = match.getAttribute(name);
242
+ attrChangeInfos.push({
243
+ idx,
244
+ newValue,
245
+ oldValue,
246
+ parts
247
+ });
239
248
  }
240
- this.#mountedList?.push(new WeakRef(match));
249
+ //this.dispatchEvent(new AttrChangeEvent(match, attrChangeInfos));
241
250
  }
251
+ return attrChangeInfos;
242
252
  }
243
253
  async #dismount(unmatching) {
244
254
  const onDismount = this.#mountInit.do?.dismount;
@@ -23,7 +23,7 @@ export function getWhereAttrSelector(whereAttr, withoutAttrs) {
23
23
  prefixLessMatches = branches.map(x => ({
24
24
  rootToBaseDelimiter,
25
25
  base: baseSelector,
26
- baseToBranchDelimiter,
26
+ baseToBranchDelimiter: x ? baseToBranchDelimiter : '',
27
27
  branch: x
28
28
  }));
29
29
  }
@@ -37,10 +37,13 @@ export function getWhereAttrSelector(whereAttr, withoutAttrs) {
37
37
  const { start } = rootCnfg;
38
38
  for (const match of prefixLessMatches) {
39
39
  const { base, baseToBranchDelimiter, branch, rootToBaseDelimiter } = match;
40
+ let branchIdx = 0;
40
41
  for (const prefixLessMatch of prefixLessMatches) {
41
42
  const { base, baseToBranchDelimiter, branch } = prefixLessMatch;
42
43
  const startAndRootToBaseDelimiter = start ? `${start}${rootToBaseDelimiter}` : '';
44
+ //TODO: could probably reduce the size of the code below
43
45
  if (branch) {
46
+ //will always have branch?
44
47
  const name = `${startAndRootToBaseDelimiter}${base}${baseToBranchDelimiter}${branch}`;
45
48
  fullListOfAttrs.push(name);
46
49
  partitionedAttrs.push({
@@ -48,6 +51,7 @@ export function getWhereAttrSelector(whereAttr, withoutAttrs) {
48
51
  name,
49
52
  base,
50
53
  branch,
54
+ branchIdx,
51
55
  rootCnfg
52
56
  });
53
57
  }
@@ -58,9 +62,11 @@ export function getWhereAttrSelector(whereAttr, withoutAttrs) {
58
62
  root: start,
59
63
  name,
60
64
  base,
61
- rootCnfg
65
+ rootCnfg,
66
+ branchIdx
62
67
  });
63
68
  }
69
+ branchIdx++;
64
70
  }
65
71
  }
66
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/types.d.ts CHANGED
@@ -80,7 +80,9 @@ interface AttrParts{
80
80
  root?: string,
81
81
  base?: string,
82
82
  branch?: string,
83
+ branchIdx: number,
83
84
  leaf?: string, //TODO
85
+ leafIdx?: number, //TODO
84
86
  rootCnfg?: RootCnfg
85
87
  }
86
88