mount-observer 0.0.64 → 0.0.66

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/Newish.js CHANGED
@@ -9,20 +9,22 @@ export class Newish {
9
9
  isResolved = false;
10
10
  #ce;
11
11
  #ref;
12
- //#assigner: undefined | Assigner = undefined;
13
12
  #options;
13
+ #args;
14
14
  constructor(enhancedElement, target, itemscope, options) {
15
+ this.#args = [enhancedElement, target, itemscope];
15
16
  this.#options = options || { assigner: Object.assign };
16
17
  this.#ref = new WeakRef(enhancedElement);
17
- this.#do(enhancedElement, target, itemscope);
18
18
  }
19
- handleEvent(event) {
19
+ handleEvent() {
20
20
  const enhancedElement = this.#ref.deref();
21
21
  if (!enhancedElement)
22
22
  return;
23
23
  this.#attachItemrefs(enhancedElement);
24
24
  }
25
- async #do(enhancedElement, target, itemscope) {
25
+ async do() {
26
+ const [enhancedElement, target, itemscope] = this.#args;
27
+ this.#args = undefined;
26
28
  if (enhancedElement[attached] === true)
27
29
  return;
28
30
  enhancedElement[attached] = true;
@@ -32,12 +34,6 @@ export class Newish {
32
34
  if (ctr === undefined) {
33
35
  const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
34
36
  const initPropVals = enhancedElement['ish'];
35
- // if(enhancedElement instanceof HTMLElement){
36
- // if(enhancedElement.dataset.ish){
37
- // const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
38
- // this.queue.push(parsedHostProps);
39
- // }
40
- // }
41
37
  const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
42
38
  const isInstance = initPropVals instanceof resolvedConstructor;
43
39
  ce = isInstance ? initPropVals : new resolvedConstructor();
@@ -49,8 +45,8 @@ export class Newish {
49
45
  if (initPropVals !== undefined)
50
46
  this.queue.push(initPropVals);
51
47
  }
52
- if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
53
- await ce['<mount>'](ce, enhancedElement, this.#options);
48
+ if ('tbd' in ce && typeof ce['tbd'] === 'function') {
49
+ await ce['tbd'](ce, enhancedElement, this.#options);
54
50
  }
55
51
  this.#ce = ce;
56
52
  const self = this;
@@ -67,12 +63,16 @@ export class Newish {
67
63
  enumerable: true,
68
64
  configurable: true,
69
65
  });
70
- this.#assignGingerly(true);
66
+ await this.#assignGingerly(true);
67
+ if ('<mount>' in ce && typeof ce['<mount>'] === 'function') {
68
+ await ce['<mount>'](ce, enhancedElement, this.#options);
69
+ }
71
70
  //attach any itemref references
72
71
  this.#attachItemrefs(enhancedElement);
73
72
  const et = ObsAttr(enhancedElement, 'itemref');
74
73
  et.addEventListener('attr-changed', this);
75
74
  this.isResolved = true;
75
+ return ce;
76
76
  }
77
77
  #alreadyAttached = new Set();
78
78
  #attachItemrefs(enhancedElement) {
@@ -104,14 +104,18 @@ export class Newish {
104
104
  if (ce === undefined) {
105
105
  throw 500;
106
106
  }
107
+ let foundArray = false;
108
+ const hasArrFilter = 'arr=>' in ce && typeof ce['arr=>'] === 'function';
109
+ const ref = this.#ref.deref();
107
110
  while (this.queue.length > 0) {
108
111
  const fi = this.queue.shift();
109
112
  //TODO: Provide support for a virtual slice of a very large list
110
113
  //TODO: Maybe should check if iterable rather than an array?
111
114
  if (Array.isArray(fi)) {
115
+ foundArray = true;
112
116
  let filtered = fi;
113
- if ('arr=>' in ce && typeof ce['arr=>'] === 'function') {
114
- filtered = await ce['arr=>'](ce, fi, this.#options);
117
+ if (hasArrFilter) {
118
+ filtered = await (ce['arr=>'])(ce, fi, ref, this.#options);
115
119
  }
116
120
  ce[arr] = filtered;
117
121
  actions.add('ishListAssigned');
@@ -122,7 +126,13 @@ export class Newish {
122
126
  actions.add('ishAssigned');
123
127
  }
124
128
  }
125
- const ref = this.#ref.deref();
129
+ if (fromDo && !foundArray) {
130
+ const filtered = await (ce['arr=>'])(ce, undefined, ref, this.#options);
131
+ if (filtered !== undefined) {
132
+ ce[arr] = filtered;
133
+ actions.add('ishListAssigned');
134
+ }
135
+ }
126
136
  if (ref) {
127
137
  ref.dispatchEvent(new IshEvent(Array.from(actions)));
128
138
  }
package/Newish.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { BindishOptions, Ishcycle } from './ts-refs/mount-observer/types.js';
1
+ import { BindishOptions, HasIsh, Ishcycle } from './ts-refs/mount-observer/types.js';
2
2
 
3
3
  export {waitForEvent} from './waitForEvent.js';
4
4
  import {ObsAttr} from './ObsAttr.js';
@@ -12,27 +12,27 @@ export class Newish implements EventListenerObject {
12
12
  #ce: Ishcycle | undefined;
13
13
  #ref: WeakRef<Element>;
14
14
 
15
- //#assigner: undefined | Assigner = undefined;
16
15
  #options: BindishOptions;
17
-
18
- constructor(enhancedElement: Element,
16
+ #args: [enhancedElement: Element, target: Node, itemscope: string] | undefined;
17
+ constructor(
18
+ enhancedElement: Element,
19
19
  target: Node,
20
- itemscope: string, options?: BindishOptions){
20
+ itemscope: string,
21
+ options?: BindishOptions
22
+ ){
23
+ this.#args = [enhancedElement, target, itemscope];
21
24
  this.#options = options || {assigner: Object.assign};
22
25
  this.#ref = new WeakRef(enhancedElement);
23
- this.#do(enhancedElement, target, itemscope);
24
26
  }
25
- handleEvent(event: Event): void {
27
+ handleEvent(): void {
26
28
  const enhancedElement = this.#ref.deref();
27
29
  if(!enhancedElement) return;
28
30
  this.#attachItemrefs(enhancedElement);
29
31
  }
30
32
 
31
- async #do(
32
- enhancedElement: Element,
33
- target: Node,
34
- itemscope: string
35
- ){
33
+ async do(){
34
+ const [enhancedElement, target, itemscope] = this.#args!;
35
+ this.#args = undefined;
36
36
  if((<any>enhancedElement)[attached] === true) return;
37
37
  (<any>enhancedElement)[attached] = true;
38
38
  const options = this.#options;
@@ -42,14 +42,7 @@ export class Newish implements EventListenerObject {
42
42
  const foundCtr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
43
43
 
44
44
  const initPropVals = (<any>enhancedElement)['ish'];
45
- // if(enhancedElement instanceof HTMLElement){
46
- // if(enhancedElement.dataset.ish){
47
- // const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
48
- // this.queue.push(parsedHostProps);
49
- // }
50
- // }
51
-
52
-
45
+
53
46
  const resolvedConstructor = foundCtr.constructor.name === 'AsyncFunction' ? await foundCtr() : foundCtr;
54
47
  const isInstance = initPropVals instanceof resolvedConstructor
55
48
  ce = isInstance ? initPropVals : new resolvedConstructor() as Ishcycle;
@@ -58,13 +51,10 @@ export class Newish implements EventListenerObject {
58
51
  ce = new ctr();
59
52
  if(initPropVals !== undefined) this.queue.push(initPropVals);
60
53
  }
61
-
62
-
63
-
64
- if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
65
- await ce['<mount>'](ce, enhancedElement, this.#options)
54
+ if('tbd' in ce && typeof ce['tbd'] === 'function'){
55
+ await ce['tbd'](ce, enhancedElement, this.#options);
66
56
  }
67
-
57
+
68
58
  this.#ce = ce;
69
59
  const self = this;
70
60
  Object.defineProperty(enhancedElement, 'ish', {
@@ -79,12 +69,16 @@ export class Newish implements EventListenerObject {
79
69
  enumerable: true,
80
70
  configurable: true,
81
71
  });
82
- this.#assignGingerly(true);
72
+ await this.#assignGingerly(true);
73
+ if('<mount>' in ce && typeof ce['<mount>'] === 'function'){
74
+ await ce['<mount>'](ce, enhancedElement as HasIsh & Element, this.#options)
75
+ }
83
76
  //attach any itemref references
84
77
  this.#attachItemrefs(enhancedElement);
85
78
  const et = ObsAttr(enhancedElement, 'itemref');
86
79
  et.addEventListener('attr-changed', this);
87
80
  this.isResolved = true;
81
+ return ce;
88
82
  }
89
83
 
90
84
 
@@ -120,14 +114,18 @@ export class Newish implements EventListenerObject {
120
114
  if(ce === undefined){
121
115
  throw 500;
122
116
  }
117
+ let foundArray = false;
118
+ const hasArrFilter = 'arr=>' in ce && typeof ce['arr=>'] === 'function';
119
+ const ref = this.#ref.deref();
123
120
  while(this.queue.length > 0 ){
124
121
  const fi = this.queue.shift();
125
122
  //TODO: Provide support for a virtual slice of a very large list
126
123
  //TODO: Maybe should check if iterable rather than an array?
127
124
  if(Array.isArray(fi)){
128
- let filtered = fi;
129
- if('arr=>' in ce && typeof ce['arr=>'] === 'function'){
130
- filtered = await ce['arr=>'](ce, fi, this.#options);
125
+ foundArray = true;
126
+ let filtered = fi as any | undefined;
127
+ if(hasArrFilter){
128
+ filtered = await (ce['arr=>']!)(ce, fi, ref! as HasIsh & Element, this.#options);
131
129
  }
132
130
  (<any>ce)[arr] = filtered;
133
131
  actions.add('ishListAssigned');
@@ -138,7 +136,14 @@ export class Newish implements EventListenerObject {
138
136
  }
139
137
 
140
138
  }
141
- const ref = this.#ref.deref();
139
+ if(fromDo && !foundArray){
140
+ const filtered = await (ce['arr=>']!)(ce, undefined, ref! as HasIsh & Element, this.#options);
141
+ if(filtered !== undefined){
142
+ (<any>ce)[arr] = filtered;
143
+ actions.add('ishListAssigned');
144
+ }
145
+ }
146
+
142
147
  if(ref){
143
148
  ref.dispatchEvent(new IshEvent(Array.from(actions)));
144
149
  }
package/bindish.js CHANGED
@@ -8,7 +8,8 @@ export async function bindishIt(scopes, target, options) {
8
8
  const itemscope = scope.getAttribute('itemscope');
9
9
  if (itemscope && !(scope.ish instanceof HTMLElement)) {
10
10
  const { Newish } = await import('./Newish.js');
11
- new Newish(scope, target, itemscope, options);
11
+ const newIsh = new Newish(scope, target, itemscope, options);
12
+ await newIsh.do();
12
13
  }
13
14
  }
14
15
  }
package/bindish.ts CHANGED
@@ -15,7 +15,8 @@ export async function bindishIt(scopes: Array<Element>, target: Node, options?:
15
15
  const itemscope = scope.getAttribute('itemscope');
16
16
  if(itemscope && !((<any>scope).ish instanceof HTMLElement)){
17
17
  const {Newish} = await import('./Newish.js');
18
- new Newish(scope, target, itemscope, options);
18
+ const newIsh = new Newish(scope, target, itemscope, options);
19
+ await newIsh.do()
19
20
  }
20
21
  }
21
22
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.64",
3
+ "version": "0.0.66",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
package/refid/regIsh.js CHANGED
@@ -23,5 +23,11 @@ export function regIsh(scope, name, ctr) {
23
23
  }
24
24
  };
25
25
  };
26
+ ctr.prototype['#arr='] = function (newArr) {
27
+ if (newArr === undefined) {
28
+ return this[arr];
29
+ }
30
+ this[arr] = newArr;
31
+ };
26
32
  document.dispatchEvent(new Event(guid));
27
33
  }
package/refid/regIsh.ts CHANGED
@@ -26,5 +26,11 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
26
26
  }
27
27
  };
28
28
  };
29
+ ctr.prototype['#arr='] = function(newArr?: any[]){
30
+ if(newArr === undefined){
31
+ return this[arr];
32
+ }
33
+ this[arr] = newArr;
34
+ }
29
35
  document.dispatchEvent(new Event(guid));
30
36
  }
@@ -220,10 +220,16 @@ export interface BindishOptions{
220
220
  initPropVals?: any,
221
221
  }
222
222
 
223
+ //TODO: move to mount observer
224
+ export interface HasIsh {
225
+ ish: any;
226
+ }
227
+
223
228
  export interface Ishcycle{
224
- '<mount>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
229
+ '<mount>'?(self: Ishcycle, el: Element & HasIsh, options: BindishOptions): Promise<void>;
225
230
  //'</dismount>'?(self: IshFace, el: Element): Promise<void>;
226
- '<inScope>'?(self: Ishcycle, el: Element, options: BindishOptions): Promise<void>;
231
+ '<inScope>'?(self: Ishcycle, el: Element & HasIsh, options: BindishOptions): Promise<void>;
232
+ 'arr=>'?(self: Ishcycle, arr: any[] | undefined, el: Element & HasIsh, options: BindishOptions): Promise<void | any[]>;
227
233
  //'</outOfScope>'?(self: IshFace, el: Element): Promise<void>;
228
234
  }
229
235
 
@@ -184,10 +184,7 @@ export interface PIP<TProp = any, TElement = Element> extends EventListenerObjec
184
184
  readonly outEvtName: string;
185
185
  }
186
186
 
187
- //TODO: move to mount observer
188
- export interface HasIsh {
189
- ish: EventTarget;
190
- }
187
+
191
188
 
192
189
  export interface HasIshList {
193
190
  ishList: Array<any>;